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 | 4df7e24 | 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; |
changbetty | 363e8ac | 2019-12-06 18:16:37 +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; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 30 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 31 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 32 | import android.content.Context; |
| 33 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 34 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 35 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 36 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 37 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 38 | import android.net.Uri; |
| 39 | import android.os.AsyncResult; |
| 40 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 41 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 42 | import android.os.Bundle; |
| 43 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 44 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.os.Looper; |
| 46 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 47 | import android.os.Messenger; |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 48 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 49 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 50 | import android.os.PersistableBundle; |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 51 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 52 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 53 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 54 | import android.os.ServiceSpecificException; |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 55 | import android.os.SystemClock; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 56 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 57 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 58 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 59 | import android.preference.PreferenceManager; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 60 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 61 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 62 | import android.provider.Telephony; |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 63 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 64 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 65 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 66 | import android.telecom.TelecomManager; |
Chen Xu | c7b18ec | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 67 | import android.telephony.Annotation.ApnType; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 68 | import android.telephony.Annotation.ThermalMitigationResult; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 69 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 70 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 71 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 72 | import android.telephony.CellIdentity; |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 73 | import android.telephony.CellIdentityCdma; |
| 74 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 75 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 76 | import android.telephony.CellInfoGsm; |
| 77 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 78 | import android.telephony.ClientRequestStats; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 79 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 80 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 81 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 82 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 83 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 84 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 85 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 86 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 87 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 88 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 89 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 90 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 91 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 92 | import android.telephony.SignalStrength; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 93 | import android.telephony.SignalStrengthUpdateRequest; |
| 94 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 95 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 96 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 97 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 98 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 99 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 100 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 101 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 102 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 103 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 104 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 105 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 106 | import android.telephony.data.ApnSetting; |
| 107 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 108 | import android.telephony.gba.GbaAuthRequest; |
| 109 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 110 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 111 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 112 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | d4c5bde | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 113 | import android.telephony.ims.RcsContactUceCapability; |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 114 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 115 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 116 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 117 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 118 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 119 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 120 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 121 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 122 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 123 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 124 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 125 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 126 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 127 | import android.util.ArraySet; |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 128 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 129 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 130 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 131 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 132 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 133 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 134 | import com.android.ims.rcs.uce.eab.EabUtil; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 135 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 139 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.CommandException; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 142 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.GbaManager; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 145 | import com.android.internal.telephony.HalVersion; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 146 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 149 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 151 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 157 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.RIL; |
SongFerngWang | 522637d | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 162 | import com.android.internal.telephony.RILConstants; |
Daniel Bright | fe1e6ac | 2021-03-12 10:25:03 -0800 | [diff] [blame] | 163 | import com.android.internal.telephony.RadioInterfaceCapabilityController; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 166 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 167 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 168 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 169 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 171 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 172 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 173 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 175 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 176 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 177 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 178 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 179 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 180 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 181 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 182 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 183 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 184 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 185 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 186 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 187 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 188 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 189 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 190 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 191 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 192 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 193 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 194 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 195 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 196 | import com.android.services.telephony.TelecomAccountRegistry; |
| 197 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 198 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 199 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 200 | import java.io.FileDescriptor; |
| 201 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 202 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 203 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 204 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 205 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 206 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 207 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 208 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 209 | import java.util.NoSuchElementException; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 210 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 211 | import java.util.Set; |
SongFerngWang | c63cf52 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 212 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 213 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 214 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 215 | |
| 216 | /** |
| 217 | * Implementation of the ITelephony interface. |
| 218 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 219 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 220 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 221 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 222 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 223 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 224 | |
| 225 | // Message codes used with mMainThreadHandler |
| 226 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 227 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 228 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 229 | private static final int CMD_OPEN_CHANNEL = 9; |
| 230 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 231 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 232 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 233 | private static final int CMD_NV_READ_ITEM = 13; |
| 234 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 235 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 236 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 237 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 238 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 239 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 240 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 241 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 242 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 243 | private static final int CMD_SEND_ENVELOPE = 25; |
| 244 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 245 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 246 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 247 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 248 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 249 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 250 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 251 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 252 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 253 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 254 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 255 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 256 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 257 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 258 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 259 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 260 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 261 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 262 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 263 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 264 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 265 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 266 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 267 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 268 | private static final int CMD_SWITCH_SLOTS = 50; |
| 269 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 270 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 271 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 272 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 273 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 274 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 275 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 276 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 277 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 278 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 279 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 280 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 281 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 282 | private static final int CMD_MODEM_REBOOT = 64; |
| 283 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 284 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 285 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 286 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 287 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 288 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 289 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 290 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 291 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 292 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 293 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 294 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 295 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 296 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 297 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 298 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 299 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 300 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 301 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 302 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 303 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 304 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 305 | private static final int CMD_GET_CALL_WAITING = 87; |
| 306 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 307 | private static final int CMD_SET_CALL_WAITING = 89; |
| 308 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 309 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 310 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 311 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 312 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 313 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 314 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 315 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 316 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 317 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 318 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 319 | private static final int CMD_SET_SIM_POWER = 101; |
| 320 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 321 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 322 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 323 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 324 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 325 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 326 | private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 327 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 328 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 329 | // Parameters of select command. |
| 330 | private static final int SELECT_COMMAND = 0xA4; |
| 331 | private static final int SELECT_P1 = 0x04; |
| 332 | private static final int SELECT_P2 = 0; |
| 333 | private static final int SELECT_P3 = 0x10; |
| 334 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 335 | /** The singleton instance. */ |
| 336 | private static PhoneInterfaceManager sInstance; |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 337 | private static List<String> sThermalMitigationAllowlistedPackages = new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 338 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 339 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 340 | private CallManager mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 341 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 342 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 343 | private AppOpsManager mAppOps; |
| 344 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 345 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 346 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 347 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Daniel Bright | fe1e6ac | 2021-03-12 10:25:03 -0800 | [diff] [blame] | 348 | private final RadioInterfaceCapabilityController mRadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 349 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 350 | /** User Activity */ |
| 351 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 352 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 353 | |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 354 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 355 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 356 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 357 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 358 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 359 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 360 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 361 | // String to store multi SIM allowed |
| 362 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 363 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 364 | // The AID of ISD-R. |
| 365 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 366 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 367 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 368 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 369 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 370 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 371 | |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 372 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 373 | private static final int MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE = -2; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 374 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 375 | /** |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 376 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 377 | */ |
| 378 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 379 | "reset_network_erase_modem_config_enabled"; |
| 380 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 381 | private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds |
| 382 | |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 383 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 384 | * A request object to use for transmitting data to an ICC. |
| 385 | */ |
| 386 | private static final class IccAPDUArgument { |
| 387 | public int channel, cla, command, p1, p2, p3; |
| 388 | public String data; |
| 389 | |
| 390 | public IccAPDUArgument(int channel, int cla, int command, |
| 391 | int p1, int p2, int p3, String data) { |
| 392 | this.channel = channel; |
| 393 | this.cla = cla; |
| 394 | this.command = command; |
| 395 | this.p1 = p1; |
| 396 | this.p2 = p2; |
| 397 | this.p3 = p3; |
| 398 | this.data = data; |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 403 | * A request object to use for transmitting data to an ICC. |
| 404 | */ |
| 405 | private static final class ManualNetworkSelectionArgument { |
| 406 | public OperatorInfo operatorInfo; |
| 407 | public boolean persistSelection; |
| 408 | |
| 409 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 410 | this.operatorInfo = operatorInfo; |
| 411 | this.persistSelection = persistSelection; |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 416 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 417 | * request after sending. The main thread will notify the request when it is complete. |
| 418 | */ |
| 419 | private static final class MainThreadRequest { |
| 420 | /** The argument to use for the request */ |
| 421 | public Object argument; |
| 422 | /** The result of the request that is run on the main thread */ |
| 423 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 424 | // The subscriber id that this request applies to. Defaults to |
| 425 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 426 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 427 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 428 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 429 | public Phone phone; |
| 430 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 431 | public WorkSource workSource; |
| 432 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 433 | public MainThreadRequest(Object argument) { |
| 434 | this.argument = argument; |
| 435 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 436 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 437 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 438 | this.argument = argument; |
| 439 | if (phone != null) { |
| 440 | this.phone = phone; |
| 441 | } |
| 442 | this.workSource = workSource; |
| 443 | } |
| 444 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 445 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 446 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 447 | if (subId != null) { |
| 448 | this.subId = subId; |
| 449 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 450 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 451 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 452 | } |
| 453 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 454 | private static final class IncomingThirdPartyCallArgs { |
| 455 | public final ComponentName component; |
| 456 | public final String callId; |
| 457 | public final String callerDisplayName; |
| 458 | |
| 459 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 460 | String callerDisplayName) { |
| 461 | this.component = component; |
| 462 | this.callId = callId; |
| 463 | this.callerDisplayName = callerDisplayName; |
| 464 | } |
| 465 | } |
| 466 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 467 | /** |
| 468 | * A handler that processes messages on the main thread in the phone process. Since many |
| 469 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 470 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 471 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 472 | * on, which will be notified when the operation completes and will contain the result of the |
| 473 | * request. |
| 474 | * |
| 475 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 476 | * note that request.result must be set to something non-null for the calling thread to |
| 477 | * unblock. |
| 478 | */ |
| 479 | private final class MainThreadHandler extends Handler { |
| 480 | @Override |
| 481 | public void handleMessage(Message msg) { |
| 482 | MainThreadRequest request; |
| 483 | Message onCompleted; |
| 484 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 485 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 486 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 487 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 488 | |
| 489 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 490 | case CMD_HANDLE_USSD_REQUEST: { |
| 491 | request = (MainThreadRequest) msg.obj; |
| 492 | final Phone phone = getPhoneFromRequest(request); |
| 493 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 494 | String ussdRequest = ussdObject.first; |
| 495 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 496 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 497 | if (!isUssdApiAllowed(request.subId)) { |
| 498 | // Carrier does not support use of this API, return failure. |
| 499 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 500 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 501 | Bundle returnData = new Bundle(); |
| 502 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 503 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 504 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 505 | request.result = true; |
| 506 | notifyRequester(request); |
| 507 | return; |
| 508 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 509 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 510 | try { |
| 511 | request.result = phone != null |
| 512 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 513 | } catch (CallStateException cse) { |
| 514 | request.result = false; |
| 515 | } |
| 516 | // Wake up the requesting thread |
| 517 | notifyRequester(request); |
| 518 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 519 | } |
| 520 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 521 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 522 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 523 | final Phone phone = getPhoneFromRequest(request); |
| 524 | request.result = phone != null ? |
| 525 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 526 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 527 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 528 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 529 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 530 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 531 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 532 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 533 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 534 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 535 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 536 | if (uiccCard == null) { |
| 537 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 538 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 539 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 540 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 541 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 542 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 543 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 544 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 545 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 546 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 547 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 548 | break; |
| 549 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 550 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 551 | ar = (AsyncResult) msg.obj; |
| 552 | request = (MainThreadRequest) ar.userObj; |
| 553 | if (ar.exception == null && ar.result != null) { |
| 554 | request.result = ar.result; |
| 555 | } else { |
| 556 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 557 | if (ar.result == null) { |
| 558 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 559 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 560 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 561 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 562 | } else { |
| 563 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 564 | } |
| 565 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 566 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 567 | break; |
| 568 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 569 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 570 | request = (MainThreadRequest) msg.obj; |
| 571 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 572 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 573 | if (uiccCard == null) { |
| 574 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 575 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 576 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 577 | } else { |
| 578 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 579 | request); |
| 580 | uiccCard.iccTransmitApduBasicChannel( |
| 581 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 582 | iccArgument.p3, iccArgument.data, onCompleted); |
| 583 | } |
| 584 | break; |
| 585 | |
| 586 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 587 | ar = (AsyncResult) msg.obj; |
| 588 | request = (MainThreadRequest) ar.userObj; |
| 589 | if (ar.exception == null && ar.result != null) { |
| 590 | request.result = ar.result; |
| 591 | } else { |
| 592 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 593 | if (ar.result == null) { |
| 594 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 595 | } else if (ar.exception instanceof CommandException) { |
| 596 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 597 | ar.exception); |
| 598 | } else { |
| 599 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 600 | } |
| 601 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 602 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 603 | break; |
| 604 | |
| 605 | case CMD_EXCHANGE_SIM_IO: |
| 606 | request = (MainThreadRequest) msg.obj; |
| 607 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 608 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 609 | if (uiccCard == null) { |
| 610 | loge("iccExchangeSimIO: No UICC"); |
| 611 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 612 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 613 | } else { |
| 614 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 615 | request); |
| 616 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 617 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 618 | iccArgument.data, onCompleted); |
| 619 | } |
| 620 | break; |
| 621 | |
| 622 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 623 | ar = (AsyncResult) msg.obj; |
| 624 | request = (MainThreadRequest) ar.userObj; |
| 625 | if (ar.exception == null && ar.result != null) { |
| 626 | request.result = ar.result; |
| 627 | } else { |
| 628 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 629 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 630 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 631 | break; |
| 632 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 633 | case CMD_SEND_ENVELOPE: |
| 634 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 635 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 636 | if (uiccCard == null) { |
| 637 | loge("sendEnvelopeWithStatus: No UICC"); |
| 638 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 639 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 640 | } else { |
| 641 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 642 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 643 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 644 | break; |
| 645 | |
| 646 | case EVENT_SEND_ENVELOPE_DONE: |
| 647 | ar = (AsyncResult) msg.obj; |
| 648 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 649 | if (ar.exception == null && ar.result != null) { |
| 650 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 651 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 652 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 653 | if (ar.result == null) { |
| 654 | loge("sendEnvelopeWithStatus: Empty response"); |
| 655 | } else if (ar.exception instanceof CommandException) { |
| 656 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 657 | ar.exception); |
| 658 | } else { |
| 659 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 660 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 661 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 662 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 663 | break; |
| 664 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 665 | case CMD_OPEN_CHANNEL: |
| 666 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 667 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 668 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 669 | if (uiccCard == null) { |
| 670 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 671 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 672 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 673 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 674 | } else { |
| 675 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 676 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 677 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 678 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 679 | break; |
| 680 | |
| 681 | case EVENT_OPEN_CHANNEL_DONE: |
| 682 | ar = (AsyncResult) msg.obj; |
| 683 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 684 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 685 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 686 | int[] result = (int[]) ar.result; |
| 687 | int channelId = result[0]; |
| 688 | byte[] selectResponse = null; |
| 689 | if (result.length > 1) { |
| 690 | selectResponse = new byte[result.length - 1]; |
| 691 | for (int i = 1; i < result.length; ++i) { |
| 692 | selectResponse[i - 1] = (byte) result[i]; |
| 693 | } |
| 694 | } |
| 695 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 696 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 697 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 698 | if (ar.result == null) { |
| 699 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 700 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 701 | if (ar.exception != null) { |
| 702 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 703 | } |
| 704 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 705 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 706 | if (ar.exception instanceof CommandException) { |
| 707 | CommandException.Error error = |
| 708 | ((CommandException) (ar.exception)).getCommandError(); |
| 709 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 710 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 711 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 712 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 713 | } |
| 714 | } |
| 715 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 716 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 717 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 718 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 719 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 720 | break; |
| 721 | |
| 722 | case CMD_CLOSE_CHANNEL: |
| 723 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 724 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 725 | if (uiccCard == null) { |
| 726 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 727 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 728 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 729 | } else { |
| 730 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 731 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 732 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 733 | break; |
| 734 | |
| 735 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 736 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 737 | break; |
| 738 | |
| 739 | case CMD_NV_READ_ITEM: |
| 740 | request = (MainThreadRequest) msg.obj; |
| 741 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 742 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 743 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 744 | break; |
| 745 | |
| 746 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 747 | ar = (AsyncResult) msg.obj; |
| 748 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 749 | if (ar.exception == null && ar.result != null) { |
| 750 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 751 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 752 | request.result = ""; |
| 753 | if (ar.result == null) { |
| 754 | loge("nvReadItem: Empty response"); |
| 755 | } else if (ar.exception instanceof CommandException) { |
| 756 | loge("nvReadItem: CommandException: " + |
| 757 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 758 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 759 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 760 | } |
| 761 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 762 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 763 | break; |
| 764 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 765 | case CMD_NV_WRITE_ITEM: |
| 766 | request = (MainThreadRequest) msg.obj; |
| 767 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 768 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 769 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 770 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 771 | break; |
| 772 | |
| 773 | case EVENT_NV_WRITE_ITEM_DONE: |
| 774 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 775 | break; |
| 776 | |
| 777 | case CMD_NV_WRITE_CDMA_PRL: |
| 778 | request = (MainThreadRequest) msg.obj; |
| 779 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 780 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 781 | break; |
| 782 | |
| 783 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 784 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 785 | break; |
| 786 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 787 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 788 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 789 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 790 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 791 | break; |
| 792 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 793 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 794 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 795 | break; |
| 796 | |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 797 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 798 | request = (MainThreadRequest) msg.obj; |
| 799 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 800 | request); |
| 801 | Phone phone = getPhoneFromRequest(request); |
| 802 | if (phone != null) { |
| 803 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 804 | } else { |
| 805 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 806 | request.result = false; |
| 807 | notifyRequester(request); |
| 808 | } |
| 809 | break; |
| 810 | } |
| 811 | |
| 812 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 813 | ar = (AsyncResult) msg.obj; |
| 814 | request = (MainThreadRequest) ar.userObj; |
| 815 | if (ar.exception == null && ar.result != null) { |
| 816 | request.result = ar.result; |
| 817 | } else { |
| 818 | // request.result must be set to something non-null |
| 819 | // for the calling thread to unblock |
| 820 | if (request.result != null) { |
| 821 | request.result = ar.result; |
| 822 | } else { |
| 823 | request.result = false; |
| 824 | } |
| 825 | if (ar.result == null) { |
| 826 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 827 | } else if (ar.exception instanceof CommandException) { |
| 828 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 829 | + ar.exception); |
| 830 | } else { |
| 831 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 832 | } |
| 833 | } |
| 834 | notifyRequester(request); |
| 835 | break; |
| 836 | |
| 837 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 838 | request = (MainThreadRequest) msg.obj; |
| 839 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 840 | Phone phone = getPhoneFromRequest(request); |
| 841 | if (phone != null) { |
| 842 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 843 | request.workSource); |
| 844 | } else { |
| 845 | loge("enableNrDualConnectivity: No phone object"); |
| 846 | request.result = |
| 847 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 848 | notifyRequester(request); |
| 849 | } |
| 850 | break; |
| 851 | } |
| 852 | |
| 853 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 854 | ar = (AsyncResult) msg.obj; |
| 855 | request = (MainThreadRequest) ar.userObj; |
| 856 | if (ar.exception == null) { |
| 857 | request.result = |
| 858 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 859 | } else { |
| 860 | request.result = |
| 861 | TelephonyManager |
| 862 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 863 | if (ar.exception instanceof CommandException) { |
| 864 | CommandException.Error error = |
| 865 | ((CommandException) (ar.exception)).getCommandError(); |
| 866 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 867 | request.result = |
| 868 | TelephonyManager |
| 869 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
Sooraj Sasindran | 2965416 | 2021-03-03 23:00:01 +0000 | [diff] [blame] | 870 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 871 | request.result = |
| 872 | TelephonyManager |
| 873 | .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 874 | } |
| 875 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 876 | + ar.exception); |
| 877 | } else { |
| 878 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 879 | } |
| 880 | } |
| 881 | notifyRequester(request); |
| 882 | break; |
| 883 | } |
| 884 | |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 885 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 886 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 887 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 888 | request); |
| 889 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 890 | break; |
| 891 | |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 892 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 893 | ar = (AsyncResult) msg.obj; |
| 894 | request = (MainThreadRequest) ar.userObj; |
| 895 | if (ar.exception == null && ar.result != null) { |
| 896 | request.result = ar.result; // Integer |
| 897 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 898 | // request.result must be set to something non-null |
| 899 | // for the calling thread to unblock |
| 900 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 901 | if (ar.result == null) { |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 902 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 903 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 904 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 905 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 906 | } else { |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 907 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 908 | } |
| 909 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 910 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 911 | break; |
| 912 | |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 913 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 914 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 915 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 916 | request); |
| 917 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 918 | (Pair<Integer, Long>) request.argument; |
| 919 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 920 | reasonWithNetworkTypes.first, |
| 921 | reasonWithNetworkTypes.second, |
| 922 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 923 | break; |
| 924 | |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 925 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 926 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 927 | break; |
| 928 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 929 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 930 | request = (MainThreadRequest)msg.obj; |
| 931 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 932 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 933 | break; |
| 934 | |
| 935 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 936 | ar = (AsyncResult)msg.obj; |
| 937 | request = (MainThreadRequest)ar.userObj; |
| 938 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 939 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 940 | break; |
| 941 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 942 | case CMD_SET_VOICEMAIL_NUMBER: |
| 943 | request = (MainThreadRequest) msg.obj; |
| 944 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 945 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 946 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 947 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 948 | break; |
| 949 | |
| 950 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 951 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 952 | break; |
| 953 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 954 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 955 | request = (MainThreadRequest) msg.obj; |
| 956 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 957 | request); |
| 958 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 959 | break; |
| 960 | |
| 961 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 962 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 963 | break; |
| 964 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 965 | case CMD_PERFORM_NETWORK_SCAN: |
| 966 | request = (MainThreadRequest) msg.obj; |
| 967 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 968 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 969 | break; |
| 970 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 971 | case CMD_GET_CALL_FORWARDING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 972 | request = (MainThreadRequest) msg.obj; |
| 973 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 974 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 975 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 976 | request.argument; |
| 977 | int callForwardingReason = args.first; |
| 978 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 979 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 980 | } |
| 981 | case EVENT_GET_CALL_FORWARDING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 982 | ar = (AsyncResult) msg.obj; |
| 983 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 984 | TelephonyManager.CallForwardingInfoCallback callback = |
| 985 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 986 | request.argument).second; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 987 | if (ar.exception == null && ar.result != null) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 988 | CallForwardingInfo callForwardingInfo = null; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 989 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 990 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 991 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 992 | // any service for voice call. |
| 993 | if ((callForwardInfo.serviceClass |
| 994 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 995 | callForwardingInfo = new CallForwardingInfo(true, |
| 996 | callForwardInfo.reason, |
| 997 | callForwardInfo.number, |
| 998 | callForwardInfo.timeSeconds); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 999 | break; |
| 1000 | } |
| 1001 | } |
| 1002 | // Didn't find a call forward info for voice call. |
| 1003 | if (callForwardingInfo == null) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1004 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 1005 | 0 /* reason */, null /* number */, 0 /* timeout */); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1006 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1007 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1008 | } else { |
| 1009 | if (ar.result == null) { |
| 1010 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1011 | } |
| 1012 | if (ar.exception != null) { |
| 1013 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1014 | } |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1015 | int errorCode = TelephonyManager |
| 1016 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1017 | if (ar.exception instanceof CommandException) { |
| 1018 | CommandException.Error error = |
| 1019 | ((CommandException) (ar.exception)).getCommandError(); |
| 1020 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1021 | errorCode = TelephonyManager |
| 1022 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1023 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1024 | errorCode = TelephonyManager |
| 1025 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1026 | } |
| 1027 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1028 | callback.onError(errorCode); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1029 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1030 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1031 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1032 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1033 | case CMD_SET_CALL_FORWARDING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1034 | request = (MainThreadRequest) msg.obj; |
| 1035 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1036 | request = (MainThreadRequest) msg.obj; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1037 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1038 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1039 | request.argument).first; |
| 1040 | request.phone.setCallForwardingOption( |
| 1041 | callForwardingInfoToSet.isEnabled() |
| 1042 | ? CommandsInterface.CF_ACTION_ENABLE |
| 1043 | : CommandsInterface.CF_ACTION_DISABLE, |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1044 | callForwardingInfoToSet.getReason(), |
| 1045 | callForwardingInfoToSet.getNumber(), |
| 1046 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1047 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1048 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1049 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1050 | case EVENT_SET_CALL_FORWARDING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1051 | ar = (AsyncResult) msg.obj; |
| 1052 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1053 | Consumer<Integer> callback = |
| 1054 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1055 | request.argument).second; |
| 1056 | if (ar.exception != null) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1057 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1058 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1059 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1060 | if (ar.exception instanceof CommandException) { |
| 1061 | CommandException.Error error = |
| 1062 | ((CommandException) (ar.exception)).getCommandError(); |
| 1063 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1064 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1065 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1066 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1067 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1068 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1069 | } |
| 1070 | } |
| 1071 | callback.accept(errorCode); |
| 1072 | } else { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1073 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1074 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1075 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1076 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1077 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1078 | case CMD_GET_CALL_WAITING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1079 | request = (MainThreadRequest) msg.obj; |
| 1080 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1081 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1082 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1083 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1084 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1085 | case EVENT_GET_CALL_WAITING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1086 | ar = (AsyncResult) msg.obj; |
| 1087 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1088 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1089 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1090 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1091 | int[] callForwardResults = (int[]) ar.result; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1092 | // Service Class is a bit mask per 3gpp 27.007. |
| 1093 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1094 | if (callForwardResults.length > 1 |
| 1095 | && ((callForwardResults[1] |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1096 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1097 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1098 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1099 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1100 | } else { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1101 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1102 | } |
| 1103 | } else { |
| 1104 | if (ar.result == null) { |
| 1105 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1106 | } |
| 1107 | if (ar.exception != null) { |
| 1108 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1109 | } |
| 1110 | if (ar.exception instanceof CommandException) { |
| 1111 | CommandException.Error error = |
| 1112 | ((CommandException) (ar.exception)).getCommandError(); |
| 1113 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1114 | callForwardingStatus = |
| 1115 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1116 | } |
| 1117 | } |
| 1118 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1119 | callback.accept(callForwardingStatus); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1120 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1121 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1122 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1123 | case CMD_SET_CALL_WAITING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1124 | request = (MainThreadRequest) msg.obj; |
| 1125 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1126 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1127 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1128 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1129 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1130 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1131 | case EVENT_SET_CALL_WAITING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1132 | ar = (AsyncResult) msg.obj; |
| 1133 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1134 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1135 | Consumer<Integer> callback = |
| 1136 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1137 | if (ar.exception != null) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1138 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1139 | if (ar.exception instanceof CommandException) { |
| 1140 | CommandException.Error error = |
| 1141 | ((CommandException) (ar.exception)).getCommandError(); |
| 1142 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1143 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1144 | } else { |
| 1145 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1146 | } |
| 1147 | } else { |
| 1148 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1149 | } |
| 1150 | } else { |
| 1151 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1152 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1153 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1154 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1155 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1156 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1157 | ar = (AsyncResult) msg.obj; |
| 1158 | request = (MainThreadRequest) ar.userObj; |
| 1159 | CellNetworkScanResult cellScanResult; |
| 1160 | if (ar.exception == null && ar.result != null) { |
| 1161 | cellScanResult = new CellNetworkScanResult( |
| 1162 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1163 | (List<OperatorInfo>) ar.result); |
| 1164 | } else { |
| 1165 | if (ar.result == null) { |
| 1166 | loge("getCellNetworkScanResults: Empty response"); |
| 1167 | } |
| 1168 | if (ar.exception != null) { |
| 1169 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1170 | } |
| 1171 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1172 | if (ar.exception instanceof CommandException) { |
| 1173 | CommandException.Error error = |
| 1174 | ((CommandException) (ar.exception)).getCommandError(); |
| 1175 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1176 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1177 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1178 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1179 | } |
| 1180 | } |
| 1181 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1182 | } |
| 1183 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1184 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1185 | break; |
| 1186 | |
| 1187 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1188 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1189 | ManualNetworkSelectionArgument selArg = |
| 1190 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1191 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1192 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1193 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1194 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1195 | break; |
| 1196 | |
| 1197 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1198 | ar = (AsyncResult) msg.obj; |
| 1199 | request = (MainThreadRequest) ar.userObj; |
| 1200 | if (ar.exception == null) { |
| 1201 | request.result = true; |
| 1202 | } else { |
| 1203 | request.result = false; |
| 1204 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1205 | } |
| 1206 | notifyRequester(request); |
| 1207 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1208 | break; |
| 1209 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1210 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1211 | request = (MainThreadRequest) msg.obj; |
| 1212 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1213 | if (defaultPhone != null) { |
| 1214 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1215 | } else { |
| 1216 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1217 | Bundle bundle = new Bundle(); |
| 1218 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
| 1219 | new ModemActivityInfo(0, 0, 0, new int[0], 0)); |
| 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 | |
| 1224 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 1225 | ar = (AsyncResult) msg.obj; |
| 1226 | request = (MainThreadRequest) ar.userObj; |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1227 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1228 | |
| 1229 | ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1230 | if (ar.exception == null && ar.result != null) { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1231 | // Update the last modem activity info and the result of the request. |
| 1232 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1233 | if (isModemActivityInfoValid(info)) { |
| 1234 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 1235 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1236 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1237 | .getTransmitTimeMillis(); |
| 1238 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1239 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1240 | } |
| 1241 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 1242 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1243 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1244 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1245 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1246 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1247 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1248 | info.getReceiveTimeMillis() |
| 1249 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1250 | } |
| 1251 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 1252 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1253 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1254 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1255 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1256 | } else { |
| 1257 | if (ar.result == null) { |
| 1258 | loge("queryModemActivityInfo: Empty response"); |
| 1259 | } else if (ar.exception instanceof CommandException) { |
| 1260 | loge("queryModemActivityInfo: CommandException: " + |
| 1261 | ar.exception); |
| 1262 | } else { |
| 1263 | loge("queryModemActivityInfo: Unknown exception"); |
| 1264 | } |
| 1265 | } |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1266 | Bundle bundle = new Bundle(); |
| 1267 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1268 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1269 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1270 | break; |
| 1271 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1272 | case CMD_SET_ALLOWED_CARRIERS: |
| 1273 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1274 | CarrierRestrictionRules argument = |
| 1275 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1276 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1277 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1278 | break; |
| 1279 | |
| 1280 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1281 | ar = (AsyncResult) msg.obj; |
| 1282 | request = (MainThreadRequest) ar.userObj; |
| 1283 | if (ar.exception == null && ar.result != null) { |
| 1284 | request.result = ar.result; |
| 1285 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1286 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1287 | if (ar.exception instanceof CommandException) { |
| 1288 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1289 | CommandException.Error error = |
| 1290 | ((CommandException) (ar.exception)).getCommandError(); |
| 1291 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1292 | request.result = |
| 1293 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1294 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1295 | } else { |
| 1296 | loge("setAllowedCarriers: Unknown exception"); |
| 1297 | } |
| 1298 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1299 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1300 | break; |
| 1301 | |
| 1302 | case CMD_GET_ALLOWED_CARRIERS: |
| 1303 | request = (MainThreadRequest) msg.obj; |
| 1304 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1305 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1306 | break; |
| 1307 | |
| 1308 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1309 | ar = (AsyncResult) msg.obj; |
| 1310 | request = (MainThreadRequest) ar.userObj; |
| 1311 | if (ar.exception == null && ar.result != null) { |
| 1312 | request.result = ar.result; |
| 1313 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1314 | request.result = new IllegalStateException( |
| 1315 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1316 | if (ar.result == null) { |
| 1317 | loge("getAllowedCarriers: Empty response"); |
| 1318 | } else if (ar.exception instanceof CommandException) { |
| 1319 | loge("getAllowedCarriers: CommandException: " + |
| 1320 | ar.exception); |
| 1321 | } else { |
| 1322 | loge("getAllowedCarriers: Unknown exception"); |
| 1323 | } |
| 1324 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1325 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1326 | break; |
| 1327 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1328 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1329 | ar = (AsyncResult) msg.obj; |
| 1330 | request = (MainThreadRequest) ar.userObj; |
| 1331 | if (ar.exception == null && ar.result != null) { |
| 1332 | request.result = ar.result; |
| 1333 | } else { |
| 1334 | request.result = new IllegalArgumentException( |
| 1335 | "Failed to retrieve Forbidden Plmns"); |
| 1336 | if (ar.result == null) { |
| 1337 | loge("getForbiddenPlmns: Empty response"); |
| 1338 | } else { |
| 1339 | loge("getForbiddenPlmns: Unknown exception"); |
| 1340 | } |
| 1341 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1342 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1343 | break; |
| 1344 | |
| 1345 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1346 | request = (MainThreadRequest) msg.obj; |
| 1347 | uiccCard = getUiccCardFromRequest(request); |
| 1348 | if (uiccCard == null) { |
| 1349 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1350 | request.result = new IllegalArgumentException( |
| 1351 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1352 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1353 | break; |
| 1354 | } |
| 1355 | Integer appType = (Integer) request.argument; |
| 1356 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1357 | if (uiccApp == null) { |
| 1358 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1359 | + appType); |
| 1360 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1361 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1362 | break; |
| 1363 | } else { |
| 1364 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1365 | + " specified type -- " + appType); |
| 1366 | } |
| 1367 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1368 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1369 | onCompleted); |
| 1370 | break; |
| 1371 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1372 | case CMD_SWITCH_SLOTS: |
| 1373 | request = (MainThreadRequest) msg.obj; |
| 1374 | int[] physicalSlots = (int[]) request.argument; |
| 1375 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1376 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1377 | break; |
| 1378 | |
| 1379 | case EVENT_SWITCH_SLOTS_DONE: |
| 1380 | ar = (AsyncResult) msg.obj; |
| 1381 | request = (MainThreadRequest) ar.userObj; |
| 1382 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1383 | notifyRequester(request); |
| 1384 | break; |
| 1385 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1386 | request = (MainThreadRequest) msg.obj; |
| 1387 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1388 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1389 | break; |
| 1390 | |
| 1391 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1392 | ar = (AsyncResult) msg.obj; |
| 1393 | request = (MainThreadRequest) ar.userObj; |
| 1394 | if (ar.exception != null) { |
| 1395 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1396 | } else { |
| 1397 | int mode = ((int[]) ar.result)[0]; |
| 1398 | if (mode == 0) { |
| 1399 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1400 | } else { |
| 1401 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1402 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1403 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1404 | notifyRequester(request); |
| 1405 | break; |
| 1406 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1407 | request = (MainThreadRequest) msg.obj; |
| 1408 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1409 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1410 | break; |
| 1411 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1412 | ar = (AsyncResult) msg.obj; |
| 1413 | request = (MainThreadRequest) ar.userObj; |
| 1414 | if (ar.exception != null) { |
| 1415 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1416 | } else { |
| 1417 | request.result = ((int[]) ar.result)[0]; |
| 1418 | } |
| 1419 | notifyRequester(request); |
| 1420 | break; |
| 1421 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1422 | request = (MainThreadRequest) msg.obj; |
| 1423 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1424 | int mode = (int) request.argument; |
| 1425 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1426 | break; |
| 1427 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1428 | ar = (AsyncResult) msg.obj; |
| 1429 | request = (MainThreadRequest) ar.userObj; |
| 1430 | request.result = ar.exception == null; |
| 1431 | notifyRequester(request); |
| 1432 | break; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1433 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1434 | request = (MainThreadRequest) msg.obj; |
| 1435 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1436 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1437 | break; |
| 1438 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1439 | ar = (AsyncResult) msg.obj; |
| 1440 | request = (MainThreadRequest) ar.userObj; |
| 1441 | if (ar.exception != null) { |
| 1442 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1443 | } else { |
| 1444 | request.result = ((int[]) ar.result)[0]; |
| 1445 | } |
| 1446 | notifyRequester(request); |
| 1447 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1448 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1449 | request = (MainThreadRequest) msg.obj; |
| 1450 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1451 | int subscriptionMode = (int) request.argument; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1452 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1453 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1454 | break; |
| 1455 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1456 | ar = (AsyncResult) msg.obj; |
| 1457 | request = (MainThreadRequest) ar.userObj; |
| 1458 | request.result = ar.exception == null; |
| 1459 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1460 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1461 | case CMD_GET_ALL_CELL_INFO: |
| 1462 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1463 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1464 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1465 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1466 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1467 | ar = (AsyncResult) msg.obj; |
| 1468 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1469 | // If a timeout occurs, the response will be null |
| 1470 | request.result = (ar.exception == null && ar.result != null) |
| 1471 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1472 | synchronized (request) { |
| 1473 | request.notifyAll(); |
| 1474 | } |
| 1475 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1476 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1477 | request = (MainThreadRequest) msg.obj; |
| 1478 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1479 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1480 | break; |
| 1481 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1482 | ar = (AsyncResult) msg.obj; |
| 1483 | request = (MainThreadRequest) ar.userObj; |
| 1484 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1485 | try { |
| 1486 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1487 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1488 | cb.onError( |
| 1489 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1490 | ar.exception.getClass().getName(), |
| 1491 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1492 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1493 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1494 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1495 | } else { |
| 1496 | // use the result as returned |
| 1497 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1498 | } |
| 1499 | } catch (RemoteException re) { |
| 1500 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1501 | } |
| 1502 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1503 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1504 | request = (MainThreadRequest) msg.obj; |
| 1505 | WorkSource ws = (WorkSource) request.argument; |
| 1506 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1507 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1508 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1509 | } |
| 1510 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1511 | ar = (AsyncResult) msg.obj; |
| 1512 | request = (MainThreadRequest) ar.userObj; |
| 1513 | if (ar.exception == null) { |
| 1514 | request.result = ar.result; |
| 1515 | } else { |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1516 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1517 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1518 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | synchronized (request) { |
| 1522 | request.notifyAll(); |
| 1523 | } |
| 1524 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1525 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1526 | case CMD_MODEM_REBOOT: |
| 1527 | request = (MainThreadRequest) msg.obj; |
| 1528 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1529 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1530 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1531 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1532 | handleNullReturnEvent(msg, "rebootModem"); |
| 1533 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1534 | case CMD_REQUEST_ENABLE_MODEM: |
| 1535 | request = (MainThreadRequest) msg.obj; |
| 1536 | boolean enable = (boolean) request.argument; |
| 1537 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1538 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1539 | PhoneConfigurationManager.getInstance() |
| 1540 | .enablePhone(request.phone, enable, onCompleted); |
| 1541 | break; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1542 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1543 | ar = (AsyncResult) msg.obj; |
| 1544 | request = (MainThreadRequest) ar.userObj; |
| 1545 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1546 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1547 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1548 | if ((boolean) request.result) { |
| 1549 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1550 | updateModemStateMetrics(); |
| 1551 | } else { |
| 1552 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1553 | + ar.exception); |
| 1554 | } |
| 1555 | notifyRequester(request); |
| 1556 | break; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1557 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1558 | case CMD_GET_MODEM_STATUS: |
| 1559 | request = (MainThreadRequest) msg.obj; |
| 1560 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1561 | PhoneConfigurationManager.getInstance() |
| 1562 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1563 | break; |
| 1564 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1565 | ar = (AsyncResult) msg.obj; |
| 1566 | request = (MainThreadRequest) ar.userObj; |
| 1567 | int id = request.phone.getPhoneId(); |
| 1568 | if (ar.exception == null && ar.result != null) { |
| 1569 | request.result = ar.result; |
| 1570 | //update the cache as modem status has changed |
| 1571 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1572 | (boolean) request.result); |
| 1573 | } else { |
| 1574 | // Return true if modem status cannot be retrieved. For most cases, |
| 1575 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1576 | // and disable modem are not supported. Modem is always on. |
| 1577 | // TODO: this should be fixed in R to support a third |
| 1578 | // status UNKNOWN b/131631629 |
| 1579 | request.result = true; |
| 1580 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1581 | + ar.exception); |
| 1582 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1583 | notifyRequester(request); |
| 1584 | break; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1585 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1586 | request = (MainThreadRequest) msg.obj; |
| 1587 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1588 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1589 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1590 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1591 | break; |
| 1592 | } |
| 1593 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1594 | ar = (AsyncResult) msg.obj; |
| 1595 | request = (MainThreadRequest) ar.userObj; |
| 1596 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1597 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1598 | args.second.accept(ar.exception == null); |
| 1599 | notifyRequester(request); |
| 1600 | break; |
| 1601 | } |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1602 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1603 | request = (MainThreadRequest) msg.obj; |
| 1604 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1605 | Phone phone = getPhoneFromRequest(request); |
| 1606 | if (phone != null) { |
| 1607 | phone.getSystemSelectionChannels(onCompleted); |
| 1608 | } else { |
| 1609 | loge("getSystemSelectionChannels: No phone object"); |
| 1610 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1611 | notifyRequester(request); |
| 1612 | } |
| 1613 | break; |
| 1614 | } |
| 1615 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1616 | ar = (AsyncResult) msg.obj; |
| 1617 | request = (MainThreadRequest) ar.userObj; |
| 1618 | if (ar.exception == null && ar.result != null) { |
| 1619 | request.result = ar.result; |
| 1620 | } else { |
| 1621 | request.result = new IllegalArgumentException( |
| 1622 | "Failed to retrieve system selection channels"); |
| 1623 | if (ar.result == null) { |
| 1624 | loge("getSystemSelectionChannels: Empty response"); |
| 1625 | } else { |
| 1626 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1627 | } |
| 1628 | } |
| 1629 | notifyRequester(request); |
| 1630 | break; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1631 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1632 | ar = (AsyncResult) msg.obj; |
| 1633 | request = (MainThreadRequest) ar.userObj; |
| 1634 | if (ar.exception == null && ar.result != null) { |
| 1635 | request.result = ar.result; |
| 1636 | } else { |
| 1637 | request.result = -1; |
| 1638 | loge("Failed to set Forbidden Plmns"); |
| 1639 | if (ar.result == null) { |
| 1640 | loge("setForbidenPlmns: Empty response"); |
| 1641 | } else if (ar.exception != null) { |
| 1642 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1643 | request.result = -1; |
| 1644 | } else { |
| 1645 | loge("setForbiddenPlmns: Unknown exception"); |
| 1646 | } |
| 1647 | } |
| 1648 | notifyRequester(request); |
| 1649 | break; |
| 1650 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1651 | request = (MainThreadRequest) msg.obj; |
| 1652 | uiccCard = getUiccCardFromRequest(request); |
| 1653 | if (uiccCard == null) { |
| 1654 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1655 | request.result = -1; |
| 1656 | notifyRequester(request); |
| 1657 | break; |
| 1658 | } |
| 1659 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1660 | (Pair<Integer, List<String>>) request.argument; |
| 1661 | appType = setFplmnsArgs.first; |
| 1662 | List<String> fplmns = setFplmnsArgs.second; |
| 1663 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1664 | if (uiccApp == null) { |
| 1665 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1666 | request.result = -1; |
| 1667 | loge("Failed to get UICC App"); |
| 1668 | notifyRequester(request); |
| 1669 | } else { |
| 1670 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1671 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1672 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1673 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1674 | break; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1675 | case CMD_ERASE_MODEM_CONFIG: |
| 1676 | request = (MainThreadRequest) msg.obj; |
| 1677 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1678 | defaultPhone.eraseModemConfig(onCompleted); |
| 1679 | break; |
| 1680 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1681 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1682 | break; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1683 | |
| 1684 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1685 | request = (MainThreadRequest) msg.obj; |
| 1686 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1687 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1688 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1689 | changed.first, changed.second, onCompleted); |
| 1690 | break; |
| 1691 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1692 | ar = (AsyncResult) msg.obj; |
| 1693 | request = (MainThreadRequest) ar.userObj; |
| 1694 | if (ar.exception == null) { |
| 1695 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1696 | // If the operation is successful, update the PIN storage |
| 1697 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1698 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1699 | UiccController.getInstance().getPinStorage() |
| 1700 | .storePin(passwords.second, phoneId); |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1701 | } else { |
| 1702 | request.result = msg.arg1; |
| 1703 | } |
| 1704 | notifyRequester(request); |
| 1705 | break; |
| 1706 | |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1707 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1708 | request = (MainThreadRequest) msg.obj; |
| 1709 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1710 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1711 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1712 | enabled.first, enabled.second, onCompleted); |
| 1713 | break; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1714 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1715 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1716 | ar = (AsyncResult) msg.obj; |
| 1717 | request = (MainThreadRequest) ar.userObj; |
| 1718 | if (ar.exception == null) { |
| 1719 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1720 | // If the operation is successful, update the PIN storage |
| 1721 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1722 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1723 | if (enabled.first) { |
| 1724 | UiccController.getInstance().getPinStorage() |
| 1725 | .storePin(enabled.second, phoneId); |
| 1726 | } else { |
| 1727 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1728 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1729 | } else { |
| 1730 | request.result = msg.arg1; |
| 1731 | } |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1732 | |
| 1733 | |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1734 | notifyRequester(request); |
| 1735 | break; |
| 1736 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1737 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1738 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1739 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1740 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1741 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1742 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1743 | break; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 1744 | |
| 1745 | case CMD_SET_DATA_THROTTLING: { |
| 1746 | request = (MainThreadRequest) msg.obj; |
| 1747 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1748 | DataThrottlingRequest dataThrottlingRequest = |
| 1749 | (DataThrottlingRequest) request.argument; |
| 1750 | Phone phone = getPhoneFromRequest(request); |
| 1751 | if (phone != null) { |
| 1752 | phone.setDataThrottling(onCompleted, |
| 1753 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1754 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1755 | } else { |
| 1756 | loge("setDataThrottling: No phone object"); |
| 1757 | request.result = |
| 1758 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1759 | notifyRequester(request); |
| 1760 | } |
| 1761 | |
| 1762 | break; |
| 1763 | } |
| 1764 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1765 | ar = (AsyncResult) msg.obj; |
| 1766 | request = (MainThreadRequest) ar.userObj; |
| 1767 | |
| 1768 | if (ar.exception == null) { |
| 1769 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1770 | } else if (ar.exception instanceof CommandException) { |
| 1771 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1772 | CommandException.Error error = |
| 1773 | ((CommandException) (ar.exception)).getCommandError(); |
| 1774 | |
| 1775 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1776 | request.result = TelephonyManager |
| 1777 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1778 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1779 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 1780 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1781 | request.result = MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 1782 | } else { |
| 1783 | request.result = |
| 1784 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1785 | } |
| 1786 | } else { |
| 1787 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1788 | } |
| 1789 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1790 | notifyRequester(request); |
| 1791 | break; |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1792 | |
| 1793 | case CMD_SET_SIM_POWER: { |
| 1794 | request = (MainThreadRequest) msg.obj; |
| 1795 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1796 | request = (MainThreadRequest) msg.obj; |
| 1797 | int stateToSet = |
| 1798 | ((Pair<Integer, IIntegerConsumer>) |
| 1799 | request.argument).first; |
| 1800 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1801 | break; |
| 1802 | } |
| 1803 | case EVENT_SET_SIM_POWER_DONE: { |
| 1804 | ar = (AsyncResult) msg.obj; |
| 1805 | request = (MainThreadRequest) ar.userObj; |
| 1806 | IIntegerConsumer callback = |
| 1807 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 1808 | if (ar.exception != null) { |
| 1809 | loge("setSimPower exception: " + ar.exception); |
| 1810 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1811 | .RESULT_ERROR_UNKNOWN; |
| 1812 | if (ar.exception instanceof CommandException) { |
| 1813 | CommandException.Error error = |
| 1814 | ((CommandException) (ar.exception)).getCommandError(); |
| 1815 | if (error == CommandException.Error.SIM_ERR) { |
| 1816 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 1817 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1818 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 1819 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1820 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 1821 | } else { |
| 1822 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 1823 | } |
| 1824 | } |
| 1825 | try { |
| 1826 | callback.accept(errorCode); |
| 1827 | } catch (RemoteException e) { |
| 1828 | // Ignore if the remote process is no longer available to call back. |
| 1829 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1830 | } |
| 1831 | } else { |
| 1832 | try { |
| 1833 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 1834 | } catch (RemoteException e) { |
| 1835 | // Ignore if the remote process is no longer available to call back. |
| 1836 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1837 | } |
| 1838 | } |
| 1839 | break; |
| 1840 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 1841 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1842 | request = (MainThreadRequest) msg.obj; |
| 1843 | |
| 1844 | final Phone phone = getPhoneFromRequest(request); |
| 1845 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1846 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1847 | notifyRequester(request); |
| 1848 | break; |
| 1849 | } |
| 1850 | |
| 1851 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1852 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1853 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1854 | request); |
| 1855 | phone.getServiceStateTracker().setSignalStrengthUpdateRequest( |
| 1856 | request.subId, pair.first /*callingUid*/, |
| 1857 | pair.second /*request*/, onCompleted); |
| 1858 | break; |
| 1859 | } |
| 1860 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1861 | ar = (AsyncResult) msg.obj; |
| 1862 | request = (MainThreadRequest) ar.userObj; |
| 1863 | // request.result will be the exception of ar if present, true otherwise. |
| 1864 | // Be cautious not to leave result null which will wait() forever |
| 1865 | request.result = ar.exception != null ? ar.exception : true; |
| 1866 | notifyRequester(request); |
| 1867 | break; |
| 1868 | } |
| 1869 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1870 | request = (MainThreadRequest) msg.obj; |
| 1871 | |
| 1872 | Phone phone = getPhoneFromRequest(request); |
| 1873 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1874 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1875 | notifyRequester(request); |
| 1876 | break; |
| 1877 | } |
| 1878 | |
| 1879 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1880 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1881 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1882 | request); |
| 1883 | phone.getServiceStateTracker().clearSignalStrengthUpdateRequest( |
| 1884 | request.subId, pair.first /*callingUid*/, |
| 1885 | pair.second /*request*/, onCompleted); |
| 1886 | break; |
| 1887 | } |
| 1888 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1889 | ar = (AsyncResult) msg.obj; |
| 1890 | request = (MainThreadRequest) ar.userObj; |
| 1891 | request.result = ar.exception != null ? ar.exception : true; |
| 1892 | notifyRequester(request); |
| 1893 | break; |
| 1894 | } |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1895 | |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1896 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 1897 | request = (MainThreadRequest) msg.obj; |
| 1898 | request.result = |
| 1899 | UiccController.getInstance().getPinStorage().prepareUnattendedReboot(); |
| 1900 | notifyRequester(request); |
| 1901 | break; |
| 1902 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1903 | default: |
| 1904 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1905 | break; |
| 1906 | } |
| 1907 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1908 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1909 | private void notifyRequester(MainThreadRequest request) { |
| 1910 | synchronized (request) { |
| 1911 | request.notifyAll(); |
| 1912 | } |
| 1913 | } |
| 1914 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1915 | private void handleNullReturnEvent(Message msg, String command) { |
| 1916 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1917 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1918 | if (ar.exception == null) { |
| 1919 | request.result = true; |
| 1920 | } else { |
| 1921 | request.result = false; |
| 1922 | if (ar.exception instanceof CommandException) { |
| 1923 | loge(command + ": CommandException: " + ar.exception); |
| 1924 | } else { |
| 1925 | loge(command + ": Unknown exception"); |
| 1926 | } |
| 1927 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1928 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1929 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1930 | } |
| 1931 | |
| 1932 | /** |
| 1933 | * Posts the specified command to be executed on the main thread, |
| 1934 | * waits for the request to complete, and returns the result. |
| 1935 | * @see #sendRequestAsync |
| 1936 | */ |
| 1937 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1938 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 1939 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1940 | } |
| 1941 | |
| 1942 | /** |
| 1943 | * Posts the specified command to be executed on the main thread, |
| 1944 | * waits for the request to complete, and returns the result. |
| 1945 | * @see #sendRequestAsync |
| 1946 | */ |
| 1947 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1948 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1949 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -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 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1957 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1958 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 1959 | } |
| 1960 | |
| 1961 | /** |
| 1962 | * Posts the specified command to be executed on the main thread, |
| 1963 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 1964 | * if not timeout or null otherwise. |
| 1965 | * @see #sendRequestAsync |
| 1966 | */ |
| 1967 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 1968 | long timeoutInMs) { |
| 1969 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1970 | } |
| 1971 | |
| 1972 | /** |
| 1973 | * Posts the specified command to be executed on the main thread, |
| 1974 | * waits for the request to complete, and returns the result. |
| 1975 | * @see #sendRequestAsync |
| 1976 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1977 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1978 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1979 | } |
| 1980 | |
| 1981 | /** |
| 1982 | * Posts the specified command to be executed on the main thread, |
| 1983 | * waits for the request to complete, and returns the result. |
| 1984 | * @see #sendRequestAsync |
| 1985 | */ |
| 1986 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1987 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 1988 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1989 | } |
| 1990 | |
| 1991 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1992 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 1993 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 1994 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1995 | * @see #sendRequestAsync |
| 1996 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1997 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 1998 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1999 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 2000 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 2001 | } |
| 2002 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2003 | MainThreadRequest request = null; |
| 2004 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 2005 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2006 | } else if (phone != null) { |
| 2007 | request = new MainThreadRequest(argument, phone, workSource); |
| 2008 | } else { |
| 2009 | request = new MainThreadRequest(argument, subId, workSource); |
| 2010 | } |
| 2011 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2012 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2013 | msg.sendToTarget(); |
| 2014 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2015 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2016 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2017 | if (timeoutInMs >= 0) { |
| 2018 | // Wait for at least timeoutInMs before returning null request result |
| 2019 | long now = SystemClock.elapsedRealtime(); |
| 2020 | long deadline = now + timeoutInMs; |
| 2021 | while (request == null && now < deadline) { |
| 2022 | try { |
| 2023 | request.wait(deadline - now); |
| 2024 | } catch (InterruptedException e) { |
| 2025 | // Do nothing, go back and check if request is completed or timeout |
| 2026 | } finally { |
| 2027 | now = SystemClock.elapsedRealtime(); |
| 2028 | } |
| 2029 | } |
| 2030 | } else { |
| 2031 | // Wait for the request to complete |
| 2032 | while (request.result == null) { |
| 2033 | try { |
| 2034 | request.wait(); |
| 2035 | } catch (InterruptedException e) { |
| 2036 | // Do nothing, go back and wait until the request is complete |
| 2037 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2038 | } |
| 2039 | } |
| 2040 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2041 | if (request.result == null) { |
| 2042 | Log.wtf(LOG_TAG, |
| 2043 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2044 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2045 | return request.result; |
| 2046 | } |
| 2047 | |
| 2048 | /** |
| 2049 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2050 | * Posts the specified command to be executed on the main thread, and |
| 2051 | * returns immediately. |
| 2052 | * @see #sendRequest |
| 2053 | */ |
| 2054 | private void sendRequestAsync(int command) { |
| 2055 | mMainThreadHandler.sendEmptyMessage(command); |
| 2056 | } |
| 2057 | |
| 2058 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2059 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2060 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2061 | */ |
| 2062 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2063 | sendRequestAsync(command, argument, null, null); |
| 2064 | } |
| 2065 | |
| 2066 | /** |
| 2067 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2068 | * @see {@link #sendRequest(int,Object)} |
| 2069 | */ |
| 2070 | private void sendRequestAsync( |
| 2071 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2072 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2073 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2074 | msg.sendToTarget(); |
| 2075 | } |
| 2076 | |
| 2077 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2078 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2079 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2080 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2081 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2082 | synchronized (PhoneInterfaceManager.class) { |
| 2083 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2084 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2085 | } else { |
| 2086 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2087 | } |
| 2088 | return sInstance; |
| 2089 | } |
| 2090 | } |
| 2091 | |
| 2092 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2093 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2094 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2095 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 2096 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2097 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2098 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2099 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2100 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2101 | mTelephonySharedPreferences = |
| 2102 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2103 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2104 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Daniel Bright | fe1e6ac | 2021-03-12 10:25:03 -0800 | [diff] [blame] | 2105 | mRadioInterfaceCapabilities = RadioInterfaceCapabilityController.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2106 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2107 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2108 | publish(); |
| 2109 | } |
| 2110 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2111 | private Phone getDefaultPhone() { |
| 2112 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2113 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2114 | } |
| 2115 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2116 | private void publish() { |
| 2117 | if (DBG) log("publish: " + this); |
| 2118 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2119 | TelephonyFrameworkInitializer |
| 2120 | .getTelephonyServiceManager() |
| 2121 | .getTelephonyServiceRegisterer() |
| 2122 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2123 | } |
| 2124 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2125 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2126 | if (request.phone != null) { |
| 2127 | return request.phone; |
| 2128 | } else { |
| 2129 | return getPhoneFromSubId(request.subId); |
| 2130 | } |
| 2131 | } |
| 2132 | |
| 2133 | private Phone getPhoneFromSubId(int subId) { |
| 2134 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2135 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2136 | } |
| 2137 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2138 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 2139 | Phone phone = getPhoneFromRequest(request); |
| 2140 | return phone == null ? null : |
| 2141 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 2142 | } |
| 2143 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2144 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2145 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2146 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2147 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2148 | |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2149 | private void sendEraseModemConfig(Phone phone) { |
| 2150 | if (phone != null) { |
| 2151 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2152 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 2153 | final long identity = Binder.clearCallingIdentity(); |
| 2154 | try { |
| 2155 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2156 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2157 | } finally { |
| 2158 | Binder.restoreCallingIdentity(identity); |
| 2159 | } |
| 2160 | } |
| 2161 | } |
| 2162 | |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2163 | private boolean isImsAvailableOnDevice() { |
| 2164 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2165 | if (pm == null) { |
| 2166 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2167 | // so do not throw error and allow. |
| 2168 | return true; |
| 2169 | } |
| 2170 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2171 | } |
| 2172 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2173 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2174 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2175 | } |
| 2176 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2177 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2178 | if (DBG) log("dial: " + number); |
| 2179 | // No permission check needed here: This is just a wrapper around the |
| 2180 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2181 | // the UI before it does anything. |
| 2182 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2183 | final long identity = Binder.clearCallingIdentity(); |
| 2184 | try { |
| 2185 | String url = createTelUrl(number); |
| 2186 | if (url == null) { |
| 2187 | return; |
| 2188 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2189 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2190 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2191 | PhoneConstants.State state = mCM.getState(subId); |
| 2192 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2193 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2194 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2195 | mApp.startActivity(intent); |
| 2196 | } |
| 2197 | } finally { |
| 2198 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2199 | } |
| 2200 | } |
| 2201 | |
| 2202 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2203 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2204 | } |
| 2205 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2206 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2207 | if (DBG) log("call: " + number); |
| 2208 | |
| 2209 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2210 | // need to do a permission check since we're calling startActivity() |
| 2211 | // from the context of the phone app. |
| 2212 | enforceCallPermission(); |
| 2213 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2214 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2215 | != AppOpsManager.MODE_ALLOWED) { |
| 2216 | return; |
| 2217 | } |
| 2218 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2219 | final long identity = Binder.clearCallingIdentity(); |
| 2220 | try { |
| 2221 | String url = createTelUrl(number); |
| 2222 | if (url == null) { |
| 2223 | return; |
| 2224 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2225 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2226 | boolean isValid = false; |
| 2227 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2228 | if (slist != null) { |
| 2229 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2230 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2231 | isValid = true; |
| 2232 | break; |
| 2233 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2234 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2235 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2236 | if (!isValid) { |
| 2237 | return; |
| 2238 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2239 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2240 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2241 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2242 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2243 | mApp.startActivity(intent); |
| 2244 | } finally { |
| 2245 | Binder.restoreCallingIdentity(identity); |
| 2246 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2247 | } |
| 2248 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2249 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2250 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2251 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2252 | } |
| 2253 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2254 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2255 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2256 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2257 | } |
| 2258 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2259 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2260 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2261 | |
| 2262 | final long identity = Binder.clearCallingIdentity(); |
| 2263 | try { |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2264 | Phone phone = getPhone(subId); |
| 2265 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2266 | checkSimPin.start(); |
| 2267 | return checkSimPin.unlockSim(null, pin); |
| 2268 | } finally { |
| 2269 | Binder.restoreCallingIdentity(identity); |
| 2270 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2271 | } |
| 2272 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2273 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2274 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2275 | |
| 2276 | final long identity = Binder.clearCallingIdentity(); |
| 2277 | try { |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2278 | Phone phone = getPhone(subId); |
| 2279 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2280 | checkSimPuk.start(); |
| 2281 | return checkSimPuk.unlockSim(puk, pin); |
| 2282 | } finally { |
| 2283 | Binder.restoreCallingIdentity(identity); |
| 2284 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2285 | } |
| 2286 | |
| 2287 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2288 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2289 | * a synchronous one. |
| 2290 | */ |
| 2291 | private static class UnlockSim extends Thread { |
| 2292 | |
| 2293 | private final IccCard mSimCard; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2294 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2295 | |
| 2296 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2297 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2298 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2299 | |
| 2300 | // For replies from SimCard interface |
| 2301 | private Handler mHandler; |
| 2302 | |
| 2303 | // For async handler to identify request type |
| 2304 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2305 | |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2306 | UnlockSim(int phoneId, IccCard simCard) { |
| 2307 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2308 | mSimCard = simCard; |
| 2309 | } |
| 2310 | |
| 2311 | @Override |
| 2312 | public void run() { |
| 2313 | Looper.prepare(); |
| 2314 | synchronized (UnlockSim.this) { |
| 2315 | mHandler = new Handler() { |
| 2316 | @Override |
| 2317 | public void handleMessage(Message msg) { |
| 2318 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2319 | switch (msg.what) { |
| 2320 | case SUPPLY_PIN_COMPLETE: |
| 2321 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2322 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2323 | mRetryCount = msg.arg1; |
| 2324 | if (ar.exception != null) { |
| 2325 | if (ar.exception instanceof CommandException && |
| 2326 | ((CommandException)(ar.exception)).getCommandError() |
| 2327 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2328 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2329 | } //When UiccCardApp dispose,handle message and return exception |
| 2330 | else if (ar.exception instanceof CommandException && |
| 2331 | ((CommandException) (ar.exception)).getCommandError() |
| 2332 | == CommandException.Error.ABORTED) { |
| 2333 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2334 | } else { |
| 2335 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2336 | } |
| 2337 | } else { |
| 2338 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2339 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2340 | mDone = true; |
| 2341 | UnlockSim.this.notifyAll(); |
| 2342 | } |
| 2343 | break; |
| 2344 | } |
| 2345 | } |
| 2346 | }; |
| 2347 | UnlockSim.this.notifyAll(); |
| 2348 | } |
| 2349 | Looper.loop(); |
| 2350 | } |
| 2351 | |
| 2352 | /* |
| 2353 | * Use PIN or PUK to unlock SIM card |
| 2354 | * |
| 2355 | * If PUK is null, unlock SIM card with PIN |
| 2356 | * |
| 2357 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2358 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2359 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2360 | |
| 2361 | while (mHandler == null) { |
| 2362 | try { |
| 2363 | wait(); |
| 2364 | } catch (InterruptedException e) { |
| 2365 | Thread.currentThread().interrupt(); |
| 2366 | } |
| 2367 | } |
| 2368 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2369 | |
| 2370 | if (puk == null) { |
| 2371 | mSimCard.supplyPin(pin, callback); |
| 2372 | } else { |
| 2373 | mSimCard.supplyPuk(puk, pin, callback); |
| 2374 | } |
| 2375 | |
| 2376 | while (!mDone) { |
| 2377 | try { |
| 2378 | Log.d(LOG_TAG, "wait for done"); |
| 2379 | wait(); |
| 2380 | } catch (InterruptedException e) { |
| 2381 | // Restore the interrupted status |
| 2382 | Thread.currentThread().interrupt(); |
| 2383 | } |
| 2384 | } |
| 2385 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2386 | int[] resultArray = new int[2]; |
| 2387 | resultArray[0] = mResult; |
| 2388 | resultArray[1] = mRetryCount; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2389 | |
| 2390 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
| 2391 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
| 2392 | } |
| 2393 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2394 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2395 | } |
| 2396 | } |
| 2397 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2398 | /** |
| 2399 | * This method has been removed due to privacy and stability concerns. |
| 2400 | */ |
| 2401 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2402 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2403 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2404 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2405 | } |
| 2406 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2407 | @Override |
| 2408 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2409 | mApp.getSystemService(AppOpsManager.class) |
| 2410 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2411 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2412 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2413 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2414 | // Callers targeting S have no business invoking this method. |
| 2415 | return; |
| 2416 | } |
| 2417 | |
| 2418 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2419 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2420 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2421 | .setCallingPackage(callingPackage) |
| 2422 | .setCallingFeatureId(null) |
| 2423 | .setCallingPid(Binder.getCallingPid()) |
| 2424 | .setCallingUid(Binder.getCallingUid()) |
| 2425 | .setMethod("updateServiceLocation") |
| 2426 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2427 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2428 | .build()); |
| 2429 | // Apps that lack location permission have no business calling this method; |
| 2430 | // however, because no permission was declared in the public API, denials must |
| 2431 | // all be "soft". |
| 2432 | switch (locationResult) { |
| 2433 | case DENIED_HARD: /* fall through */ |
| 2434 | case DENIED_SOFT: |
| 2435 | return; |
| 2436 | } |
| 2437 | |
| 2438 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2439 | final long identity = Binder.clearCallingIdentity(); |
| 2440 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2441 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2442 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2443 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2444 | } |
| 2445 | } finally { |
| 2446 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2447 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2448 | } |
| 2449 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2450 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2451 | @Override |
| 2452 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2453 | return isRadioOnWithFeature(callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2454 | } |
| 2455 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2456 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2457 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2458 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2459 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2460 | callingFeatureId); |
| 2461 | } |
| 2462 | |
| 2463 | @Deprecated |
| 2464 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2465 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2466 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
| 2467 | } |
| 2468 | |
| 2469 | @Override |
| 2470 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2471 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2472 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2473 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2474 | return false; |
| 2475 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2476 | |
| 2477 | final long identity = Binder.clearCallingIdentity(); |
| 2478 | try { |
| 2479 | return isRadioOnForSubscriber(subId); |
| 2480 | } finally { |
| 2481 | Binder.restoreCallingIdentity(identity); |
| 2482 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2483 | } |
| 2484 | |
| 2485 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2486 | final long identity = Binder.clearCallingIdentity(); |
| 2487 | try { |
| 2488 | final Phone phone = getPhone(subId); |
| 2489 | if (phone != null) { |
| 2490 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2491 | } else { |
| 2492 | return false; |
| 2493 | } |
| 2494 | } finally { |
| 2495 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2496 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2497 | } |
| 2498 | |
| 2499 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2500 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2501 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2502 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2503 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2504 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2505 | |
| 2506 | final long identity = Binder.clearCallingIdentity(); |
| 2507 | try { |
| 2508 | final Phone phone = getPhone(subId); |
| 2509 | if (phone != null) { |
| 2510 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2511 | } |
| 2512 | } finally { |
| 2513 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2514 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2515 | } |
| 2516 | |
| 2517 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2518 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2519 | } |
| 2520 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2521 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2522 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2523 | |
| 2524 | final long identity = Binder.clearCallingIdentity(); |
| 2525 | try { |
| 2526 | final Phone phone = getPhone(subId); |
| 2527 | if (phone == null) { |
| 2528 | return false; |
| 2529 | } |
| 2530 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2531 | toggleRadioOnOffForSubscriber(subId); |
| 2532 | } |
| 2533 | return true; |
| 2534 | } finally { |
| 2535 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2536 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2537 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2538 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2539 | public boolean needMobileRadioShutdown() { |
Shuo Qian | afeaf7d | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2540 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2541 | /* |
| 2542 | * If any of the Radios are available, it will need to be |
| 2543 | * shutdown. So return true if any Radio is available. |
| 2544 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2545 | final long identity = Binder.clearCallingIdentity(); |
| 2546 | try { |
| 2547 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2548 | Phone phone = PhoneFactory.getPhone(i); |
| 2549 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2550 | } |
| 2551 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2552 | return false; |
| 2553 | } finally { |
| 2554 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2555 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2556 | } |
| 2557 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2558 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2559 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2560 | enforceModifyPermission(); |
| 2561 | |
| 2562 | final long identity = Binder.clearCallingIdentity(); |
| 2563 | try { |
| 2564 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2565 | logv("Shutting down Phone " + i); |
| 2566 | shutdownRadioUsingPhoneId(i); |
| 2567 | } |
| 2568 | } finally { |
| 2569 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2570 | } |
| 2571 | } |
| 2572 | |
| 2573 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2574 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2575 | if (phone != null && phone.isRadioAvailable()) { |
| 2576 | phone.shutdownRadio(); |
| 2577 | } |
| 2578 | } |
| 2579 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2580 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2581 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2582 | |
| 2583 | final long identity = Binder.clearCallingIdentity(); |
| 2584 | try { |
| 2585 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2586 | if (defaultPhone != null) { |
| 2587 | defaultPhone.setRadioPower(turnOn); |
| 2588 | return true; |
| 2589 | } else { |
| 2590 | loge("There's no default phone."); |
| 2591 | return false; |
| 2592 | } |
| 2593 | } finally { |
| 2594 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2595 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2596 | } |
| 2597 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2598 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2599 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2600 | |
| 2601 | final long identity = Binder.clearCallingIdentity(); |
| 2602 | try { |
| 2603 | final Phone phone = getPhone(subId); |
| 2604 | if (phone != null) { |
| 2605 | phone.setRadioPower(turnOn); |
| 2606 | return true; |
| 2607 | } else { |
| 2608 | return false; |
| 2609 | } |
| 2610 | } finally { |
| 2611 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2612 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2613 | } |
| 2614 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2615 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2616 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2617 | public boolean enableDataConnectivity() { |
| 2618 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2619 | |
| 2620 | final long identity = Binder.clearCallingIdentity(); |
| 2621 | try { |
| 2622 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2623 | final Phone phone = getPhone(subId); |
| 2624 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 2625 | phone.getDataEnabledSettings().setDataEnabled( |
| 2626 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2627 | return true; |
| 2628 | } else { |
| 2629 | return false; |
| 2630 | } |
| 2631 | } finally { |
| 2632 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2633 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2634 | } |
| 2635 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2636 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2637 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2638 | public boolean disableDataConnectivity() { |
| 2639 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2640 | |
| 2641 | final long identity = Binder.clearCallingIdentity(); |
| 2642 | try { |
| 2643 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2644 | final Phone phone = getPhone(subId); |
| 2645 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 2646 | phone.getDataEnabledSettings().setDataEnabled( |
| 2647 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2648 | return true; |
| 2649 | } else { |
| 2650 | return false; |
| 2651 | } |
| 2652 | } finally { |
| 2653 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2654 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2655 | } |
| 2656 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2657 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2658 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2659 | final long identity = Binder.clearCallingIdentity(); |
| 2660 | try { |
| 2661 | final Phone phone = getPhone(subId); |
| 2662 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2663 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2664 | } else { |
| 2665 | return false; |
| 2666 | } |
| 2667 | } finally { |
| 2668 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2669 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2670 | } |
| 2671 | |
| 2672 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2673 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2674 | } |
| 2675 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2676 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2677 | enforceCallPermission(); |
| 2678 | |
| 2679 | final long identity = Binder.clearCallingIdentity(); |
| 2680 | try { |
| 2681 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2682 | return; |
| 2683 | } |
| 2684 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2685 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2686 | } finally { |
| 2687 | Binder.restoreCallingIdentity(identity); |
| 2688 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2689 | }; |
| 2690 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2691 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2692 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2693 | |
| 2694 | final long identity = Binder.clearCallingIdentity(); |
| 2695 | try { |
| 2696 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2697 | return false; |
| 2698 | } |
| 2699 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2700 | } finally { |
| 2701 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2702 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2703 | } |
| 2704 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2705 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2706 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2707 | } |
| 2708 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2709 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2710 | final long identity = Binder.clearCallingIdentity(); |
| 2711 | try { |
| 2712 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2713 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2714 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2715 | } finally { |
| 2716 | Binder.restoreCallingIdentity(identity); |
| 2717 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2718 | } |
| 2719 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2720 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2721 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2722 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2723 | } |
| 2724 | |
| 2725 | @Override |
| 2726 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2727 | final long identity = Binder.clearCallingIdentity(); |
| 2728 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2729 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2730 | if (phone != null) { |
| 2731 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2732 | } else { |
| 2733 | return PhoneConstantConversions.convertDataState( |
| 2734 | PhoneConstants.DataState.DISCONNECTED); |
| 2735 | } |
| 2736 | } finally { |
| 2737 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2738 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2739 | } |
| 2740 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2741 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2742 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2743 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2744 | } |
| 2745 | |
| 2746 | @Override |
| 2747 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2748 | final long identity = Binder.clearCallingIdentity(); |
| 2749 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2750 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2751 | if (phone != null) { |
| 2752 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2753 | } else { |
| 2754 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2755 | } |
| 2756 | } finally { |
| 2757 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2758 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2759 | } |
| 2760 | |
| 2761 | @Override |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2762 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2763 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2764 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2765 | |
| 2766 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2767 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2768 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2769 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2770 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2771 | .setCallingPid(Binder.getCallingPid()) |
| 2772 | .setCallingUid(Binder.getCallingUid()) |
| 2773 | .setMethod("getCellLocation") |
Hall Liu | c3f8eb6 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2774 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2775 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2776 | .build()); |
| 2777 | switch (locationResult) { |
| 2778 | case DENIED_HARD: |
| 2779 | throw new SecurityException("Not allowed to access cell location"); |
| 2780 | case DENIED_SOFT: |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2781 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2782 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2783 | } |
| 2784 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2785 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2786 | final long identity = Binder.clearCallingIdentity(); |
| 2787 | try { |
| 2788 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2789 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2790 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2791 | } finally { |
| 2792 | Binder.restoreCallingIdentity(identity); |
| 2793 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2794 | } |
| 2795 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2796 | @Override |
Jack Yu | 0142503 | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2797 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2798 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2799 | // registered cell info, so return a NULL country instead. |
| 2800 | final long identity = Binder.clearCallingIdentity(); |
| 2801 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2802 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2803 | // Get default phone in this case. |
| 2804 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2805 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2806 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2807 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | cf38ed9 | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2808 | if (phone == null) return ""; |
| 2809 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2810 | if (sst == null) return ""; |
| 2811 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2812 | if (lt == null) return ""; |
Shuo Qian | 9418a92 | 2021-03-09 11:21:16 -0800 | [diff] [blame] | 2813 | return lt.getCurrentCountry(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2814 | } finally { |
| 2815 | Binder.restoreCallingIdentity(identity); |
| 2816 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2817 | } |
| 2818 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2819 | /** |
| 2820 | * This method was removed due to potential issues caused by performing partial |
| 2821 | * updates of service state, and lack of a credible use case. |
| 2822 | * |
| 2823 | * This has the ability to break the telephony implementation by disabling notification of |
| 2824 | * changes in device connectivity. DO NOT USE THIS! |
| 2825 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2826 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2827 | public void enableLocationUpdates() { |
| 2828 | mApp.enforceCallingOrSelfPermission( |
| 2829 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2830 | } |
| 2831 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2832 | /** |
| 2833 | * This method was removed due to potential issues caused by performing partial |
| 2834 | * updates of service state, and lack of a credible use case. |
| 2835 | * |
| 2836 | * This has the ability to break the telephony implementation by disabling notification of |
| 2837 | * changes in device connectivity. DO NOT USE THIS! |
| 2838 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2839 | @Override |
| 2840 | public void disableLocationUpdates() { |
| 2841 | mApp.enforceCallingOrSelfPermission( |
| 2842 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2843 | } |
| 2844 | |
| 2845 | @Override |
| 2846 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2847 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2848 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2849 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2850 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2851 | throw new SecurityException( |
| 2852 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2853 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2854 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2855 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2856 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2857 | return null; |
| 2858 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2859 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2860 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2861 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2862 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2863 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2864 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2865 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2866 | for (CellInfo ci : info) { |
| 2867 | if (ci instanceof CellInfoGsm) { |
| 2868 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2869 | } else if (ci instanceof CellInfoWcdma) { |
| 2870 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2871 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2872 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2873 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2874 | } |
| 2875 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2876 | private List<CellInfo> getCachedCellInfo() { |
| 2877 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2878 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2879 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2880 | if (info != null) cellInfos.addAll(info); |
| 2881 | } |
| 2882 | return cellInfos; |
| 2883 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2884 | |
| 2885 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2886 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2887 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2888 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2889 | |
| 2890 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2891 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2892 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2893 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2894 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2895 | .setCallingPid(Binder.getCallingPid()) |
| 2896 | .setCallingUid(Binder.getCallingUid()) |
| 2897 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2898 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2899 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2900 | .build()); |
| 2901 | switch (locationResult) { |
| 2902 | case DENIED_HARD: |
| 2903 | throw new SecurityException("Not allowed to access cell info"); |
| 2904 | case DENIED_SOFT: |
| 2905 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2906 | } |
| 2907 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2908 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2909 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2910 | return getCachedCellInfo(); |
| 2911 | } |
| 2912 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2913 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2914 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2915 | final long identity = Binder.clearCallingIdentity(); |
| 2916 | try { |
| 2917 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2918 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2919 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2920 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2921 | if (info != null) cellInfos.addAll(info); |
| 2922 | } |
| 2923 | return cellInfos; |
| 2924 | } finally { |
| 2925 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2926 | } |
| 2927 | } |
| 2928 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2929 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2930 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2931 | String callingFeatureId) { |
| 2932 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2933 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2934 | } |
| 2935 | |
| 2936 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2937 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2938 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2939 | enforceModifyPermission(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2940 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2941 | } |
| 2942 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2943 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2944 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2945 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2946 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2947 | |
| 2948 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2949 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2950 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2951 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2952 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2953 | .setCallingPid(Binder.getCallingPid()) |
| 2954 | .setCallingUid(Binder.getCallingUid()) |
| 2955 | .setMethod("requestCellInfoUpdate") |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2956 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2957 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2958 | .build()); |
| 2959 | switch (locationResult) { |
| 2960 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2961 | if (TelephonyPermissions |
| 2962 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2963 | // Safetynet logging for b/154934934 |
| 2964 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2965 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2966 | throw new SecurityException("Not allowed to access cell info"); |
| 2967 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2968 | if (TelephonyPermissions |
| 2969 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2970 | // Safetynet logging for b/154934934 |
| 2971 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2972 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2973 | try { |
| 2974 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2975 | } catch (RemoteException re) { |
| 2976 | // Drop without consequences |
| 2977 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2978 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2979 | } |
| 2980 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2981 | |
| 2982 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2983 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2984 | |
| 2985 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2986 | } |
| 2987 | |
| 2988 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2989 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2990 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2991 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2992 | |
| 2993 | final long identity = Binder.clearCallingIdentity(); |
| 2994 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2995 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2996 | } finally { |
| 2997 | Binder.restoreCallingIdentity(identity); |
| 2998 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2999 | } |
| 3000 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3001 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3002 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3003 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3004 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3005 | return null; |
| 3006 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3007 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3008 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3009 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3010 | return null; |
| 3011 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3012 | |
| 3013 | final long identity = Binder.clearCallingIdentity(); |
| 3014 | try { |
| 3015 | return phone.getImei(); |
| 3016 | } finally { |
| 3017 | Binder.restoreCallingIdentity(identity); |
| 3018 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3019 | } |
| 3020 | |
| 3021 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3022 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3023 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3024 | String tac = null; |
| 3025 | if (phone != null) { |
| 3026 | String imei = phone.getImei(); |
| 3027 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3028 | } |
| 3029 | return tac; |
| 3030 | } |
| 3031 | |
| 3032 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3033 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3034 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3035 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3036 | return null; |
| 3037 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3038 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3039 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3040 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3041 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3042 | return null; |
| 3043 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3044 | |
| 3045 | final long identity = Binder.clearCallingIdentity(); |
| 3046 | try { |
| 3047 | return phone.getMeid(); |
| 3048 | } finally { |
| 3049 | Binder.restoreCallingIdentity(identity); |
| 3050 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3051 | } |
| 3052 | |
| 3053 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3054 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3055 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3056 | String manufacturerCode = null; |
| 3057 | if (phone != null) { |
| 3058 | String meid = phone.getMeid(); |
| 3059 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3060 | } |
| 3061 | return manufacturerCode; |
| 3062 | } |
| 3063 | |
| 3064 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3065 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3066 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3067 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3068 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3069 | return null; |
| 3070 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3071 | int subId = phone.getSubId(); |
| 3072 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3073 | mApp, subId, callingPackage, callingFeatureId, |
| 3074 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3075 | return null; |
| 3076 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3077 | |
| 3078 | final long identity = Binder.clearCallingIdentity(); |
| 3079 | try { |
| 3080 | return phone.getDeviceSvn(); |
| 3081 | } finally { |
| 3082 | Binder.restoreCallingIdentity(identity); |
| 3083 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3084 | } |
| 3085 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3086 | @Override |
| 3087 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3088 | final long identity = Binder.clearCallingIdentity(); |
| 3089 | try { |
| 3090 | final Phone phone = getPhone(subId); |
| 3091 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3092 | } finally { |
| 3093 | Binder.restoreCallingIdentity(identity); |
| 3094 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3095 | } |
| 3096 | |
| 3097 | @Override |
| 3098 | public String getSubscriptionCarrierName(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 ? null : phone.getCarrierName(); |
| 3103 | } finally { |
| 3104 | Binder.restoreCallingIdentity(identity); |
| 3105 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3106 | } |
| 3107 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3108 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3109 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3110 | final long identity = Binder.clearCallingIdentity(); |
| 3111 | try { |
| 3112 | final Phone phone = getPhone(subId); |
| 3113 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3114 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3115 | } finally { |
| 3116 | Binder.restoreCallingIdentity(identity); |
| 3117 | } |
| 3118 | } |
| 3119 | |
| 3120 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3121 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3122 | final long identity = Binder.clearCallingIdentity(); |
| 3123 | try { |
| 3124 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3125 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3126 | } finally { |
| 3127 | Binder.restoreCallingIdentity(identity); |
| 3128 | } |
| 3129 | } |
| 3130 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3131 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3132 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3133 | if (!isSubscriptionMccMnc) { |
| 3134 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3135 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3136 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3137 | if (phone == null) { |
| 3138 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3139 | } |
| 3140 | final long identity = Binder.clearCallingIdentity(); |
| 3141 | try { |
| 3142 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3143 | } finally { |
| 3144 | Binder.restoreCallingIdentity(identity); |
| 3145 | } |
| 3146 | } |
| 3147 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3148 | // |
| 3149 | // Internal helper methods. |
| 3150 | // |
| 3151 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3152 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3153 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3154 | * |
| 3155 | * @throws SecurityException if the caller does not have the required permission |
| 3156 | */ |
| 3157 | private void enforceModifyPermission() { |
| 3158 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3159 | } |
| 3160 | |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3161 | /** |
| 3162 | * Make sure the caller is system. |
| 3163 | * |
| 3164 | * @throws SecurityException if the caller is not system. |
| 3165 | */ |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 3166 | private static void enforceSystemCaller() { |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3167 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 3168 | throw new SecurityException("Caller must be system"); |
| 3169 | } |
| 3170 | } |
| 3171 | |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3172 | private void enforceActiveEmergencySessionPermission() { |
| 3173 | mApp.enforceCallingOrSelfPermission( |
| 3174 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3175 | } |
| 3176 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3177 | /** |
| 3178 | * Make sure the caller has the CALL_PHONE permission. |
| 3179 | * |
| 3180 | * @throws SecurityException if the caller does not have the required permission |
| 3181 | */ |
| 3182 | private void enforceCallPermission() { |
| 3183 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3184 | } |
| 3185 | |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3186 | private void enforceSettingsPermission() { |
| 3187 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3188 | } |
| 3189 | |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3190 | private void enforceRebootPermission() { |
| 3191 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3192 | } |
| 3193 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3194 | private String createTelUrl(String number) { |
| 3195 | if (TextUtils.isEmpty(number)) { |
| 3196 | return null; |
| 3197 | } |
| 3198 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3199 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3200 | } |
| 3201 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3202 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3203 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3204 | } |
| 3205 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3206 | private static void logv(String msg) { |
| 3207 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3208 | } |
| 3209 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3210 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3211 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3212 | } |
| 3213 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3214 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3215 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3216 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3217 | } |
| 3218 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3219 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3220 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3221 | final long identity = Binder.clearCallingIdentity(); |
| 3222 | try { |
| 3223 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3224 | if (phone == null) { |
| 3225 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3226 | } else { |
| 3227 | return phone.getPhoneType(); |
| 3228 | } |
| 3229 | } finally { |
| 3230 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3231 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3232 | } |
| 3233 | |
| 3234 | /** |
| 3235 | * Returns the CDMA ERI icon index to display |
| 3236 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3237 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3238 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3239 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3240 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3241 | } |
| 3242 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3243 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3244 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3245 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3246 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3247 | mApp, subId, callingPackage, callingFeatureId, |
| 3248 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3249 | return -1; |
| 3250 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3251 | |
| 3252 | final long identity = Binder.clearCallingIdentity(); |
| 3253 | try { |
| 3254 | final Phone phone = getPhone(subId); |
| 3255 | if (phone != null) { |
| 3256 | return phone.getCdmaEriIconIndex(); |
| 3257 | } else { |
| 3258 | return -1; |
| 3259 | } |
| 3260 | } finally { |
| 3261 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3262 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3263 | } |
| 3264 | |
| 3265 | /** |
| 3266 | * Returns the CDMA ERI icon mode, |
| 3267 | * 0 - ON |
| 3268 | * 1 - FLASHING |
| 3269 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3270 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3271 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3272 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3273 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3274 | } |
| 3275 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3276 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3277 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3278 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3279 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3280 | mApp, subId, callingPackage, callingFeatureId, |
| 3281 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3282 | return -1; |
| 3283 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3284 | |
| 3285 | final long identity = Binder.clearCallingIdentity(); |
| 3286 | try { |
| 3287 | final Phone phone = getPhone(subId); |
| 3288 | if (phone != null) { |
| 3289 | return phone.getCdmaEriIconMode(); |
| 3290 | } else { |
| 3291 | return -1; |
| 3292 | } |
| 3293 | } finally { |
| 3294 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3295 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3296 | } |
| 3297 | |
| 3298 | /** |
| 3299 | * Returns the CDMA ERI text, |
| 3300 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3301 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3302 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3303 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3304 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3305 | } |
| 3306 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3307 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3308 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3309 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3310 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3311 | mApp, subId, callingPackage, callingFeatureId, |
| 3312 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3313 | return null; |
| 3314 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3315 | |
| 3316 | final long identity = Binder.clearCallingIdentity(); |
| 3317 | try { |
| 3318 | final Phone phone = getPhone(subId); |
| 3319 | if (phone != null) { |
| 3320 | return phone.getCdmaEriText(); |
| 3321 | } else { |
| 3322 | return null; |
| 3323 | } |
| 3324 | } finally { |
| 3325 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3326 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3327 | } |
| 3328 | |
| 3329 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3330 | * Returns the CDMA MDN. |
| 3331 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3332 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3333 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3334 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3335 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3336 | |
| 3337 | final long identity = Binder.clearCallingIdentity(); |
| 3338 | try { |
| 3339 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3340 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3341 | return phone.getLine1Number(); |
| 3342 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3343 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3344 | return null; |
| 3345 | } |
| 3346 | } finally { |
| 3347 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3348 | } |
| 3349 | } |
| 3350 | |
| 3351 | /** |
| 3352 | * Returns the CDMA MIN. |
| 3353 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3354 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3355 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3356 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3357 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3358 | |
| 3359 | final long identity = Binder.clearCallingIdentity(); |
| 3360 | try { |
| 3361 | final Phone phone = getPhone(subId); |
| 3362 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3363 | return phone.getCdmaMin(); |
| 3364 | } else { |
| 3365 | return null; |
| 3366 | } |
| 3367 | } finally { |
| 3368 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3369 | } |
| 3370 | } |
| 3371 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3372 | @Override |
| 3373 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3374 | INumberVerificationCallback callback, String callingPackage) { |
| 3375 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3376 | != PERMISSION_GRANTED) { |
| 3377 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3378 | } |
| 3379 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3380 | |
| 3381 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3382 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3383 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3384 | + "calling package: " + callingPackage |
| 3385 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3386 | } |
| 3387 | |
| 3388 | if (range == null) { |
| 3389 | throw new NullPointerException("Range must be non-null"); |
| 3390 | } |
| 3391 | |
| 3392 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3393 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3394 | |
| 3395 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3396 | } |
| 3397 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3398 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3399 | * Returns true if CDMA provisioning needs to run. |
| 3400 | */ |
| 3401 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3402 | final long identity = Binder.clearCallingIdentity(); |
| 3403 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3404 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3405 | } finally { |
| 3406 | Binder.restoreCallingIdentity(identity); |
| 3407 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3408 | } |
| 3409 | |
| 3410 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3411 | * Sets the voice mail number of a given subId. |
| 3412 | */ |
| 3413 | @Override |
| 3414 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3415 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3416 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3417 | |
| 3418 | final long identity = Binder.clearCallingIdentity(); |
| 3419 | try { |
| 3420 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3421 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3422 | return success; |
| 3423 | } finally { |
| 3424 | Binder.restoreCallingIdentity(identity); |
| 3425 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3426 | } |
| 3427 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3428 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3429 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3430 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3431 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3432 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3433 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3434 | throw new SecurityException("caller must be system dialer"); |
| 3435 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3436 | |
| 3437 | final long identity = Binder.clearCallingIdentity(); |
| 3438 | try { |
| 3439 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3440 | if (phoneAccountHandle == null) { |
| 3441 | return null; |
| 3442 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3443 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3444 | } finally { |
| 3445 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3446 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3447 | } |
| 3448 | |
| 3449 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3450 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3451 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3452 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3453 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3454 | mApp, subId, callingPackage, callingFeatureId, |
| 3455 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3456 | return null; |
| 3457 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3458 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3459 | final long identity = Binder.clearCallingIdentity(); |
| 3460 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3461 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3462 | } finally { |
| 3463 | Binder.restoreCallingIdentity(identity); |
| 3464 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3465 | } |
| 3466 | |
| 3467 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3468 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3469 | VisualVoicemailSmsFilterSettings settings) { |
| 3470 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3471 | |
| 3472 | final long identity = Binder.clearCallingIdentity(); |
| 3473 | try { |
| 3474 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3475 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3476 | } finally { |
| 3477 | Binder.restoreCallingIdentity(identity); |
| 3478 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3479 | } |
| 3480 | |
| 3481 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3482 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3483 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3484 | |
| 3485 | final long identity = Binder.clearCallingIdentity(); |
| 3486 | try { |
| 3487 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3488 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3489 | } finally { |
| 3490 | Binder.restoreCallingIdentity(identity); |
| 3491 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3492 | } |
| 3493 | |
| 3494 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3495 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3496 | String callingPackage, int subId) { |
| 3497 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3498 | |
| 3499 | final long identity = Binder.clearCallingIdentity(); |
| 3500 | try { |
| 3501 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3502 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3503 | } finally { |
| 3504 | Binder.restoreCallingIdentity(identity); |
| 3505 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3506 | } |
| 3507 | |
| 3508 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3509 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3510 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3511 | |
| 3512 | final long identity = Binder.clearCallingIdentity(); |
| 3513 | try { |
| 3514 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3515 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3516 | } finally { |
| 3517 | Binder.restoreCallingIdentity(identity); |
| 3518 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3519 | } |
| 3520 | |
| 3521 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3522 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3523 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3524 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3525 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3526 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3527 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3528 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3529 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3530 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3531 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3532 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3533 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3534 | * Sets the voice activation state of a given subId. |
| 3535 | */ |
| 3536 | @Override |
| 3537 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3538 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3539 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3540 | |
| 3541 | final long identity = Binder.clearCallingIdentity(); |
| 3542 | try { |
| 3543 | final Phone phone = getPhone(subId); |
| 3544 | if (phone != null) { |
| 3545 | phone.setVoiceActivationState(activationState); |
| 3546 | } else { |
| 3547 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3548 | } |
| 3549 | } finally { |
| 3550 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3551 | } |
| 3552 | } |
| 3553 | |
| 3554 | /** |
| 3555 | * Sets the data activation state of a given subId. |
| 3556 | */ |
| 3557 | @Override |
| 3558 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3559 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3560 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3561 | |
| 3562 | final long identity = Binder.clearCallingIdentity(); |
| 3563 | try { |
| 3564 | final Phone phone = getPhone(subId); |
| 3565 | if (phone != null) { |
| 3566 | phone.setDataActivationState(activationState); |
| 3567 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3568 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3569 | } |
| 3570 | } finally { |
| 3571 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3572 | } |
| 3573 | } |
| 3574 | |
| 3575 | /** |
| 3576 | * Returns the voice activation state of a given subId. |
| 3577 | */ |
| 3578 | @Override |
| 3579 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3580 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3581 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3582 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3583 | final long identity = Binder.clearCallingIdentity(); |
| 3584 | try { |
| 3585 | if (phone != null) { |
| 3586 | return phone.getVoiceActivationState(); |
| 3587 | } else { |
| 3588 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3589 | } |
| 3590 | } finally { |
| 3591 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3592 | } |
| 3593 | } |
| 3594 | |
| 3595 | /** |
| 3596 | * Returns the data activation state of a given subId. |
| 3597 | */ |
| 3598 | @Override |
| 3599 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3600 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3601 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3602 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3603 | final long identity = Binder.clearCallingIdentity(); |
| 3604 | try { |
| 3605 | if (phone != null) { |
| 3606 | return phone.getDataActivationState(); |
| 3607 | } else { |
| 3608 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3609 | } |
| 3610 | } finally { |
| 3611 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3612 | } |
| 3613 | } |
| 3614 | |
| 3615 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3616 | * Returns the unread count of voicemails for a subId |
| 3617 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3618 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3619 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3620 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3621 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3622 | mApp, subId, callingPackage, callingFeatureId, |
| 3623 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3624 | return 0; |
| 3625 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3626 | final long identity = Binder.clearCallingIdentity(); |
| 3627 | try { |
| 3628 | final Phone phone = getPhone(subId); |
| 3629 | if (phone != null) { |
| 3630 | return phone.getVoiceMessageCount(); |
| 3631 | } else { |
| 3632 | return 0; |
| 3633 | } |
| 3634 | } finally { |
| 3635 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3636 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3637 | } |
| 3638 | |
| 3639 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3640 | * returns true, if the device is in a state where both voice and data |
| 3641 | * are supported simultaneously. This can change based on location or network condition. |
| 3642 | */ |
| 3643 | @Override |
| 3644 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3645 | final long identity = Binder.clearCallingIdentity(); |
| 3646 | try { |
| 3647 | final Phone phone = getPhone(subId); |
| 3648 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3649 | } finally { |
| 3650 | Binder.restoreCallingIdentity(identity); |
| 3651 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3652 | } |
| 3653 | |
| 3654 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3655 | * Send the dialer code if called from the current default dialer or the caller has |
| 3656 | * carrier privilege. |
| 3657 | * @param inputCode The dialer code to send |
| 3658 | */ |
| 3659 | @Override |
| 3660 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3661 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3662 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3663 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3664 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3665 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3666 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3667 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3668 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3669 | |
| 3670 | final long identity = Binder.clearCallingIdentity(); |
| 3671 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3672 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3673 | } finally { |
| 3674 | Binder.restoreCallingIdentity(identity); |
| 3675 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3676 | } |
| 3677 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3678 | @Override |
| 3679 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3680 | TelephonyPermissions |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3681 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3682 | mApp, subId, "getNetworkSelectionMode"); |
| 3683 | final long identity = Binder.clearCallingIdentity(); |
| 3684 | try { |
| 3685 | if (!isActiveSubscription(subId)) { |
| 3686 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3687 | } |
| 3688 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3689 | } finally { |
| 3690 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3691 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3692 | } |
| 3693 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3694 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3695 | public boolean isInEmergencySmsMode() { |
| 3696 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3697 | final long identity = Binder.clearCallingIdentity(); |
| 3698 | try { |
| 3699 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3700 | if (phone.isInEmergencySmsMode()) { |
| 3701 | return true; |
| 3702 | } |
| 3703 | } |
| 3704 | } finally { |
| 3705 | Binder.restoreCallingIdentity(identity); |
| 3706 | } |
| 3707 | return false; |
| 3708 | } |
| 3709 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3710 | /** |
| 3711 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3712 | * @param subId The subscription to use to check the configuration. |
| 3713 | * @param c The callback that will be used to send the result. |
| 3714 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3715 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3716 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3717 | throws RemoteException { |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3718 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3719 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3720 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3721 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3722 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3723 | "IMS not available on device."); |
| 3724 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3725 | final long token = Binder.clearCallingIdentity(); |
| 3726 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3727 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3728 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3729 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3730 | } catch (ImsException e) { |
| 3731 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3732 | } finally { |
| 3733 | Binder.restoreCallingIdentity(token); |
| 3734 | } |
| 3735 | } |
| 3736 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3737 | /** |
| 3738 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3739 | * @param subId The subscription to use to check the configuration. |
| 3740 | * @param c The callback that will be used to send the result. |
| 3741 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3742 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3743 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3744 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3745 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3746 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3747 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3748 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3749 | final long token = Binder.clearCallingIdentity(); |
| 3750 | try { |
| 3751 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3752 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3753 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3754 | } catch (ImsException e) { |
| 3755 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3756 | + "is inactive, ignoring unregister."); |
| 3757 | // If the subscription is no longer active, just return, since the callback |
| 3758 | // will already have been removed internally. |
| 3759 | } finally { |
| 3760 | Binder.restoreCallingIdentity(token); |
| 3761 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3762 | } |
| 3763 | |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3764 | /** |
| 3765 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3766 | */ |
| 3767 | @Override |
| 3768 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3769 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3770 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3771 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3772 | "IMS not available on device."); |
| 3773 | } |
| 3774 | final long token = Binder.clearCallingIdentity(); |
| 3775 | try { |
| 3776 | Phone phone = getPhone(subId); |
| 3777 | if (phone == null) { |
| 3778 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3779 | + subId + "'"); |
| 3780 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3781 | } |
| 3782 | phone.getImsRegistrationState(regState -> { |
| 3783 | try { |
| 3784 | consumer.accept((regState == null) |
| 3785 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3786 | } catch (RemoteException e) { |
| 3787 | // Ignore if the remote process is no longer available to call back. |
| 3788 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3789 | } |
| 3790 | }); |
| 3791 | } finally { |
| 3792 | Binder.restoreCallingIdentity(token); |
| 3793 | } |
| 3794 | } |
| 3795 | |
| 3796 | /** |
| 3797 | * Get the transport type for the IMS service registration state. |
| 3798 | */ |
| 3799 | @Override |
| 3800 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3801 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3802 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3803 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3804 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3805 | "IMS not available on device."); |
| 3806 | } |
| 3807 | final long token = Binder.clearCallingIdentity(); |
| 3808 | try { |
| 3809 | Phone phone = getPhone(subId); |
| 3810 | if (phone == null) { |
| 3811 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3812 | + subId + "'"); |
| 3813 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3814 | } |
| 3815 | phone.getImsRegistrationTech(regTech -> { |
| 3816 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3817 | int regTechConverted = (regTech == null) |
| 3818 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3819 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3820 | regTechConverted); |
| 3821 | try { |
| 3822 | consumer.accept(regTechConverted); |
| 3823 | } catch (RemoteException e) { |
| 3824 | // Ignore if the remote process is no longer available to call back. |
| 3825 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3826 | } |
| 3827 | }); |
| 3828 | } finally { |
| 3829 | Binder.restoreCallingIdentity(token); |
| 3830 | } |
| 3831 | } |
| 3832 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3833 | /** |
| 3834 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3835 | * @param subId The subscription to use to check the configuration. |
| 3836 | * @param c The callback that will be used to send the result. |
| 3837 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3838 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3839 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3840 | throws RemoteException { |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3841 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3842 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3843 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3844 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3845 | "IMS not available on device."); |
| 3846 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3847 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3848 | final long token = Binder.clearCallingIdentity(); |
| 3849 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3850 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3851 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3852 | } catch (ImsException e) { |
| 3853 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3854 | } finally { |
| 3855 | Binder.restoreCallingIdentity(token); |
| 3856 | } |
| 3857 | } |
| 3858 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3859 | /** |
| 3860 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3861 | * @param subId The subscription to use to check the configuration. |
| 3862 | * @param c The callback that will be used to send the result. |
| 3863 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3864 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3865 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3866 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3867 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3868 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3869 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3870 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3871 | |
| 3872 | final long token = Binder.clearCallingIdentity(); |
| 3873 | try { |
| 3874 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3875 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3876 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3877 | } catch (ImsException e) { |
| 3878 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3879 | + "is inactive, ignoring unregister."); |
| 3880 | // If the subscription is no longer active, just return, since the callback |
| 3881 | // will already have been removed internally. |
| 3882 | } finally { |
| 3883 | Binder.restoreCallingIdentity(token); |
| 3884 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3885 | } |
| 3886 | |
| 3887 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3888 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3889 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3890 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3891 | final long token = Binder.clearCallingIdentity(); |
| 3892 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3893 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3894 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3895 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3896 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3897 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3898 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3899 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3900 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3901 | } finally { |
| 3902 | Binder.restoreCallingIdentity(token); |
| 3903 | } |
| 3904 | } |
| 3905 | |
| 3906 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3907 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3908 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3909 | final long token = Binder.clearCallingIdentity(); |
| 3910 | try { |
| 3911 | Phone phone = getPhone(subId); |
| 3912 | if (phone == null) return false; |
| 3913 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 32706d9 | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3914 | } catch (com.android.ims.ImsException e) { |
| 3915 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3916 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3917 | } finally { |
| 3918 | Binder.restoreCallingIdentity(token); |
| 3919 | } |
| 3920 | } |
| 3921 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3922 | /** |
| 3923 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3924 | * subscription. |
| 3925 | * @param subId The subscription to use to check the configuration. |
| 3926 | * @param callback The callback that will be used to send the result. |
| 3927 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3928 | * @param transportType The transport type of the MmTelFeature capability. |
| 3929 | */ |
| 3930 | @Override |
| 3931 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3932 | int transportType) { |
| 3933 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3934 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3935 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3936 | "IMS not available on device."); |
| 3937 | } |
| 3938 | final long token = Binder.clearCallingIdentity(); |
| 3939 | try { |
| 3940 | int slotId = getSlotIndex(subId); |
| 3941 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3942 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3943 | + subId + "'"); |
| 3944 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3945 | } |
| 3946 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3947 | transportType, aBoolean -> { |
| 3948 | try { |
| 3949 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3950 | } catch (RemoteException e) { |
| 3951 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3952 | + "running. Ignore"); |
| 3953 | } |
| 3954 | }); |
| 3955 | } finally { |
| 3956 | Binder.restoreCallingIdentity(token); |
| 3957 | } |
| 3958 | } |
| 3959 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3960 | /** |
| 3961 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3962 | * @param subId The subscription to use to check the configuration. |
| 3963 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3964 | @Override |
| 3965 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 3966 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3967 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3968 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3969 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3970 | final long token = Binder.clearCallingIdentity(); |
| 3971 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3972 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3973 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3974 | } catch (ImsException e) { |
| 3975 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3976 | } finally { |
| 3977 | Binder.restoreCallingIdentity(token); |
| 3978 | } |
| 3979 | } |
| 3980 | |
| 3981 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3982 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3983 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3984 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3985 | final long identity = Binder.clearCallingIdentity(); |
| 3986 | try { |
| 3987 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3988 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3989 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3990 | } catch (ImsException e) { |
| 3991 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3992 | } finally { |
| 3993 | Binder.restoreCallingIdentity(identity); |
| 3994 | } |
| 3995 | } |
| 3996 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3997 | /** |
| 3998 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3999 | * @param subId The subscription to use to check the configuration. |
| 4000 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4001 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 4002 | public boolean isVtSettingEnabled(int subId) { |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4003 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4004 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4005 | final long identity = Binder.clearCallingIdentity(); |
| 4006 | try { |
| 4007 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4008 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 4009 | } catch (ImsException e) { |
| 4010 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4011 | } finally { |
| 4012 | Binder.restoreCallingIdentity(identity); |
| 4013 | } |
| 4014 | } |
| 4015 | |
| 4016 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4017 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4018 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4019 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4020 | final long identity = Binder.clearCallingIdentity(); |
| 4021 | try { |
| 4022 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4023 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4024 | } catch (ImsException e) { |
| 4025 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4026 | } finally { |
| 4027 | Binder.restoreCallingIdentity(identity); |
| 4028 | } |
| 4029 | } |
| 4030 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4031 | /** |
| 4032 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4033 | * @param subId The subscription to use to check the configuration. |
| 4034 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4035 | @Override |
| 4036 | public boolean isVoWiFiSettingEnabled(int subId) { |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4037 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4038 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4039 | final long identity = Binder.clearCallingIdentity(); |
| 4040 | try { |
| 4041 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4042 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4043 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4044 | } catch (ImsException e) { |
| 4045 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4046 | } finally { |
| 4047 | Binder.restoreCallingIdentity(identity); |
| 4048 | } |
| 4049 | } |
| 4050 | |
| 4051 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4052 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4053 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4054 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4055 | final long identity = Binder.clearCallingIdentity(); |
| 4056 | try { |
| 4057 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4058 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4059 | } catch (ImsException e) { |
| 4060 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4061 | } finally { |
| 4062 | Binder.restoreCallingIdentity(identity); |
| 4063 | } |
| 4064 | } |
| 4065 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4066 | /** |
| 4067 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4068 | * @param subId The subscription to use to check the configuration. |
| 4069 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4070 | @Override |
| 4071 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4072 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4073 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4074 | final long identity = Binder.clearCallingIdentity(); |
| 4075 | try { |
| 4076 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4077 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4078 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4079 | } catch (ImsException e) { |
| 4080 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4081 | } finally { |
| 4082 | Binder.restoreCallingIdentity(identity); |
| 4083 | } |
| 4084 | } |
| 4085 | |
| 4086 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4087 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4088 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4089 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4090 | final long identity = Binder.clearCallingIdentity(); |
| 4091 | try { |
| 4092 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4093 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4094 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4095 | } catch (ImsException e) { |
| 4096 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4097 | } finally { |
| 4098 | Binder.restoreCallingIdentity(identity); |
| 4099 | } |
| 4100 | } |
| 4101 | |
| 4102 | @Override |
| 4103 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4104 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4105 | "setVoWiFiNonPersistent"); |
| 4106 | final long identity = Binder.clearCallingIdentity(); |
| 4107 | try { |
| 4108 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4109 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 4110 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4111 | } catch (ImsException e) { |
| 4112 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4113 | } finally { |
| 4114 | Binder.restoreCallingIdentity(identity); |
| 4115 | } |
| 4116 | } |
| 4117 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4118 | /** |
| 4119 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4120 | * @param subId The subscription to use to check the configuration. |
| 4121 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4122 | @Override |
| 4123 | public int getVoWiFiModeSetting(int subId) { |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4124 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4125 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4126 | final long identity = Binder.clearCallingIdentity(); |
| 4127 | try { |
| 4128 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4129 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4130 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4131 | } catch (ImsException e) { |
| 4132 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4133 | } finally { |
| 4134 | Binder.restoreCallingIdentity(identity); |
| 4135 | } |
| 4136 | } |
| 4137 | |
| 4138 | @Override |
| 4139 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4140 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4141 | "setVoWiFiModeSetting"); |
| 4142 | final long identity = Binder.clearCallingIdentity(); |
| 4143 | try { |
| 4144 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4145 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4146 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4147 | } catch (ImsException e) { |
| 4148 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4149 | } finally { |
| 4150 | Binder.restoreCallingIdentity(identity); |
| 4151 | } |
| 4152 | } |
| 4153 | |
| 4154 | @Override |
| 4155 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4156 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4157 | final long identity = Binder.clearCallingIdentity(); |
| 4158 | try { |
| 4159 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4160 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4161 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4162 | } catch (ImsException e) { |
| 4163 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4164 | } finally { |
| 4165 | Binder.restoreCallingIdentity(identity); |
| 4166 | } |
| 4167 | } |
| 4168 | |
| 4169 | @Override |
| 4170 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4171 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4172 | "setVoWiFiRoamingModeSetting"); |
| 4173 | final long identity = Binder.clearCallingIdentity(); |
| 4174 | try { |
| 4175 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4176 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4177 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4178 | } catch (ImsException e) { |
| 4179 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4180 | } finally { |
| 4181 | Binder.restoreCallingIdentity(identity); |
| 4182 | } |
| 4183 | } |
| 4184 | |
| 4185 | @Override |
| 4186 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4187 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4188 | "setRttCapabilityEnabled"); |
| 4189 | final long identity = Binder.clearCallingIdentity(); |
| 4190 | try { |
| 4191 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4192 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 4193 | } catch (ImsException e) { |
| 4194 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4195 | } finally { |
| 4196 | Binder.restoreCallingIdentity(identity); |
| 4197 | } |
| 4198 | } |
| 4199 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4200 | /** |
| 4201 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4202 | * @param subId The subscription to use to check the configuration. |
| 4203 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4204 | @Override |
| 4205 | public boolean isTtyOverVolteEnabled(int subId) { |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 4206 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4207 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4208 | final long identity = Binder.clearCallingIdentity(); |
| 4209 | try { |
| 4210 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4211 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4212 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4213 | } catch (ImsException e) { |
| 4214 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4215 | } finally { |
| 4216 | Binder.restoreCallingIdentity(identity); |
| 4217 | } |
| 4218 | } |
| 4219 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4220 | @Override |
| 4221 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4222 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 4223 | final long identity = Binder.clearCallingIdentity(); |
| 4224 | try { |
Brad Ebinger | 6cf0f65 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4225 | if (!isImsAvailableOnDevice()) { |
| 4226 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4227 | "IMS not available on device."); |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4228 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4229 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4230 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4231 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4232 | } catch (ImsException e) { |
| 4233 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4234 | } finally { |
| 4235 | Binder.restoreCallingIdentity(identity); |
| 4236 | } |
| 4237 | } |
| 4238 | |
| 4239 | @Override |
| 4240 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4241 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 4242 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4243 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4244 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4245 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4246 | try { |
| 4247 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4248 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4249 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4250 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4251 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4252 | + "is inactive, ignoring unregister."); |
| 4253 | // If the subscription is no longer active, just return, since the callback will already |
| 4254 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4255 | } finally { |
| 4256 | Binder.restoreCallingIdentity(identity); |
| 4257 | } |
| 4258 | } |
| 4259 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4260 | |
| 4261 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4262 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4263 | message); |
| 4264 | } |
| 4265 | |
| 4266 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4267 | boolean isMmtelCapability) { |
| 4268 | Phone phone = getPhone(subId); |
| 4269 | if (phone == null) { |
| 4270 | loge("phone instance null for subid " + subId); |
| 4271 | return false; |
| 4272 | } |
| 4273 | if (isMmtelCapability) { |
| 4274 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4275 | return false; |
| 4276 | } |
| 4277 | } else { |
| 4278 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4279 | return false; |
| 4280 | } |
| 4281 | } |
| 4282 | return true; |
| 4283 | } |
| 4284 | |
| 4285 | @Override |
| 4286 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4287 | boolean isProvisioned) { |
| 4288 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4289 | |
| 4290 | final long identity = Binder.clearCallingIdentity(); |
| 4291 | try { |
| 4292 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4293 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4294 | return; |
| 4295 | } |
| 4296 | |
| 4297 | // this capability requires provisioning, route to the correct API. |
| 4298 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4299 | switch (capability) { |
| 4300 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4301 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4302 | ims.setEabProvisioned(isProvisioned); |
| 4303 | break; |
| 4304 | default: { |
| 4305 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4306 | + "rcs capability '" + capability + "', which does not require " |
| 4307 | + "provisioning."); |
| 4308 | } |
| 4309 | } |
| 4310 | } finally { |
| 4311 | Binder.restoreCallingIdentity(identity); |
| 4312 | } |
| 4313 | |
| 4314 | } |
| 4315 | |
| 4316 | |
| 4317 | @Override |
| 4318 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4319 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4320 | final long identity = Binder.clearCallingIdentity(); |
| 4321 | try { |
| 4322 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4323 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4324 | return true; |
| 4325 | } |
| 4326 | |
| 4327 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4328 | switch (capability) { |
| 4329 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4330 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4331 | return ims.isEabProvisionedOnDevice(); |
| 4332 | |
| 4333 | default: { |
| 4334 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4335 | + "capability '" + capability + "', which does not require " |
| 4336 | + "provisioning."); |
| 4337 | } |
| 4338 | } |
| 4339 | |
| 4340 | } finally { |
| 4341 | Binder.restoreCallingIdentity(identity); |
| 4342 | } |
| 4343 | } |
| 4344 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4345 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4346 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4347 | boolean isProvisioned) { |
| 4348 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4349 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4350 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4351 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4352 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4353 | final long identity = Binder.clearCallingIdentity(); |
| 4354 | try { |
| 4355 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4356 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4357 | return; |
| 4358 | } |
| 4359 | |
| 4360 | // this capability requires provisioning, route to the correct API. |
| 4361 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4362 | switch (capability) { |
| 4363 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4364 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4365 | ims.setVolteProvisioned(isProvisioned); |
| 4366 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4367 | ims.setWfcProvisioned(isProvisioned); |
| 4368 | } |
| 4369 | break; |
| 4370 | } |
| 4371 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4372 | // There is currently no difference in VT provisioning type. |
| 4373 | ims.setVtProvisioned(isProvisioned); |
| 4374 | break; |
| 4375 | } |
| 4376 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4377 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4378 | // change the capability of the feature instead if needed. |
| 4379 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4380 | == isProvisioned) { |
| 4381 | // No change in provisioning. |
| 4382 | return; |
| 4383 | } |
| 4384 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4385 | try { |
| 4386 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4387 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4388 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4389 | + ", Exception" + e.getMessage()); |
| 4390 | } |
| 4391 | break; |
| 4392 | } |
| 4393 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4394 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4395 | + "MmTel capability '" + capability + "', which does not require " |
| 4396 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4397 | } |
| 4398 | } |
| 4399 | |
| 4400 | } finally { |
| 4401 | Binder.restoreCallingIdentity(identity); |
| 4402 | } |
| 4403 | } |
| 4404 | |
| 4405 | @Override |
| 4406 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4407 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4408 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4409 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4410 | } |
| 4411 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4412 | final long identity = Binder.clearCallingIdentity(); |
| 4413 | try { |
| 4414 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4415 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4416 | return true; |
| 4417 | } |
| 4418 | |
| 4419 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4420 | switch (capability) { |
| 4421 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4422 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4423 | return ims.isVolteProvisionedOnDevice(); |
| 4424 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4425 | return ims.isWfcProvisionedOnDevice(); |
| 4426 | } |
| 4427 | // This should never happen, since we are checking tech above to make sure it |
| 4428 | // is either LTE or IWLAN. |
| 4429 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4430 | + "capability."); |
| 4431 | } |
| 4432 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4433 | // There is currently no difference in VT provisioning type. |
| 4434 | return ims.isVtProvisionedOnDevice(); |
| 4435 | } |
| 4436 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4437 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4438 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4439 | } |
| 4440 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4441 | throw new IllegalArgumentException( |
| 4442 | "Tried to get provisioning for MmTel capability '" + capability |
| 4443 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4444 | } |
| 4445 | } |
| 4446 | |
| 4447 | } finally { |
| 4448 | Binder.restoreCallingIdentity(identity); |
| 4449 | } |
| 4450 | } |
| 4451 | |
| 4452 | @Override |
| 4453 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4454 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4455 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4456 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4457 | } |
| 4458 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4459 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4460 | return (provisionedBits & capability) > 0; |
| 4461 | } |
| 4462 | |
| 4463 | @Override |
| 4464 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4465 | boolean isProvisioned) { |
| 4466 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4467 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4468 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4469 | } |
| 4470 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4471 | "setProvisioningStatusForCapability"); |
| 4472 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4473 | // If the current provisioning status for capability already matches isProvisioned, |
| 4474 | // do nothing. |
| 4475 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4476 | return; |
| 4477 | } |
| 4478 | if (isProvisioned) { |
| 4479 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4480 | } else { |
| 4481 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4482 | } |
| 4483 | } |
| 4484 | |
| 4485 | /** |
| 4486 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4487 | * technology. The bitfield should mirror the bitfield defined by |
| 4488 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4489 | */ |
| 4490 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4491 | String key = getMmTelProvisioningKey(subId, tech); |
| 4492 | // Default is no capabilities are provisioned. |
| 4493 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4494 | } |
| 4495 | |
| 4496 | /** |
| 4497 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4498 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4499 | * technology specified. |
| 4500 | * |
| 4501 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4502 | */ |
| 4503 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4504 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4505 | String key = getMmTelProvisioningKey(subId, tech); |
| 4506 | editor.putInt(key, newField); |
| 4507 | editor.commit(); |
| 4508 | } |
| 4509 | |
| 4510 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4511 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4512 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4513 | } |
| 4514 | |
| 4515 | /** |
| 4516 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4517 | * carrier associated with the subscription id. |
| 4518 | */ |
| 4519 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4520 | int capability) { |
| 4521 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4522 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4523 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4524 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4525 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4526 | false); |
| 4527 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4528 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4529 | |
| 4530 | // First check to make sure that the capability requires provisioning. |
| 4531 | switch (capability) { |
| 4532 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4533 | // intentional fallthrough |
| 4534 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4535 | if (requireVoiceVtProvisioning) { |
| 4536 | // Voice and Video requires provisioning |
| 4537 | return true; |
| 4538 | } |
| 4539 | break; |
| 4540 | } |
| 4541 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4542 | if (requireUtProvisioning) { |
| 4543 | // UT requires provisioning |
| 4544 | return true; |
| 4545 | } |
| 4546 | break; |
| 4547 | } |
| 4548 | } |
| 4549 | return false; |
| 4550 | } |
| 4551 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4552 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4553 | int capability) { |
| 4554 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4555 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4556 | |
| 4557 | boolean requireRcsProvisioning = c.getBoolean( |
| 4558 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4559 | |
| 4560 | // First check to make sure that the capability requires provisioning. |
| 4561 | switch (capability) { |
| 4562 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4563 | // intentional fallthrough |
| 4564 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4565 | if (requireRcsProvisioning) { |
| 4566 | // OPTION or PRESENCE requires provisioning |
| 4567 | return true; |
| 4568 | } |
| 4569 | break; |
| 4570 | } |
| 4571 | } |
| 4572 | return false; |
| 4573 | } |
| 4574 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4575 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4576 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4577 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4578 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4579 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4580 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4581 | final long identity = Binder.clearCallingIdentity(); |
| 4582 | try { |
| 4583 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4584 | int slotId = getSlotIndex(subId); |
| 4585 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4586 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4587 | + subId + "' for key:" + key); |
| 4588 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4589 | } |
calvinpan | 9cfff47 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4590 | return ImsManager.getInstance(mApp, slotId).getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4591 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4592 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4593 | + subId + "' for key:" + key); |
| 4594 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4595 | } finally { |
| 4596 | Binder.restoreCallingIdentity(identity); |
| 4597 | } |
| 4598 | } |
| 4599 | |
| 4600 | @Override |
| 4601 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4602 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4603 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4604 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4605 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4606 | final long identity = Binder.clearCallingIdentity(); |
| 4607 | try { |
| 4608 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4609 | int slotId = getSlotIndex(subId); |
| 4610 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4611 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4612 | + subId + "' for key:" + key); |
| 4613 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4614 | } |
calvinpan | 9cfff47 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4615 | return ImsManager.getInstance(mApp, slotId).getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4616 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4617 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4618 | + subId + "' for key:" + key); |
| 4619 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4620 | } finally { |
| 4621 | Binder.restoreCallingIdentity(identity); |
| 4622 | } |
| 4623 | } |
| 4624 | |
| 4625 | @Override |
| 4626 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4627 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4628 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4629 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4630 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4631 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4632 | final long identity = Binder.clearCallingIdentity(); |
| 4633 | try { |
| 4634 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4635 | int slotId = getSlotIndex(subId); |
| 4636 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4637 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4638 | + subId + "' for key:" + key); |
| 4639 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4640 | } |
calvinpan | 9cfff47 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4641 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4642 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4643 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
calvinpan | 9cfff47 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4644 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4645 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4646 | } finally { |
| 4647 | Binder.restoreCallingIdentity(identity); |
| 4648 | } |
| 4649 | } |
| 4650 | |
| 4651 | @Override |
| 4652 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4653 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4654 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4655 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4656 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4657 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4658 | final long identity = Binder.clearCallingIdentity(); |
| 4659 | try { |
| 4660 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4661 | int slotId = getSlotIndex(subId); |
| 4662 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4663 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4664 | + subId + "' for key:" + key); |
| 4665 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4666 | } |
calvinpan | 9cfff47 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4667 | return ImsManager.getInstance(mApp, slotId).setConfig(key, value); |
| 4668 | } catch (com.android.ims.ImsException | RemoteException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4669 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
calvinpan | 9cfff47 | 2021-02-08 19:59:36 +0800 | [diff] [blame] | 4670 | + "' for key:" + key, e); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4671 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4672 | } finally { |
| 4673 | Binder.restoreCallingIdentity(identity); |
| 4674 | } |
| 4675 | } |
| 4676 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4677 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4678 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4679 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4680 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4681 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4682 | } |
| 4683 | return slotId; |
| 4684 | } |
| 4685 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4686 | private int getSlotIndex(int subId) { |
| 4687 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4688 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4689 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4690 | } |
| 4691 | return slotId; |
| 4692 | } |
| 4693 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4694 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4695 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4696 | */ |
| 4697 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4698 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4699 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 4700 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4701 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4702 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4703 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4704 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4705 | mApp, subId, callingPackage, callingFeatureId, |
| 4706 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4707 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4708 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4709 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4710 | final long identity = Binder.clearCallingIdentity(); |
| 4711 | try { |
| 4712 | final Phone phone = getPhone(subId); |
| 4713 | if (phone != null) { |
| 4714 | return phone.getServiceState().getDataNetworkType(); |
| 4715 | } else { |
| 4716 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4717 | } |
| 4718 | } finally { |
| 4719 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4720 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4721 | } |
| 4722 | |
| 4723 | /** |
| 4724 | * Returns the data network type |
| 4725 | */ |
| 4726 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4727 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
Zoey Chen | fd61f7f | 2021-04-21 13:42:10 +0800 | [diff] [blame] | 4728 | return getDataNetworkTypeForSubscriber(mSubscriptionController.getDefaultDataSubId(), |
| 4729 | callingPackage, callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4730 | } |
| 4731 | |
| 4732 | /** |
| 4733 | * Returns the data network type for a subId |
| 4734 | */ |
| 4735 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4736 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4737 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4738 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4739 | mApp, subId, callingPackage, callingFeatureId, |
| 4740 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4741 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4742 | } |
| 4743 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4744 | final long identity = Binder.clearCallingIdentity(); |
| 4745 | try { |
| 4746 | final Phone phone = getPhone(subId); |
| 4747 | if (phone != null) { |
| 4748 | return phone.getServiceState().getDataNetworkType(); |
| 4749 | } else { |
| 4750 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4751 | } |
| 4752 | } finally { |
| 4753 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4754 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4755 | } |
| 4756 | |
| 4757 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4758 | * Returns the Voice network type for a subId |
| 4759 | */ |
| 4760 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4761 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4762 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4763 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4764 | mApp, subId, callingPackage, callingFeatureId, |
| 4765 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4766 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4767 | } |
| 4768 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4769 | final long identity = Binder.clearCallingIdentity(); |
| 4770 | try { |
| 4771 | final Phone phone = getPhone(subId); |
| 4772 | if (phone != null) { |
| 4773 | return phone.getServiceState().getVoiceNetworkType(); |
| 4774 | } else { |
| 4775 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4776 | } |
| 4777 | } finally { |
| 4778 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4779 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4780 | } |
| 4781 | |
| 4782 | /** |
| 4783 | * @return true if a ICC card is present |
| 4784 | */ |
| 4785 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4786 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4787 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4788 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4789 | } |
| 4790 | |
| 4791 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4792 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4793 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4794 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4795 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4796 | final long identity = Binder.clearCallingIdentity(); |
| 4797 | try { |
| 4798 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4799 | if (phone != null) { |
| 4800 | return phone.getIccCard().hasIccCard(); |
| 4801 | } else { |
| 4802 | return false; |
| 4803 | } |
| 4804 | } finally { |
| 4805 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4806 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4807 | } |
| 4808 | |
| 4809 | /** |
| 4810 | * Return if the current radio is LTE on CDMA. This |
| 4811 | * is a tri-state return value as for a period of time |
| 4812 | * the mode may be unknown. |
| 4813 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4814 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4815 | * @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] | 4816 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4817 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4818 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4819 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4820 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4821 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4822 | } |
| 4823 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4824 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4825 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4826 | String callingFeatureId) { |
Sarah Chin | f6656a6 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4827 | try { |
| 4828 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4829 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4830 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4831 | } |
| 4832 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4833 | final long identity = Binder.clearCallingIdentity(); |
| 4834 | try { |
| 4835 | final Phone phone = getPhone(subId); |
| 4836 | if (phone == null) { |
| 4837 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4838 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 4839 | return TelephonyProperties.lte_on_cdma_device() |
| 4840 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4841 | } |
| 4842 | } finally { |
| 4843 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4844 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4845 | } |
| 4846 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4847 | /** |
| 4848 | * {@hide} |
| 4849 | * Returns Default subId, 0 in the case of single standby. |
| 4850 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4851 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4852 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4853 | } |
| 4854 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4855 | private int getSlotForDefaultSubscription() { |
| 4856 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4857 | } |
| 4858 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4859 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4860 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4861 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4862 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4863 | private boolean isActiveSubscription(int subId) { |
| 4864 | return mSubscriptionController.isActiveSubId(subId); |
| 4865 | } |
| 4866 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4867 | /** |
| 4868 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4869 | */ |
| 4870 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4871 | final long identity = Binder.clearCallingIdentity(); |
| 4872 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4873 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4874 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4875 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4876 | } finally { |
| 4877 | Binder.restoreCallingIdentity(identity); |
| 4878 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4879 | } |
| 4880 | |
| 4881 | /** |
| 4882 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4883 | */ |
| 4884 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4885 | final long identity = Binder.clearCallingIdentity(); |
| 4886 | try { |
| 4887 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4888 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4889 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4890 | } finally { |
| 4891 | Binder.restoreCallingIdentity(identity); |
| 4892 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4893 | } |
| 4894 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4895 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4896 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4897 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4898 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4899 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4900 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4901 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4902 | if (phoneId == -1) { |
| 4903 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4904 | + " does not correspond to an active phone"); |
| 4905 | } |
| 4906 | return PhoneFactory.getPhone(phoneId); |
| 4907 | } |
| 4908 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4909 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4910 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4911 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4912 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4913 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4914 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4915 | if (DBG) { |
| 4916 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4917 | } |
| 4918 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4919 | p2); |
| 4920 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4921 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4922 | |
| 4923 | @Override |
| 4924 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4925 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4926 | enforceModifyPermission(); |
| 4927 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4928 | if (DBG) { |
| 4929 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4930 | } |
| 4931 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4932 | callingPackage, aid, p2); |
| 4933 | } |
| 4934 | |
| 4935 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4936 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4937 | final long identity = Binder.clearCallingIdentity(); |
| 4938 | try { |
| 4939 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4940 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4941 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4942 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4943 | if (bestComponent == null |
| 4944 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4945 | loge("The calling package is not allowed to access ISD-R."); |
| 4946 | throw new SecurityException( |
| 4947 | "The calling package is not allowed to access ISD-R."); |
| 4948 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4949 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4950 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4951 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4952 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4953 | null /* workSource */); |
| 4954 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4955 | return response; |
| 4956 | } finally { |
| 4957 | Binder.restoreCallingIdentity(identity); |
| 4958 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4959 | } |
| 4960 | |
| 4961 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4962 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4963 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4964 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4965 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4966 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4967 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4968 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4969 | @Override |
| 4970 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4971 | enforceModifyPermission(); |
| 4972 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4973 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4974 | channel); |
| 4975 | } |
| 4976 | |
| 4977 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4978 | final long identity = Binder.clearCallingIdentity(); |
| 4979 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4980 | if (channel < 0) { |
| 4981 | return false; |
| 4982 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4983 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4984 | null /* workSource */); |
| 4985 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4986 | return success; |
| 4987 | } finally { |
| 4988 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4989 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4990 | } |
| 4991 | |
| 4992 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4993 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4994 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4995 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4996 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4997 | if (DBG) { |
| 4998 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4999 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5000 | + p3 + " data=" + data); |
| 5001 | } |
| 5002 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5003 | command, p1, p2, p3, data); |
| 5004 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5005 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5006 | @Override |
| 5007 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 5008 | int command, int p1, int p2, int p3, String data) { |
| 5009 | enforceModifyPermission(); |
| 5010 | if (DBG) { |
| 5011 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 5012 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5013 | + p3 + " data=" + data); |
| 5014 | } |
| 5015 | return iccTransmitApduLogicalChannelWithPermission( |
| 5016 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 5017 | data); |
| 5018 | } |
| 5019 | |
| 5020 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5021 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5022 | final long identity = Binder.clearCallingIdentity(); |
| 5023 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5024 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5025 | return ""; |
| 5026 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5027 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5028 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5029 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5030 | null /* workSource */); |
| 5031 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5032 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5033 | // Append the returned status code to the end of the response payload. |
| 5034 | String s = Integer.toHexString( |
| 5035 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5036 | if (response.payload != null) { |
| 5037 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5038 | } |
| 5039 | return s; |
| 5040 | } finally { |
| 5041 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5042 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5043 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5044 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5045 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5046 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5047 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5048 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5049 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5050 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5051 | if (DBG) { |
| 5052 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5053 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5054 | } |
| 5055 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5056 | cla, command, p1, p2, p3, data); |
| 5057 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5058 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5059 | @Override |
| 5060 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 5061 | int command, int p1, int p2, int p3, String data) { |
| 5062 | enforceModifyPermission(); |
| 5063 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5064 | if (DBG) { |
| 5065 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 5066 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 5067 | + " data=" + data); |
| 5068 | } |
| 5069 | |
| 5070 | return iccTransmitApduBasicChannelWithPermission( |
| 5071 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 5072 | p2, p3, data); |
| 5073 | } |
| 5074 | |
| 5075 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5076 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5077 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5078 | final long identity = Binder.clearCallingIdentity(); |
| 5079 | try { |
| 5080 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5081 | && TextUtils.equals(ISDR_AID, data)) { |
| 5082 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5083 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5084 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5085 | if (bestComponent == null |
| 5086 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5087 | loge("The calling package is not allowed to select ISD-R."); |
| 5088 | throw new SecurityException( |
| 5089 | "The calling package is not allowed to select ISD-R."); |
| 5090 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5091 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5092 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5093 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5094 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5095 | null /* workSource */); |
| 5096 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5097 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5098 | // Append the returned status code to the end of the response payload. |
| 5099 | String s = Integer.toHexString( |
| 5100 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5101 | if (response.payload != null) { |
| 5102 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5103 | } |
| 5104 | return s; |
| 5105 | } finally { |
| 5106 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5107 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5108 | } |
| 5109 | |
| 5110 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5111 | 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] | 5112 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5113 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5114 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5115 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5116 | final long identity = Binder.clearCallingIdentity(); |
| 5117 | try { |
| 5118 | if (DBG) { |
| 5119 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5120 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5121 | } |
| 5122 | |
| 5123 | IccIoResult response = |
| 5124 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5125 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5126 | subId); |
| 5127 | |
| 5128 | if (DBG) { |
| 5129 | log("Exchange SIM_IO [R]" + response); |
| 5130 | } |
| 5131 | |
| 5132 | byte[] result = null; |
| 5133 | int length = 2; |
| 5134 | if (response.payload != null) { |
| 5135 | length = 2 + response.payload.length; |
| 5136 | result = new byte[length]; |
| 5137 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5138 | } else { |
| 5139 | result = new byte[length]; |
| 5140 | } |
| 5141 | |
| 5142 | result[length - 1] = (byte) response.sw2; |
| 5143 | result[length - 2] = (byte) response.sw1; |
| 5144 | return result; |
| 5145 | } finally { |
| 5146 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5147 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5148 | } |
| 5149 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5150 | /** |
| 5151 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5152 | * on a particular subscription |
| 5153 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5154 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5155 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5156 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5157 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5158 | return null; |
| 5159 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5160 | |
| 5161 | final long identity = Binder.clearCallingIdentity(); |
| 5162 | try { |
| 5163 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5164 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5165 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5166 | return null; |
| 5167 | } |
| 5168 | Object response = sendRequest( |
| 5169 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5170 | if (response instanceof String[]) { |
| 5171 | return (String[]) response; |
| 5172 | } |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5173 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5174 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5175 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5176 | } finally { |
| 5177 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5178 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5179 | } |
| 5180 | |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5181 | /** |
| 5182 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5183 | * subscription. |
| 5184 | * |
| 5185 | * @param subId the id of the subscription. |
| 5186 | * @param appType the uicc app type, must be USIM or SIM. |
| 5187 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5188 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5189 | * @param callingFeatureId the feature in the package. |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5190 | * @return number of fplmns that is successfully written to the SIM. |
| 5191 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5192 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5193 | String callingFeatureId) { |
| 5194 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 5195 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5196 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 5197 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 5198 | } |
| 5199 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5200 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5201 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5202 | } |
| 5203 | if (fplmns == null) { |
| 5204 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5205 | } |
| 5206 | for (String fplmn : fplmns) { |
| 5207 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5208 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5209 | } |
| 5210 | } |
| 5211 | final long identity = Binder.clearCallingIdentity(); |
| 5212 | try { |
| 5213 | Object response = sendRequest( |
| 5214 | CMD_SET_FORBIDDEN_PLMNS, |
| 5215 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5216 | subId); |
| 5217 | return (int) response; |
| 5218 | } finally { |
| 5219 | Binder.restoreCallingIdentity(identity); |
| 5220 | } |
| 5221 | } |
| 5222 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5223 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5224 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5225 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5226 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5227 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5228 | final long identity = Binder.clearCallingIdentity(); |
| 5229 | try { |
| 5230 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5231 | if (response.payload == null) { |
| 5232 | return ""; |
| 5233 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5234 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5235 | // Append the returned status code to the end of the response payload. |
| 5236 | String s = Integer.toHexString( |
| 5237 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5238 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5239 | return s; |
| 5240 | } finally { |
| 5241 | Binder.restoreCallingIdentity(identity); |
| 5242 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5243 | } |
| 5244 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5245 | /** |
| 5246 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5247 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5248 | * |
| 5249 | * @param itemID the ID of the item to read |
| 5250 | * @return the NV item as a String, or null on error. |
| 5251 | */ |
| 5252 | @Override |
| 5253 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5254 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5255 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5256 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5257 | |
| 5258 | final long identity = Binder.clearCallingIdentity(); |
| 5259 | try { |
| 5260 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5261 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5262 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5263 | return value; |
| 5264 | } finally { |
| 5265 | Binder.restoreCallingIdentity(identity); |
| 5266 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5267 | } |
| 5268 | |
| 5269 | /** |
| 5270 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5271 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5272 | * |
| 5273 | * @param itemID the ID of the item to read |
| 5274 | * @param itemValue the value to write, as a String |
| 5275 | * @return true on success; false on any failure |
| 5276 | */ |
| 5277 | @Override |
| 5278 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5279 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5280 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5281 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5282 | |
| 5283 | final long identity = Binder.clearCallingIdentity(); |
| 5284 | try { |
| 5285 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5286 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5287 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5288 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5289 | return success; |
| 5290 | } finally { |
| 5291 | Binder.restoreCallingIdentity(identity); |
| 5292 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5293 | } |
| 5294 | |
| 5295 | /** |
| 5296 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5297 | * Used for device configuration by some CDMA operators. |
| 5298 | * |
| 5299 | * @param preferredRoamingList byte array containing the new PRL |
| 5300 | * @return true on success; false on any failure |
| 5301 | */ |
| 5302 | @Override |
| 5303 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5304 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5305 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5306 | |
| 5307 | final long identity = Binder.clearCallingIdentity(); |
| 5308 | try { |
| 5309 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5310 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5311 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5312 | return success; |
| 5313 | } finally { |
| 5314 | Binder.restoreCallingIdentity(identity); |
| 5315 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5316 | } |
| 5317 | |
| 5318 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5319 | * 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] | 5320 | * Used for device configuration by some CDMA operators. |
| 5321 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5322 | * @param slotIndex - device slot. |
| 5323 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5324 | * @return true on success; false on any failure |
| 5325 | */ |
| 5326 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5327 | public boolean resetModemConfig(int slotIndex) { |
| 5328 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5329 | if (phone != null) { |
| 5330 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5331 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5332 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5333 | final long identity = Binder.clearCallingIdentity(); |
| 5334 | try { |
| 5335 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5336 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5337 | return success; |
| 5338 | } finally { |
| 5339 | Binder.restoreCallingIdentity(identity); |
| 5340 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5341 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5342 | return false; |
| 5343 | } |
| 5344 | |
| 5345 | /** |
| 5346 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5347 | * |
| 5348 | * @param slotIndex - device slot. |
| 5349 | * |
| 5350 | * @return true on success; false on any failure |
| 5351 | */ |
| 5352 | @Override |
| 5353 | public boolean rebootModem(int slotIndex) { |
| 5354 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5355 | if (phone != null) { |
| 5356 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5357 | mApp, phone.getSubId(), "rebootModem"); |
| 5358 | |
| 5359 | final long identity = Binder.clearCallingIdentity(); |
| 5360 | try { |
| 5361 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5362 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5363 | return success; |
| 5364 | } finally { |
| 5365 | Binder.restoreCallingIdentity(identity); |
| 5366 | } |
| 5367 | } |
| 5368 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5369 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5370 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5371 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5372 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5373 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5374 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5375 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5376 | return new String[0]; |
| 5377 | } |
| 5378 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5379 | final long identity = Binder.clearCallingIdentity(); |
| 5380 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5381 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5382 | } finally { |
| 5383 | Binder.restoreCallingIdentity(identity); |
| 5384 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5385 | } |
| 5386 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5387 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5388 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5389 | * {@link #disableIms(int)}. |
| 5390 | * @param slotIndex device slot. |
| 5391 | */ |
| 5392 | public void resetIms(int slotIndex) { |
| 5393 | enforceModifyPermission(); |
| 5394 | |
| 5395 | final long identity = Binder.clearCallingIdentity(); |
| 5396 | try { |
| 5397 | if (mImsResolver == null) { |
| 5398 | // may happen if the does not support IMS. |
| 5399 | return; |
| 5400 | } |
| 5401 | mImsResolver.disableIms(slotIndex); |
| 5402 | mImsResolver.enableIms(slotIndex); |
| 5403 | } finally { |
| 5404 | Binder.restoreCallingIdentity(identity); |
| 5405 | } |
| 5406 | } |
| 5407 | |
| 5408 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5409 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5410 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5411 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5412 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5413 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5414 | |
| 5415 | final long identity = Binder.clearCallingIdentity(); |
| 5416 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5417 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5418 | // may happen if the device does not support IMS. |
| 5419 | return; |
| 5420 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5421 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5422 | } finally { |
| 5423 | Binder.restoreCallingIdentity(identity); |
| 5424 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5425 | } |
| 5426 | |
| 5427 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5428 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5429 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5430 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5431 | public void disableIms(int slotId) { |
| 5432 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5433 | |
| 5434 | final long identity = Binder.clearCallingIdentity(); |
| 5435 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5436 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5437 | // may happen if the device does not support IMS. |
| 5438 | return; |
| 5439 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5440 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5441 | } finally { |
| 5442 | Binder.restoreCallingIdentity(identity); |
| 5443 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5444 | } |
| 5445 | |
| 5446 | /** |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5447 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5448 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5449 | */ |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5450 | @Override |
Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5451 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5452 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5453 | |
| 5454 | final long identity = Binder.clearCallingIdentity(); |
| 5455 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5456 | if (mImsResolver == null) { |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5457 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5458 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5459 | } |
Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5460 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5461 | } finally { |
| 5462 | Binder.restoreCallingIdentity(identity); |
| 5463 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5464 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5465 | /** |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5466 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5467 | */ |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5468 | @Override |
| 5469 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5470 | enforceModifyPermission(); |
| 5471 | |
| 5472 | final long identity = Binder.clearCallingIdentity(); |
| 5473 | try { |
| 5474 | if (mImsResolver == null) return; |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5475 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5476 | } finally { |
| 5477 | Binder.restoreCallingIdentity(identity); |
| 5478 | } |
| 5479 | } |
| 5480 | |
| 5481 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5482 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5483 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5484 | */ |
| 5485 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5486 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5487 | |
| 5488 | final long identity = Binder.clearCallingIdentity(); |
| 5489 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5490 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5491 | // may happen if the device does not support IMS. |
| 5492 | return null; |
| 5493 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5494 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5495 | } finally { |
| 5496 | Binder.restoreCallingIdentity(identity); |
| 5497 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5498 | } |
| 5499 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5500 | /** |
| 5501 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5502 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5503 | */ |
| 5504 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5505 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5506 | |
| 5507 | final long identity = Binder.clearCallingIdentity(); |
| 5508 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5509 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5510 | // may happen if the device does not support IMS. |
| 5511 | return null; |
| 5512 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5513 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5514 | } finally { |
| 5515 | Binder.restoreCallingIdentity(identity); |
| 5516 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5517 | } |
| 5518 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5519 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5520 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5521 | * |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5522 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5523 | * @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] | 5524 | * ImsService is the device default ImsService. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5525 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5526 | * @param packageName The name of the package that the current configuration will be replaced |
| 5527 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5528 | * @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] | 5529 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5530 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5531 | int[] featureTypes, String packageName) { |
| 5532 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5533 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5534 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5535 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5536 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5537 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5538 | final long identity = Binder.clearCallingIdentity(); |
| 5539 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5540 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5541 | // may happen if the device does not support IMS. |
| 5542 | return false; |
| 5543 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5544 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5545 | for (int featureType : featureTypes) { |
| 5546 | featureConfig.put(featureType, packageName); |
| 5547 | } |
| 5548 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5549 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5550 | } finally { |
| 5551 | Binder.restoreCallingIdentity(identity); |
| 5552 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5553 | } |
| 5554 | |
| 5555 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5556 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5557 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5558 | * |
| 5559 | * This should only be used for testing. |
| 5560 | * |
| 5561 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5562 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5563 | */ |
| 5564 | @Override |
| 5565 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5566 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5567 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5568 | "clearCarrierImsServiceOverride"); |
| 5569 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5570 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5571 | "clearCarrierImsServiceOverride"); |
| 5572 | |
| 5573 | final long identity = Binder.clearCallingIdentity(); |
| 5574 | try { |
| 5575 | if (mImsResolver == null) { |
| 5576 | // may happen if the device does not support IMS. |
| 5577 | return false; |
| 5578 | } |
| 5579 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5580 | } finally { |
| 5581 | Binder.restoreCallingIdentity(identity); |
| 5582 | } |
| 5583 | } |
| 5584 | |
| 5585 | /** |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5586 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5587 | * |
| 5588 | * @param slotId The slot that the ImsService is associated with. |
| 5589 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5590 | * the device default. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5591 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5592 | * @return the package name of the ImsService configuration. |
| 5593 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5594 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5595 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5596 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5597 | TelephonyPermissions |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5598 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5599 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5600 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5601 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5602 | final long identity = Binder.clearCallingIdentity(); |
| 5603 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5604 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5605 | // may happen if the device does not support IMS. |
| 5606 | return ""; |
| 5607 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5608 | // TODO: change API to query RCS separately. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5609 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5610 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5611 | } finally { |
| 5612 | Binder.restoreCallingIdentity(identity); |
| 5613 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5614 | } |
| 5615 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5616 | /** |
| 5617 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5618 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5619 | * @param callback A callback with an integer containing the |
| 5620 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5621 | */ |
| 5622 | @Override |
| 5623 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5624 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5625 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5626 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5627 | "IMS not available on device."); |
| 5628 | } |
| 5629 | final long token = Binder.clearCallingIdentity(); |
| 5630 | try { |
| 5631 | int slotId = getSlotIndex(subId); |
| 5632 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5633 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5634 | + subId + "'"); |
| 5635 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5636 | } |
| 5637 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5638 | try { |
| 5639 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5640 | } catch (RemoteException e) { |
| 5641 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5642 | + "Ignore"); |
| 5643 | } |
| 5644 | }); |
| 5645 | } finally { |
| 5646 | Binder.restoreCallingIdentity(token); |
| 5647 | } |
| 5648 | } |
| 5649 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5650 | /** |
| 5651 | * Sets the ims registration state on all valid {@link Phone}s. |
| 5652 | */ |
| 5653 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5654 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5655 | |
| 5656 | final long identity = Binder.clearCallingIdentity(); |
| 5657 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5658 | // NOTE: Before S, this method only set the default phone. |
| 5659 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 5660 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 5661 | phone.setImsRegistrationState(registered); |
| 5662 | } |
| 5663 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5664 | } finally { |
| 5665 | Binder.restoreCallingIdentity(identity); |
| 5666 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5667 | } |
| 5668 | |
| 5669 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5670 | * Set the network selection mode to automatic. |
| 5671 | * |
| 5672 | */ |
| 5673 | @Override |
| 5674 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5675 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5676 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5677 | |
| 5678 | final long identity = Binder.clearCallingIdentity(); |
| 5679 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5680 | if (!isActiveSubscription(subId)) { |
| 5681 | return; |
| 5682 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5683 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 5684 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 5685 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5686 | } finally { |
| 5687 | Binder.restoreCallingIdentity(identity); |
| 5688 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5689 | } |
| 5690 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5691 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5692 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5693 | * |
| 5694 | * @param subId the id of the subscription. |
| 5695 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5696 | * the operator to attach to. |
| 5697 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5698 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5699 | * normal network selection next time. |
| 5700 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5701 | */ |
| 5702 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5703 | public boolean setNetworkSelectionModeManual( |
| 5704 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5705 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5706 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5707 | |
| 5708 | if (!isActiveSubscription(subId)) { |
| 5709 | return false; |
| 5710 | } |
| 5711 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5712 | final long identity = Binder.clearCallingIdentity(); |
| 5713 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5714 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5715 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5716 | if (DBG) { |
| 5717 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5718 | + " operator: " + operatorInfo); |
| 5719 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5720 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5721 | } finally { |
| 5722 | Binder.restoreCallingIdentity(identity); |
| 5723 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5724 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5725 | /** |
| 5726 | * Get the manual network selection |
| 5727 | * |
| 5728 | * @param subId the id of the subscription. |
| 5729 | * |
| 5730 | * @return the previously saved user selected PLMN |
| 5731 | */ |
| 5732 | @Override |
| 5733 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5734 | TelephonyPermissions |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 5735 | .enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5736 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5737 | |
| 5738 | final long identity = Binder.clearCallingIdentity(); |
| 5739 | try { |
| 5740 | if (!isActiveSubscription(subId)) { |
| 5741 | return ""; |
| 5742 | } |
| 5743 | |
| 5744 | final Phone phone = getPhone(subId); |
| 5745 | if (phone == null) { |
| 5746 | return ""; |
| 5747 | } |
| 5748 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5749 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5750 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5751 | } finally { |
| 5752 | Binder.restoreCallingIdentity(identity); |
| 5753 | } |
| 5754 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5755 | |
| 5756 | /** |
| 5757 | * Scans for available networks. |
| 5758 | */ |
| 5759 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5760 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5761 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5762 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5763 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5764 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5765 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5766 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5767 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5768 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5769 | .setCallingPid(Binder.getCallingPid()) |
| 5770 | .setCallingUid(Binder.getCallingUid()) |
| 5771 | .setMethod("getCellNetworkScanResults") |
| 5772 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5773 | .build()); |
| 5774 | switch (locationResult) { |
| 5775 | case DENIED_HARD: |
| 5776 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5777 | case DENIED_SOFT: |
| 5778 | return null; |
| 5779 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5780 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5781 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5782 | try { |
| 5783 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5784 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5785 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5786 | } finally { |
| 5787 | Binder.restoreCallingIdentity(identity); |
| 5788 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5789 | } |
| 5790 | |
| 5791 | /** |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5792 | * Get the call forwarding info, given the call forwarding reason. |
| 5793 | */ |
| 5794 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5795 | public void getCallForwarding(int subId, int callForwardingReason, |
| 5796 | ICallForwardingInfoCallback callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5797 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5798 | long identity = Binder.clearCallingIdentity(); |
| 5799 | try { |
| 5800 | if (DBG) { |
| 5801 | log("getCallForwarding: subId " + subId |
| 5802 | + " callForwardingReason" + callForwardingReason); |
| 5803 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5804 | |
| 5805 | Phone phone = getPhone(subId); |
| 5806 | if (phone == null) { |
| 5807 | try { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5808 | callback.onError( |
| 5809 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5810 | } catch (RemoteException e) { |
| 5811 | // ignore |
| 5812 | } |
| 5813 | return; |
| 5814 | } |
| 5815 | |
| 5816 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 5817 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 5818 | @Override |
| 5819 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 5820 | try { |
| 5821 | callback.onCallForwardingInfoAvailable(info); |
| 5822 | } catch (RemoteException e) { |
| 5823 | // ignore |
| 5824 | } |
| 5825 | } |
| 5826 | |
| 5827 | @Override |
| 5828 | public void onError(int error) { |
| 5829 | try { |
| 5830 | callback.onError(error); |
| 5831 | } catch (RemoteException e) { |
| 5832 | // ignore |
| 5833 | } |
| 5834 | } |
| 5835 | }); |
| 5836 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5837 | } finally { |
| 5838 | Binder.restoreCallingIdentity(identity); |
| 5839 | } |
| 5840 | } |
| 5841 | |
| 5842 | /** |
| 5843 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5844 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5845 | */ |
| 5846 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5847 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 5848 | IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5849 | enforceModifyPermission(); |
| 5850 | long identity = Binder.clearCallingIdentity(); |
| 5851 | try { |
| 5852 | if (DBG) { |
| 5853 | log("setCallForwarding: subId " + subId |
| 5854 | + " callForwardingInfo" + callForwardingInfo); |
| 5855 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5856 | |
| 5857 | Phone phone = getPhone(subId); |
| 5858 | if (phone == null) { |
| 5859 | try { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5860 | callback.accept( |
| 5861 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5862 | } catch (RemoteException e) { |
| 5863 | // ignore |
| 5864 | } |
| 5865 | return; |
| 5866 | } |
| 5867 | |
| 5868 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 5869 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5870 | |
| 5871 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5872 | } finally { |
| 5873 | Binder.restoreCallingIdentity(identity); |
| 5874 | } |
| 5875 | } |
| 5876 | |
| 5877 | /** |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5878 | * Get the call waiting status for a subId. |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5879 | */ |
| 5880 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5881 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
SongFerngWang | c63cf52 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 5882 | enforceReadPrivilegedPermission("getCallWaitingStatus"); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5883 | long identity = Binder.clearCallingIdentity(); |
| 5884 | try { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5885 | Phone phone = getPhone(subId); |
| 5886 | if (phone == null) { |
| 5887 | try { |
| 5888 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5889 | } catch (RemoteException e) { |
| 5890 | // ignore |
| 5891 | } |
| 5892 | return; |
| 5893 | } |
SongFerngWang | c63cf52 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 5894 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 5895 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 5896 | boolean requireUssd = c.getBoolean( |
| 5897 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5898 | |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5899 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
SongFerngWang | c63cf52 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 5900 | if (requireUssd) { |
| 5901 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 5902 | getSubscriptionCarrierId(subId)); |
| 5903 | String newUssdCommand = ""; |
| 5904 | try { |
| 5905 | newUssdCommand = carrierXmlParser.getFeature( |
| 5906 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 5907 | .makeCommand(CarrierXmlParser.SsEntry.SSAction.QUERY, null); |
| 5908 | } catch (NullPointerException e) { |
| 5909 | loge("Failed to generate USSD number" + e); |
| 5910 | } |
| 5911 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 5912 | mMainThreadHandler, callback, carrierXmlParser, |
| 5913 | CarrierXmlParser.SsEntry.SSAction.QUERY); |
| 5914 | final String ussdCommand = newUssdCommand; |
| 5915 | Executors.newSingleThreadExecutor().execute(() -> { |
| 5916 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 5917 | }); |
| 5918 | } else { |
| 5919 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException( |
| 5920 | callback::accept); |
| 5921 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
| 5922 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5923 | } finally { |
| 5924 | Binder.restoreCallingIdentity(identity); |
| 5925 | } |
| 5926 | } |
| 5927 | |
| 5928 | /** |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5929 | * Sets whether call waiting is enabled for a given subId. |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5930 | */ |
| 5931 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5932 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5933 | enforceModifyPermission(); |
| 5934 | long identity = Binder.clearCallingIdentity(); |
| 5935 | try { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5936 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 5937 | |
| 5938 | Phone phone = getPhone(subId); |
| 5939 | if (phone == null) { |
| 5940 | try { |
| 5941 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5942 | } catch (RemoteException e) { |
| 5943 | // ignore |
| 5944 | } |
| 5945 | return; |
| 5946 | } |
| 5947 | |
SongFerngWang | c63cf52 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 5948 | CarrierConfigManager configManager = new CarrierConfigManager(phone.getContext()); |
| 5949 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 5950 | boolean requireUssd = c.getBoolean( |
| 5951 | CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5952 | |
SongFerngWang | c63cf52 | 2021-03-31 22:08:45 +0800 | [diff] [blame] | 5953 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 5954 | if (requireUssd) { |
| 5955 | CarrierXmlParser carrierXmlParser = new CarrierXmlParser(phone.getContext(), |
| 5956 | getSubscriptionCarrierId(subId)); |
| 5957 | CarrierXmlParser.SsEntry.SSAction ssAction = |
| 5958 | enable ? CarrierXmlParser.SsEntry.SSAction.UPDATE_ACTIVATE |
| 5959 | : CarrierXmlParser.SsEntry.SSAction.UPDATE_DEACTIVATE; |
| 5960 | String newUssdCommand = ""; |
| 5961 | try { |
| 5962 | newUssdCommand = carrierXmlParser.getFeature( |
| 5963 | CarrierXmlParser.FEATURE_CALL_WAITING) |
| 5964 | .makeCommand(ssAction, null); |
| 5965 | } catch (NullPointerException e) { |
| 5966 | loge("Failed to generate USSD number" + e); |
| 5967 | } |
| 5968 | ResultReceiver wrappedCallback = new CallWaitingUssdResultReceiver( |
| 5969 | mMainThreadHandler, callback, carrierXmlParser, ssAction); |
| 5970 | final String ussdCommand = newUssdCommand; |
| 5971 | Executors.newSingleThreadExecutor().execute(() -> { |
| 5972 | handleUssdRequest(subId, ussdCommand, wrappedCallback); |
| 5973 | }); |
| 5974 | } else { |
| 5975 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 5976 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5977 | |
| 5978 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
| 5979 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5980 | } finally { |
| 5981 | Binder.restoreCallingIdentity(identity); |
| 5982 | } |
| 5983 | } |
| 5984 | |
| 5985 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5986 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5987 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5988 | * @param subId id of the subscription |
| 5989 | * @param request contains the radio access networks with bands/channels to scan |
| 5990 | * @param messenger callback messenger for scan results or errors |
| 5991 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5992 | * @return the id of the requested scan which can be used to stop the scan. |
| 5993 | */ |
| 5994 | @Override |
| 5995 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5996 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5997 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5998 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5999 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 6000 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6001 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6002 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6003 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6004 | .setCallingPid(Binder.getCallingPid()) |
| 6005 | .setCallingUid(Binder.getCallingUid()) |
| 6006 | .setMethod("requestNetworkScan") |
| 6007 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6008 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6009 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 284aa04 | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6010 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 6011 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6012 | if (e != null) { |
| 6013 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 6014 | throw e; |
| 6015 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 6016 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6017 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 6018 | } |
| 6019 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6020 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6021 | int callingUid = Binder.getCallingUid(); |
| 6022 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6023 | final long identity = Binder.clearCallingIdentity(); |
| 6024 | try { |
| 6025 | return mNetworkScanRequestTracker.startNetworkScan( |
| 6026 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6027 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 6028 | } finally { |
| 6029 | Binder.restoreCallingIdentity(identity); |
| 6030 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6031 | } |
| 6032 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6033 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 284aa04 | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6034 | NetworkScanRequest request, int subId, String callingPackage) { |
| 6035 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6036 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6037 | boolean hasNetworkScanPermission = |
| 6038 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6039 | == PERMISSION_GRANTED; |
| 6040 | |
| 6041 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6042 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6043 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6044 | } |
| 6045 | |
| 6046 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6047 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6048 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6049 | return new SecurityException("Specific channels must not be" |
| 6050 | + " scanned without location access."); |
| 6051 | } |
| 6052 | } |
| 6053 | } |
| 6054 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6055 | return null; |
| 6056 | } |
| 6057 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6058 | /** |
| 6059 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6060 | * |
| 6061 | * @param subId id of the subscription |
| 6062 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6063 | */ |
| 6064 | @Override |
| 6065 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6066 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6067 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6068 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6069 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6070 | final long identity = Binder.clearCallingIdentity(); |
| 6071 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6072 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6073 | } finally { |
| 6074 | Binder.restoreCallingIdentity(identity); |
| 6075 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6076 | } |
| 6077 | |
| 6078 | /** |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6079 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6080 | * |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6081 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6082 | */ |
| 6083 | @Override |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6084 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6085 | TelephonyPermissions |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6086 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6087 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6088 | |
| 6089 | final long identity = Binder.clearCallingIdentity(); |
| 6090 | try { |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6091 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6092 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6093 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6094 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6095 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6096 | } finally { |
| 6097 | Binder.restoreCallingIdentity(identity); |
| 6098 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6099 | } |
| 6100 | |
| 6101 | /** |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6102 | * Get the allowed network types for certain reason. |
| 6103 | * |
| 6104 | * @param subId the id of the subscription. |
| 6105 | * @param reason the reason the allowed network type change is taking place |
| 6106 | * @return the allowed network types. |
| 6107 | */ |
| 6108 | @Override |
| 6109 | public long getAllowedNetworkTypesForReason(int subId, |
| 6110 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6111 | TelephonyPermissions.enforceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 522637d | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6112 | mApp, subId, "getAllowedNetworkTypesForReason"); |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6113 | final long identity = Binder.clearCallingIdentity(); |
| 6114 | try { |
| 6115 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6116 | } finally { |
| 6117 | Binder.restoreCallingIdentity(identity); |
| 6118 | } |
| 6119 | } |
| 6120 | |
| 6121 | /** |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6122 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6123 | * @param subId subscription id of the sim card |
| 6124 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6125 | * This can be passed following states |
| 6126 | * <ol> |
| 6127 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6128 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6129 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6130 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6131 | * </ol> |
| 6132 | * @return operation result. |
| 6133 | */ |
| 6134 | @Override |
| 6135 | public int setNrDualConnectivityState(int subId, |
| 6136 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6137 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6138 | mApp, subId, "enableNRDualConnectivity"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6139 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6140 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6141 | return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED; |
| 6142 | } |
| 6143 | |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6144 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6145 | final long identity = Binder.clearCallingIdentity(); |
| 6146 | try { |
| 6147 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6148 | nrDualConnectivityState, subId, |
| 6149 | workSource); |
| 6150 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6151 | return result; |
| 6152 | } finally { |
| 6153 | Binder.restoreCallingIdentity(identity); |
| 6154 | } |
| 6155 | } |
| 6156 | |
| 6157 | /** |
| 6158 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6159 | * @return true if dual connectivity is enabled else false |
| 6160 | */ |
| 6161 | @Override |
| 6162 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6163 | TelephonyPermissions |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6164 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6165 | mApp, subId, "isNRDualConnectivityEnabled"); |
Sooraj Sasindran | 0e4e00a | 2021-03-16 18:02:32 -0700 | [diff] [blame] | 6166 | if (!isRadioInterfaceCapabilitySupported( |
Sooraj Sasindran | dfd595b | 2021-03-11 17:38:13 -0800 | [diff] [blame] | 6167 | TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) { |
| 6168 | return false; |
| 6169 | } |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 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 | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6183 | * Set the allowed network types of the device and |
| 6184 | * provide the reason triggering the allowed network change. |
| 6185 | * |
| 6186 | * @param subId the id of the subscription. |
| 6187 | * @param reason the reason the allowed network type change is taking place |
| 6188 | * @param allowedNetworkTypes the allowed network types. |
| 6189 | * @return true on success; false on any failure. |
| 6190 | */ |
| 6191 | @Override |
| 6192 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6193 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6194 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6195 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6196 | mApp, subId, "setAllowedNetworkTypesForReason"); |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6197 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
| 6198 | Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason); |
| 6199 | return false; |
| 6200 | } |
| 6201 | |
SongFerngWang | 522637d | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6202 | log("setAllowedNetworkTypesForReason: " + reason + " value: " |
| 6203 | + TelephonyManager.convertNetworkTypeBitmaskToString(allowedNetworkTypes)); |
| 6204 | |
| 6205 | |
| 6206 | if (allowedNetworkTypes == getPhoneFromSubId(subId).getAllowedNetworkTypes(reason)) { |
| 6207 | log("setAllowedNetworkTypesForReason: " + reason + "does not change value"); |
| 6208 | return true; |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6209 | } |
SongFerngWang | 522637d | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 6210 | |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6211 | final long identity = Binder.clearCallingIdentity(); |
| 6212 | try { |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6213 | Boolean success = (Boolean) sendRequest( |
| 6214 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6215 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6216 | |
| 6217 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6218 | return success; |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6219 | } finally { |
| 6220 | Binder.restoreCallingIdentity(identity); |
| 6221 | } |
| 6222 | } |
| 6223 | |
| 6224 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6225 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6226 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6227 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6228 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6229 | * @hide |
| 6230 | */ |
| 6231 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6232 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6233 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6234 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6235 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6236 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6237 | if (phone != null) { |
| 6238 | return phone.hasMatchedTetherApnSetting(); |
| 6239 | } else { |
| 6240 | return false; |
| 6241 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6242 | } finally { |
| 6243 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6244 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6245 | } |
| 6246 | |
| 6247 | /** |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6248 | * Enable or disable always reporting signal strength changes from radio. |
| 6249 | * |
| 6250 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 6251 | */ |
| 6252 | @Override |
| 6253 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 6254 | enforceModifyPermission(); |
| 6255 | enforceSystemCaller(); |
| 6256 | |
| 6257 | final long identity = Binder.clearCallingIdentity(); |
| 6258 | final Phone phone = getPhone(subId); |
| 6259 | try { |
| 6260 | if (phone != null) { |
| 6261 | if (DBG) { |
| 6262 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6263 | + " isEnable=" + isEnable); |
| 6264 | } |
| 6265 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6266 | } else { |
| 6267 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6268 | + subId); |
| 6269 | } |
| 6270 | } finally { |
| 6271 | Binder.restoreCallingIdentity(identity); |
| 6272 | } |
| 6273 | } |
| 6274 | |
| 6275 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6276 | * Get the user enabled state of Mobile Data. |
| 6277 | * |
| 6278 | * TODO: remove and use isUserDataEnabled. |
| 6279 | * This can't be removed now because some vendor codes |
| 6280 | * calls through ITelephony directly while they should |
| 6281 | * use TelephonyManager. |
| 6282 | * |
| 6283 | * @return true on enabled |
| 6284 | */ |
| 6285 | @Override |
| 6286 | public boolean getDataEnabled(int subId) { |
| 6287 | return isUserDataEnabled(subId); |
| 6288 | } |
| 6289 | |
| 6290 | /** |
| 6291 | * Get whether mobile data is enabled per user setting. |
| 6292 | * |
| 6293 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6294 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6295 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6296 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6297 | * |
| 6298 | * @return {@code true} if data is enabled else {@code false} |
| 6299 | */ |
| 6300 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6301 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6302 | try { |
| 6303 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6304 | null); |
| 6305 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6306 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6307 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6308 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6309 | |
| 6310 | final long identity = Binder.clearCallingIdentity(); |
| 6311 | try { |
| 6312 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6313 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6314 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6315 | if (phone != null) { |
| 6316 | boolean retVal = phone.isUserDataEnabled(); |
| 6317 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6318 | return retVal; |
| 6319 | } else { |
| 6320 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6321 | return false; |
| 6322 | } |
| 6323 | } finally { |
| 6324 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6325 | } |
| 6326 | } |
| 6327 | |
| 6328 | /** |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6329 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6330 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6331 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6332 | * |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6333 | * @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] | 6334 | */ |
| 6335 | @Override |
| 6336 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6337 | try { |
| 6338 | try { |
| 6339 | mApp.enforceCallingOrSelfPermission( |
| 6340 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6341 | null); |
| 6342 | } catch (Exception e) { |
| 6343 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6344 | "isDataEnabled"); |
| 6345 | } |
| 6346 | } catch (Exception e) { |
| 6347 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6348 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6349 | |
| 6350 | final long identity = Binder.clearCallingIdentity(); |
| 6351 | try { |
| 6352 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6353 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6354 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6355 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6356 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6357 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6358 | return retVal; |
| 6359 | } else { |
| 6360 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6361 | return false; |
| 6362 | } |
| 6363 | } finally { |
| 6364 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6365 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6366 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6367 | |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6368 | /** |
| 6369 | * Check if data is enabled for a specific reason |
| 6370 | * @param subId Subscription index |
| 6371 | * @param reason the reason the data enable change is taking place |
| 6372 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6373 | */ |
| 6374 | @Override |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6375 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6376 | @TelephonyManager.DataEnabledReason int reason) { |
| 6377 | try { |
| 6378 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6379 | null); |
| 6380 | } catch (Exception e) { |
| 6381 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6382 | "isDataEnabledForReason"); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6383 | } |
| 6384 | |
| 6385 | |
| 6386 | final long identity = Binder.clearCallingIdentity(); |
| 6387 | try { |
| 6388 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6389 | if (DBG) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6390 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6391 | + " reason=" + reason); |
| 6392 | } |
| 6393 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6394 | if (phone != null) { |
| 6395 | boolean retVal; |
| 6396 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6397 | retVal = phone.isUserDataEnabled(); |
| 6398 | } else { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6399 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6400 | } |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6401 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6402 | return retVal; |
| 6403 | } else { |
| 6404 | if (DBG) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6405 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6406 | + subId + " retVal=false"); |
| 6407 | } |
| 6408 | return false; |
| 6409 | } |
| 6410 | } finally { |
| 6411 | Binder.restoreCallingIdentity(identity); |
| 6412 | } |
| 6413 | } |
| 6414 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6415 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6416 | Phone phone) { |
Hall Liu | ce478d2 | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 6417 | if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) { |
| 6418 | // Skip the check if it's one of these special uids |
| 6419 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6420 | } |
| 6421 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6422 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6423 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6424 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6425 | || subController == null) return privilegeFromSim; |
| 6426 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6427 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6428 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6429 | |
| 6430 | final long identity = Binder.clearCallingIdentity(); |
| 6431 | try { |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6432 | int subId = phone.getSubId(); |
| 6433 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6434 | // A test override is in place for the privileges for this subId, so don't try to |
| 6435 | // read the subscription privileges. |
| 6436 | return privilegeFromSim; |
| 6437 | } |
| 6438 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6439 | SubscriptionManager subManager = (SubscriptionManager) |
| 6440 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6441 | for (String pkg : packages) { |
| 6442 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6443 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6444 | } |
| 6445 | } |
| 6446 | return privilegeFromSim; |
| 6447 | } finally { |
| 6448 | Binder.restoreCallingIdentity(identity); |
| 6449 | } |
| 6450 | } |
| 6451 | |
| 6452 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6453 | String pkgName) { |
| 6454 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6455 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6456 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6457 | || subController == null) return privilegeFromSim; |
| 6458 | |
| 6459 | final long identity = Binder.clearCallingIdentity(); |
| 6460 | try { |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6461 | int subId = phone.getSubId(); |
| 6462 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6463 | // A test override is in place for the privileges for this subId, so don't try to |
| 6464 | // read the subscription privileges. |
| 6465 | return privilegeFromSim; |
| 6466 | } |
| 6467 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6468 | SubscriptionManager subManager = (SubscriptionManager) |
| 6469 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6470 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6471 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6472 | } finally { |
| 6473 | Binder.restoreCallingIdentity(identity); |
| 6474 | } |
| 6475 | } |
| 6476 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6477 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6478 | public int getCarrierPrivilegeStatus(int subId) { |
| 6479 | final Phone phone = getPhone(subId); |
| 6480 | if (phone == null) { |
| 6481 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6482 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6483 | } |
| 6484 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6485 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6486 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6487 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6488 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6489 | |
| 6490 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6491 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6492 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6493 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6494 | |
| 6495 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6496 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6497 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6498 | final Phone phone = getPhone(subId); |
| 6499 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6500 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6501 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6502 | } |
| 6503 | UiccProfile profile = |
| 6504 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6505 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6506 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6507 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6508 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6509 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6510 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6511 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6512 | } |
| 6513 | |
| 6514 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6515 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 6516 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6517 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6518 | } |
| 6519 | |
| 6520 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 6521 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6522 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6523 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [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( |
| 6527 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6528 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6529 | } |
| 6530 | |
| 6531 | @Override |
| 6532 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6533 | if (TextUtils.isEmpty(pkgName)) |
| 6534 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6535 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6536 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6537 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 6538 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6539 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6540 | continue; |
| 6541 | } |
| 6542 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6543 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6544 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6545 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6546 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6547 | break; |
| 6548 | } |
| 6549 | } |
| 6550 | |
| 6551 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6552 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6553 | |
| 6554 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6555 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 6556 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6557 | loge("phoneId " + phoneId + " is not valid."); |
| 6558 | return null; |
| 6559 | } |
| 6560 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6561 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6562 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6563 | return null ; |
| 6564 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6565 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6566 | } |
| 6567 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6568 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6569 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6570 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6571 | List<String> privilegedPackages = new ArrayList<>(); |
| 6572 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6573 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 6574 | // has UICC in that slot. |
| 6575 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6576 | if (card.hasCarrierPrivilegeRules()) { |
| 6577 | if (packages == null) { |
| 6578 | // Only check packages in user 0 for now |
| 6579 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6580 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6581 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6582 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6583 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6584 | } |
| 6585 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6586 | PackageInfo pkgInfo = packages.get(p); |
| 6587 | if (pkgInfo != null && pkgInfo.packageName != null |
| 6588 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6589 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6590 | privilegedPackages.add(pkgInfo.packageName); |
| 6591 | } |
| 6592 | } |
| 6593 | } |
| 6594 | } |
| 6595 | return privilegedPackages; |
| 6596 | } |
| 6597 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6598 | @Override |
| 6599 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6600 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6601 | |
| 6602 | final long identity = Binder.clearCallingIdentity(); |
| 6603 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6604 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6605 | try { |
| 6606 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6607 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6608 | } |
| 6609 | } finally { |
| 6610 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6611 | } |
| 6612 | return privilegedPackages; |
| 6613 | } |
| 6614 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6615 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6616 | final Phone phone = getPhone(subId); |
| 6617 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6618 | if (card == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6619 | return null; |
| 6620 | } |
| 6621 | String iccId = card.getIccId(); |
| 6622 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6623 | return null; |
| 6624 | } |
| 6625 | return iccId; |
| 6626 | } |
| 6627 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6628 | @Override |
Shuo Qian | 8aa1132 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6629 | public void setCallComposerStatus(int subId, int status) { |
| 6630 | enforceModifyPermission(); |
| 6631 | |
| 6632 | final long identity = Binder.clearCallingIdentity(); |
| 6633 | try { |
| 6634 | Phone phone = getPhone(subId); |
| 6635 | if (phone != null) { |
| 6636 | Phone defaultPhone = phone.getImsPhone(); |
| 6637 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6638 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6639 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | d878246 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6640 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6641 | .updateImsServiceConfig(); |
Shuo Qian | 8aa1132 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6642 | } |
| 6643 | } |
Shuo Qian | d878246 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6644 | } catch (ImsException e) { |
| 6645 | throw new ServiceSpecificException(e.getCode()); |
| 6646 | } finally { |
Shuo Qian | 8aa1132 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6647 | Binder.restoreCallingIdentity(identity); |
| 6648 | } |
| 6649 | } |
| 6650 | |
| 6651 | @Override |
| 6652 | public int getCallComposerStatus(int subId) { |
| 6653 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 6654 | |
| 6655 | final long identity = Binder.clearCallingIdentity(); |
| 6656 | try { |
| 6657 | Phone phone = getPhone(subId); |
| 6658 | if (phone != null) { |
| 6659 | Phone defaultPhone = phone.getImsPhone(); |
| 6660 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6661 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6662 | return imsPhone.getCallComposerStatus(); |
| 6663 | } |
| 6664 | } |
| 6665 | } finally { |
| 6666 | Binder.restoreCallingIdentity(identity); |
| 6667 | } |
| 6668 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 6669 | } |
| 6670 | |
| 6671 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6672 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6673 | String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6674 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6675 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6676 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6677 | final long identity = Binder.clearCallingIdentity(); |
| 6678 | try { |
| 6679 | final String iccId = getIccId(subId); |
| 6680 | final Phone phone = getPhone(subId); |
| 6681 | if (phone == null) { |
| 6682 | return false; |
| 6683 | } |
| 6684 | final String subscriberId = phone.getSubscriberId(); |
| 6685 | |
| 6686 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6687 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6688 | + subscriberId + " to " + number); |
| 6689 | } |
| 6690 | |
| 6691 | if (TextUtils.isEmpty(iccId)) { |
| 6692 | return false; |
| 6693 | } |
| 6694 | |
| 6695 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6696 | |
| 6697 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6698 | if (alphaTag == null) { |
| 6699 | editor.remove(alphaTagPrefKey); |
| 6700 | } else { |
| 6701 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6702 | } |
| 6703 | |
| 6704 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6705 | // track all merged IMSIs based on line number |
| 6706 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6707 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6708 | if (number == null) { |
| 6709 | editor.remove(numberPrefKey); |
| 6710 | editor.remove(subscriberPrefKey); |
| 6711 | } else { |
| 6712 | editor.putString(numberPrefKey, number); |
| 6713 | editor.putString(subscriberPrefKey, subscriberId); |
| 6714 | } |
| 6715 | |
| 6716 | editor.commit(); |
| 6717 | return true; |
| 6718 | } finally { |
| 6719 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6720 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6721 | } |
| 6722 | |
| 6723 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6724 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6725 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6726 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6727 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6728 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6729 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6730 | return null; |
| 6731 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6732 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6733 | final long identity = Binder.clearCallingIdentity(); |
| 6734 | try { |
| 6735 | String iccId = getIccId(subId); |
| 6736 | if (iccId != null) { |
| 6737 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6738 | if (DBG_MERGE) { |
| 6739 | log("getLine1NumberForDisplay returning " |
| 6740 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6741 | } |
| 6742 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6743 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6744 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6745 | return null; |
| 6746 | } finally { |
| 6747 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6748 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6749 | } |
| 6750 | |
| 6751 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6752 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6753 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6754 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6755 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6756 | return null; |
| 6757 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6758 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6759 | final long identity = Binder.clearCallingIdentity(); |
| 6760 | try { |
| 6761 | String iccId = getIccId(subId); |
| 6762 | if (iccId != null) { |
| 6763 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6764 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6765 | } |
| 6766 | return null; |
| 6767 | } finally { |
| 6768 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6769 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6770 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6771 | |
| 6772 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6773 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6774 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6775 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6776 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6777 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6778 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6779 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6780 | return null; |
| 6781 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6782 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6783 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6784 | // the process, where TelephonyManager was instantiated. |
| 6785 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6786 | final long identity = Binder.clearCallingIdentity(); |
| 6787 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6788 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6789 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6790 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6791 | |
| 6792 | // Figure out what subscribers are currently active |
| 6793 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6794 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6795 | // Only consider subs which match the current subId |
| 6796 | // This logic can be simplified. See b/131189269 for progress. |
| 6797 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6798 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6799 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6800 | |
| 6801 | // First pass, find a number override for an active subscriber |
| 6802 | String mergeNumber = null; |
| 6803 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6804 | for (String key : prefs.keySet()) { |
| 6805 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6806 | final String subscriberId = (String) prefs.get(key); |
| 6807 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6808 | final String iccId = key.substring( |
| 6809 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6810 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6811 | mergeNumber = (String) prefs.get(numberKey); |
| 6812 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6813 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6814 | + " for active subscriber " + subscriberId); |
| 6815 | } |
| 6816 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6817 | break; |
| 6818 | } |
| 6819 | } |
| 6820 | } |
| 6821 | } |
| 6822 | |
| 6823 | // Shortcut when no active merged subscribers |
| 6824 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6825 | return null; |
| 6826 | } |
| 6827 | |
| 6828 | // Second pass, find all subscribers under that line override |
| 6829 | final ArraySet<String> result = new ArraySet<>(); |
| 6830 | for (String key : prefs.keySet()) { |
| 6831 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6832 | final String number = (String) prefs.get(key); |
| 6833 | if (mergeNumber.equals(number)) { |
| 6834 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6835 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6836 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6837 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6838 | result.add(subscriberId); |
| 6839 | } |
| 6840 | } |
| 6841 | } |
| 6842 | } |
| 6843 | |
| 6844 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6845 | Arrays.sort(resultArray); |
| 6846 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6847 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6848 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6849 | } |
| 6850 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6851 | } finally { |
| 6852 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6853 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6854 | } |
| 6855 | |
| 6856 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6857 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6858 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6859 | |
| 6860 | final long identity = Binder.clearCallingIdentity(); |
| 6861 | try { |
| 6862 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6863 | TelephonyManager.class); |
| 6864 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6865 | if (subscriberId == null) { |
| 6866 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6867 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6868 | + subId); |
| 6869 | } |
| 6870 | return null; |
| 6871 | } |
| 6872 | |
| 6873 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6874 | .getSubscriptionInfo(subId); |
| 6875 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6876 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6877 | if (groupUuid == null) { |
| 6878 | return new String[]{subscriberId}; |
| 6879 | } |
| 6880 | |
| 6881 | // Get all subscriberIds from the group. |
| 6882 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6883 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6884 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6885 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6886 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6887 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6888 | if (subscriberId != null) { |
| 6889 | mergedSubscriberIds.add(subscriberId); |
| 6890 | } |
| 6891 | } |
| 6892 | |
| 6893 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6894 | } finally { |
| 6895 | Binder.restoreCallingIdentity(identity); |
| 6896 | |
| 6897 | } |
| 6898 | } |
| 6899 | |
| 6900 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6901 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6902 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6903 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6904 | |
| 6905 | final long identity = Binder.clearCallingIdentity(); |
| 6906 | try { |
| 6907 | final Phone phone = getPhone(subId); |
| 6908 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6909 | } finally { |
| 6910 | Binder.restoreCallingIdentity(identity); |
| 6911 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6912 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6913 | |
| 6914 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6915 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6916 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6917 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6918 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6919 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6920 | |
| 6921 | final long identity = Binder.clearCallingIdentity(); |
| 6922 | try { |
| 6923 | final Phone phone = getPhone(subId); |
| 6924 | if (phone == null) { |
| 6925 | return false; |
| 6926 | } |
| 6927 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6928 | cdmaNonRoamingList); |
| 6929 | } finally { |
| 6930 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6931 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6932 | } |
| 6933 | |
| 6934 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6935 | @Deprecated |
| 6936 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6937 | enforceModifyPermission(); |
| 6938 | |
| 6939 | int returnValue = 0; |
| 6940 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6941 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6942 | if(result.exception == null) { |
| 6943 | if (result.result != null) { |
| 6944 | byte[] responseData = (byte[])(result.result); |
| 6945 | if(responseData.length > oemResp.length) { |
| 6946 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6947 | responseData.length + "bytes. Buffer Size is " + |
| 6948 | oemResp.length + "bytes."); |
| 6949 | } |
| 6950 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6951 | returnValue = responseData.length; |
| 6952 | } |
| 6953 | } else { |
| 6954 | CommandException ex = (CommandException) result.exception; |
| 6955 | returnValue = ex.getCommandError().ordinal(); |
| 6956 | if(returnValue > 0) returnValue *= -1; |
| 6957 | } |
| 6958 | } catch (RuntimeException e) { |
| 6959 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6960 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6961 | if(returnValue > 0) returnValue *= -1; |
| 6962 | } |
| 6963 | |
| 6964 | return returnValue; |
| 6965 | } |
| 6966 | |
| 6967 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6968 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6969 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 6970 | try { |
| 6971 | TelephonyPermissions |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6972 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 6973 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6974 | } catch (SecurityException e) { |
| 6975 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 6976 | throw e; |
| 6977 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6978 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6979 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6980 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6981 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6982 | final long identity = Binder.clearCallingIdentity(); |
| 6983 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6984 | TelephonyPermissions |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 6985 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6986 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6987 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6988 | } finally { |
| 6989 | Binder.restoreCallingIdentity(identity); |
| 6990 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6991 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6992 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6993 | |
| 6994 | @Override |
| 6995 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6996 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6997 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6998 | |
| 6999 | final long identity = Binder.clearCallingIdentity(); |
| 7000 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7001 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7002 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7003 | } finally { |
| 7004 | Binder.restoreCallingIdentity(identity); |
| 7005 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7006 | } |
| 7007 | |
| 7008 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7009 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7010 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7011 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7012 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7013 | return false; |
| 7014 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7015 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7016 | final long identity = Binder.clearCallingIdentity(); |
| 7017 | try { |
| 7018 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7019 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7020 | // In the long run, we may instead need to check if there exists a connection service |
| 7021 | // which can support video calling. |
| 7022 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7023 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7024 | return imsManager.isVtEnabledByPlatform() |
| 7025 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7026 | && imsManager.isVtEnabledByUser(); |
| 7027 | } finally { |
| 7028 | Binder.restoreCallingIdentity(identity); |
| 7029 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7030 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7031 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7032 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7033 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7034 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7035 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7036 | mApp, subId, callingPackage, callingFeatureId, |
| 7037 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7038 | return false; |
| 7039 | } |
| 7040 | |
| 7041 | final long identity = Binder.clearCallingIdentity(); |
| 7042 | try { |
| 7043 | CarrierConfigManager configManager = |
| 7044 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7045 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7046 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7047 | } finally { |
| 7048 | Binder.restoreCallingIdentity(identity); |
| 7049 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7050 | } |
| 7051 | |
| 7052 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7053 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7054 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7055 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7056 | return false; |
| 7057 | } |
| 7058 | |
| 7059 | final long identity = Binder.clearCallingIdentity(); |
| 7060 | try { |
| 7061 | CarrierConfigManager configManager = |
| 7062 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7063 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7064 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7065 | } finally { |
| 7066 | Binder.restoreCallingIdentity(identity); |
| 7067 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7068 | } |
| 7069 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7070 | @Override |
| 7071 | public boolean isTtyModeSupported() { |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7072 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7073 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7074 | } |
| 7075 | |
| 7076 | @Override |
| 7077 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7078 | final long identity = Binder.clearCallingIdentity(); |
| 7079 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7080 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7081 | } finally { |
| 7082 | Binder.restoreCallingIdentity(identity); |
| 7083 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7084 | } |
| 7085 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7086 | /** |
| 7087 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7088 | * support for the feature and device firmware support. |
| 7089 | * |
| 7090 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7091 | */ |
| 7092 | @Override |
| 7093 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7094 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7095 | final Phone phone = getPhone(subscriptionId); |
| 7096 | if (phone == null) { |
| 7097 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7098 | return false; |
| 7099 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7100 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7101 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7102 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7103 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7104 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7105 | return isCarrierSupported && isDeviceSupported; |
| 7106 | } finally { |
| 7107 | Binder.restoreCallingIdentity(identity); |
| 7108 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7109 | } |
| 7110 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7111 | /** |
Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7112 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7113 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7114 | * 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] | 7115 | */ |
| 7116 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7117 | final long identity = Binder.clearCallingIdentity(); |
| 7118 | try { |
Hall Liu | 63767ec | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7119 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7120 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7121 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7122 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7123 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7124 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7125 | } finally { |
| 7126 | Binder.restoreCallingIdentity(identity); |
| 7127 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7128 | } |
| 7129 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7130 | @Deprecated |
| 7131 | @Override |
| 7132 | public String getDeviceId(String callingPackage) { |
| 7133 | return getDeviceIdWithFeature(callingPackage, null); |
| 7134 | } |
| 7135 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7136 | /** |
| 7137 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7138 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7139 | * |
| 7140 | * <p>Requires Permission: |
| 7141 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7142 | */ |
| 7143 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7144 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7145 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7146 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7147 | return null; |
| 7148 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7149 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7150 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7151 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7152 | return null; |
| 7153 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7154 | |
| 7155 | final long identity = Binder.clearCallingIdentity(); |
| 7156 | try { |
| 7157 | return phone.getDeviceId(); |
| 7158 | } finally { |
| 7159 | Binder.restoreCallingIdentity(identity); |
| 7160 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7161 | } |
| 7162 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7163 | /** |
| 7164 | * {@hide} |
| 7165 | * Returns the IMS Registration Status on a particular subid |
| 7166 | * |
| 7167 | * @param subId |
| 7168 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7169 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7170 | Phone phone = getPhone(subId); |
| 7171 | if (phone != null) { |
| 7172 | return phone.isImsRegistered(); |
| 7173 | } else { |
| 7174 | return false; |
| 7175 | } |
| 7176 | } |
| 7177 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7178 | @Override |
| 7179 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7180 | final long identity = Binder.clearCallingIdentity(); |
| 7181 | try { |
| 7182 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 7183 | } finally { |
| 7184 | Binder.restoreCallingIdentity(identity); |
| 7185 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7186 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 7187 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7188 | @Override |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7189 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7190 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7191 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7192 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7193 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7194 | } |
| 7195 | final long identity = Binder.clearCallingIdentity(); |
| 7196 | try { |
| 7197 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7198 | } finally { |
| 7199 | Binder.restoreCallingIdentity(identity); |
| 7200 | } |
| 7201 | } |
| 7202 | |
| 7203 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7204 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
duki.hong | fd96bde | 2020-07-22 17:32:19 +0900 | [diff] [blame] | 7205 | enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, " |
| 7206 | + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7207 | final long identity = Binder.clearCallingIdentity(); |
| 7208 | try { |
| 7209 | Phone phone = getPhone(subscriptionId); |
| 7210 | if (phone == null) { |
| 7211 | return null; |
| 7212 | } |
| 7213 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7214 | } finally { |
| 7215 | Binder.restoreCallingIdentity(identity); |
| 7216 | } |
| 7217 | } |
| 7218 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7219 | /** |
| 7220 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7221 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7222 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7223 | final long identity = Binder.clearCallingIdentity(); |
| 7224 | try { |
| 7225 | Phone phone = getPhone(subId); |
| 7226 | if (phone != null) { |
| 7227 | return phone.isWifiCallingEnabled(); |
| 7228 | } else { |
| 7229 | return false; |
| 7230 | } |
| 7231 | } finally { |
| 7232 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7233 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7234 | } |
| 7235 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7236 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7237 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7238 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7239 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7240 | final long identity = Binder.clearCallingIdentity(); |
| 7241 | try { |
| 7242 | Phone phone = getPhone(subId); |
| 7243 | if (phone != null) { |
| 7244 | return phone.isVideoEnabled(); |
| 7245 | } else { |
| 7246 | return false; |
| 7247 | } |
| 7248 | } finally { |
| 7249 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7250 | } |
| 7251 | } |
| 7252 | |
| 7253 | /** |
| 7254 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7255 | * defined in {@link ImsRegistrationImplBase}. |
| 7256 | */ |
| 7257 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7258 | final long identity = Binder.clearCallingIdentity(); |
| 7259 | try { |
| 7260 | Phone phone = getPhone(subId); |
| 7261 | if (phone != null) { |
| 7262 | return phone.getImsRegistrationTech(); |
| 7263 | } else { |
| 7264 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7265 | } |
| 7266 | } finally { |
| 7267 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7268 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7269 | } |
| 7270 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7271 | @Override |
| 7272 | public void factoryReset(int subId) { |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7273 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7274 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7275 | return; |
| 7276 | } |
| 7277 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7278 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7279 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7280 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7281 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7282 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7283 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7284 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7285 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 522637d | 2021-03-02 22:09:29 +0800 | [diff] [blame] | 7286 | Phone phone = getPhone(subId); |
| 7287 | if (phone != null) { |
| 7288 | SubscriptionManager.setSubscriptionProperty(subId, |
| 7289 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 7290 | "user=" + RadioAccessFamily.getRafFromNetworkType( |
| 7291 | RILConstants.PREFERRED_NETWORK_MODE)); |
| 7292 | phone.loadAllowedNetworksFromSubscriptionDatabase(); |
| 7293 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7294 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 7295 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7296 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7297 | // There has been issues when Sms raw table somehow stores orphan |
| 7298 | // fragments. They lead to garbled message when new fragments come |
| 7299 | // in and combined with those stale ones. In case this happens again, |
| 7300 | // user can reset all network settings which will clean up this table. |
| 7301 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7302 | // Clean up IMS settings as well here. |
| 7303 | int slotId = getSlotIndex(subId); |
| 7304 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7305 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7306 | } |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7307 | |
| 7308 | // Erase modem config if erase modem on network setting is enabled. |
| 7309 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7310 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7311 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 7312 | sendEraseModemConfig(getDefaultPhone()); |
| 7313 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7314 | } finally { |
| 7315 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7316 | } |
| 7317 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7318 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7319 | private void cleanUpSmsRawTable(Context context) { |
| 7320 | ContentResolver resolver = context.getContentResolver(); |
| 7321 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7322 | resolver.delete(uri, null, null); |
| 7323 | } |
| 7324 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7325 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7326 | public String getSimLocaleForSubscriber(int subId) { |
| 7327 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7328 | final Phone phone = getPhone(subId); |
| 7329 | if (phone == null) { |
| 7330 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7331 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7332 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7333 | final long identity = Binder.clearCallingIdentity(); |
| 7334 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7335 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7336 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7337 | if (info == null) { |
| 7338 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7339 | return null; |
| 7340 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7341 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7342 | // preferences (EF-PL and EF-LI)... |
| 7343 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7344 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7345 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7346 | if (localeFromDefaultSim != null) { |
| 7347 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7348 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7349 | + localeFromDefaultSim); |
| 7350 | return localeFromDefaultSim.toLanguageTag(); |
| 7351 | } else { |
| 7352 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7353 | } |
| 7354 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7355 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7356 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7357 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7358 | // the SIM and carrier preferences does not include a country we add the country |
| 7359 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7360 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7361 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7362 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7363 | return mccLocale.toLanguageTag(); |
| 7364 | } |
| 7365 | |
| 7366 | if (DBG) log("No locale found - returning null"); |
| 7367 | return null; |
| 7368 | } finally { |
| 7369 | Binder.restoreCallingIdentity(identity); |
| 7370 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7371 | } |
| 7372 | |
| 7373 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7374 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7375 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7376 | } |
| 7377 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7378 | /** |
| 7379 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7380 | */ |
| 7381 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7382 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7383 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7384 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7385 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7386 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7387 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7388 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7389 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7390 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7391 | * representing the state of the modem. |
| 7392 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7393 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7394 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7395 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7396 | */ |
| 7397 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7398 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7399 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7400 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7401 | |
| 7402 | final long identity = Binder.clearCallingIdentity(); |
| 7403 | try { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 7404 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7405 | } finally { |
| 7406 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7407 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7408 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7409 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7410 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7411 | // less than total activity duration. |
| 7412 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7413 | if (info == null) { |
| 7414 | return false; |
| 7415 | } |
| 7416 | int activityDurationMs = |
| 7417 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 7418 | int totalTxTimeMs = 0; |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7419 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 7420 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 7421 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7422 | } |
| 7423 | return (info.isValid() |
| 7424 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7425 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7426 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7427 | && (totalTxTimeMs <= activityDurationMs)); |
| 7428 | } |
| 7429 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7430 | /** |
| 7431 | * {@hide} |
| 7432 | * Returns the service state information on specified subscription. |
| 7433 | */ |
| 7434 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7435 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7436 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7437 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7438 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7439 | return null; |
| 7440 | } |
| 7441 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7442 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7443 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7444 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7445 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7446 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7447 | .setCallingPid(Binder.getCallingPid()) |
| 7448 | .setCallingUid(Binder.getCallingUid()) |
| 7449 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7450 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7451 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7452 | .build()); |
| 7453 | |
| 7454 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7455 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7456 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7457 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7458 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7459 | .setCallingPid(Binder.getCallingPid()) |
| 7460 | .setCallingUid(Binder.getCallingUid()) |
| 7461 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7462 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7463 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7464 | .build()); |
| 7465 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7466 | boolean hasFinePermission = |
| 7467 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7468 | boolean hasCoarsePermission = |
| 7469 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7470 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7471 | final long identity = Binder.clearCallingIdentity(); |
| 7472 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7473 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7474 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7475 | Rlog.d(LOG_TAG, |
| 7476 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7477 | return null; |
| 7478 | } |
| 7479 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7480 | final Phone phone = getPhone(subId); |
| 7481 | if (phone == null) { |
| 7482 | return null; |
| 7483 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7484 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7485 | ServiceState ss = phone.getServiceState(); |
| 7486 | |
| 7487 | // Scrub out the location info in ServiceState depending on what level of access |
| 7488 | // the caller has. |
| 7489 | if (hasFinePermission) return ss; |
Malcolm Chen | db33797 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7490 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7491 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7492 | } finally { |
| 7493 | Binder.restoreCallingIdentity(identity); |
| 7494 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7495 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7496 | |
| 7497 | /** |
| 7498 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7499 | * |
| 7500 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7501 | * voicemail ringtone. |
| 7502 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7503 | * PhoneAccount. |
| 7504 | */ |
| 7505 | @Override |
| 7506 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7507 | final long identity = Binder.clearCallingIdentity(); |
| 7508 | try { |
| 7509 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7510 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7511 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7512 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7513 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7514 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7515 | } finally { |
| 7516 | Binder.restoreCallingIdentity(identity); |
| 7517 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7518 | } |
| 7519 | |
| 7520 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7521 | * Sets the per-account voicemail ringtone. |
| 7522 | * |
| 7523 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7524 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7525 | * |
| 7526 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7527 | * voicemail ringtone. |
| 7528 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7529 | * PhoneAccount. |
| 7530 | */ |
| 7531 | @Override |
| 7532 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7533 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7534 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7535 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7536 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7537 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7538 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7539 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7540 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7541 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7542 | |
| 7543 | final long identity = Binder.clearCallingIdentity(); |
| 7544 | try { |
| 7545 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7546 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7547 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7548 | } |
| 7549 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7550 | } finally { |
| 7551 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7552 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7553 | } |
| 7554 | |
| 7555 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7556 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7557 | * |
| 7558 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7559 | * voicemail vibration setting. |
| 7560 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7561 | */ |
| 7562 | @Override |
| 7563 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7564 | final long identity = Binder.clearCallingIdentity(); |
| 7565 | try { |
| 7566 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7567 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7568 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7569 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7570 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7571 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7572 | } finally { |
| 7573 | Binder.restoreCallingIdentity(identity); |
| 7574 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7575 | } |
| 7576 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7577 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7578 | * Sets the per-account voicemail vibration. |
| 7579 | * |
| 7580 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7581 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7582 | * |
| 7583 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7584 | * voicemail vibration setting. |
| 7585 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7586 | * specific PhoneAccount. |
| 7587 | */ |
| 7588 | @Override |
| 7589 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7590 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7591 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7592 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7593 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7594 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7595 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7596 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7597 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7598 | } |
| 7599 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7600 | final long identity = Binder.clearCallingIdentity(); |
| 7601 | try { |
| 7602 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7603 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7604 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7605 | } |
| 7606 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7607 | } finally { |
| 7608 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7609 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7610 | } |
| 7611 | |
| 7612 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7613 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 7614 | * |
| 7615 | * @throws SecurityException if the caller does not have the required permission |
| 7616 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7617 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7618 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7619 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7620 | } |
| 7621 | |
| 7622 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7623 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 7624 | * permission. |
| 7625 | * |
| 7626 | * @throws SecurityException if the caller does not have the required permission |
| 7627 | */ |
| 7628 | private void enforceSendSmsPermission() { |
| 7629 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 7630 | } |
| 7631 | |
| 7632 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7633 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7634 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7635 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7636 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7637 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7638 | final long identity = Binder.clearCallingIdentity(); |
| 7639 | try { |
| 7640 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7641 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7642 | if (componentName == null) { |
| 7643 | throw new SecurityException( |
| 7644 | "Caller not current active visual voicemail package[null]"); |
| 7645 | } |
| 7646 | String vvmPackage = componentName.getPackageName(); |
| 7647 | if (!callingPackage.equals(vvmPackage)) { |
| 7648 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 7649 | + vvmPackage + "]"); |
| 7650 | } |
| 7651 | } finally { |
| 7652 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7653 | } |
| 7654 | } |
| 7655 | |
| 7656 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7657 | * Return the application ID for the app type. |
| 7658 | * |
| 7659 | * @param subId the subscription ID that this request applies to. |
| 7660 | * @param appType the uicc app type. |
| 7661 | * @return Application ID for specificied app type, or null if no uicc. |
| 7662 | */ |
| 7663 | @Override |
| 7664 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7665 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7666 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7667 | |
| 7668 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7669 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7670 | if (phone == null) { |
| 7671 | return null; |
| 7672 | } |
| 7673 | String aid = null; |
| 7674 | try { |
| 7675 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 7676 | .getApplicationByType(appType).getAid(); |
| 7677 | } catch (Exception e) { |
| 7678 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 7679 | } |
| 7680 | return aid; |
| 7681 | } finally { |
| 7682 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7683 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7684 | } |
| 7685 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7686 | /** |
| 7687 | * Return the Electronic Serial Number. |
| 7688 | * |
| 7689 | * @param subId the subscription ID that this request applies to. |
| 7690 | * @return ESN or null if error. |
| 7691 | */ |
| 7692 | @Override |
| 7693 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7694 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7695 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7696 | |
| 7697 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7698 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7699 | if (phone == null) { |
| 7700 | return null; |
| 7701 | } |
| 7702 | String esn = null; |
| 7703 | try { |
| 7704 | esn = phone.getEsn(); |
| 7705 | } catch (Exception e) { |
| 7706 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 7707 | } |
| 7708 | return esn; |
| 7709 | } finally { |
| 7710 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7711 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7712 | } |
| 7713 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7714 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7715 | * Return the Preferred Roaming List Version. |
| 7716 | * |
| 7717 | * @param subId the subscription ID that this request applies to. |
| 7718 | * @return PRLVersion or null if error. |
| 7719 | */ |
| 7720 | @Override |
| 7721 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7722 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7723 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7724 | |
| 7725 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7726 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7727 | if (phone == null) { |
| 7728 | return null; |
| 7729 | } |
| 7730 | String cdmaPrlVersion = null; |
| 7731 | try { |
| 7732 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7733 | } catch (Exception e) { |
| 7734 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7735 | } |
| 7736 | return cdmaPrlVersion; |
| 7737 | } finally { |
| 7738 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7739 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7740 | } |
| 7741 | |
| 7742 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7743 | * Get snapshot of Telephony histograms |
| 7744 | * @return List of Telephony histograms |
| 7745 | * @hide |
| 7746 | */ |
| 7747 | @Override |
| 7748 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7749 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7750 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7751 | |
| 7752 | final long identity = Binder.clearCallingIdentity(); |
| 7753 | try { |
| 7754 | return RIL.getTelephonyRILTimingHistograms(); |
| 7755 | } finally { |
| 7756 | Binder.restoreCallingIdentity(identity); |
| 7757 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7758 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7759 | |
| 7760 | /** |
| 7761 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7762 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7763 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7764 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7765 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7766 | * @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] | 7767 | */ |
| 7768 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7769 | @TelephonyManager.SetCarrierRestrictionResult |
| 7770 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7771 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7772 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7773 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7774 | if (carrierRestrictionRules == null) { |
| 7775 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7776 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7777 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7778 | final long identity = Binder.clearCallingIdentity(); |
| 7779 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7780 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7781 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7782 | } finally { |
| 7783 | Binder.restoreCallingIdentity(identity); |
| 7784 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7785 | } |
| 7786 | |
| 7787 | /** |
| 7788 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7789 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7790 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7791 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7792 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7793 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7794 | */ |
| 7795 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7796 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7797 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7798 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7799 | |
| 7800 | final long identity = Binder.clearCallingIdentity(); |
| 7801 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7802 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7803 | if (response instanceof CarrierRestrictionRules) { |
| 7804 | return (CarrierRestrictionRules) response; |
| 7805 | } |
| 7806 | // Response is an Exception of some kind, |
| 7807 | // which is signalled to the user as a NULL retval |
| 7808 | return null; |
| 7809 | } catch (Exception e) { |
| 7810 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7811 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7812 | } finally { |
| 7813 | Binder.restoreCallingIdentity(identity); |
| 7814 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7815 | } |
| 7816 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7817 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7818 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7819 | * @param subId the subscription ID that this action applies to. |
| 7820 | * @param enabled control enable or disable radio. |
| 7821 | * {@hide} |
| 7822 | */ |
| 7823 | @Override |
| 7824 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7825 | enforceModifyPermission(); |
| 7826 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7827 | |
| 7828 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7829 | if (phone == null) { |
| 7830 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7831 | return; |
| 7832 | } |
| 7833 | try { |
| 7834 | phone.carrierActionSetRadioEnabled(enabled); |
| 7835 | } catch (Exception e) { |
| 7836 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7837 | } finally { |
| 7838 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7839 | } |
| 7840 | } |
| 7841 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7842 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7843 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7844 | * network status based on which carrier apps could apply actions accordingly, |
| 7845 | * enable/disable default url handler for example. |
| 7846 | * |
| 7847 | * @param subId the subscription ID that this action applies to. |
| 7848 | * @param report control start/stop reporting the default network status. |
| 7849 | * {@hide} |
| 7850 | */ |
| 7851 | @Override |
| 7852 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7853 | enforceModifyPermission(); |
| 7854 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7855 | |
| 7856 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7857 | if (phone == null) { |
| 7858 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7859 | return; |
| 7860 | } |
| 7861 | try { |
| 7862 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7863 | } catch (Exception e) { |
| 7864 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7865 | } finally { |
| 7866 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7867 | } |
| 7868 | } |
| 7869 | |
| 7870 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7871 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7872 | * @param subId the subscription ID that this action applies to. |
| 7873 | * {@hide} |
| 7874 | */ |
| 7875 | @Override |
| 7876 | public void carrierActionResetAll(int subId) { |
| 7877 | enforceModifyPermission(); |
| 7878 | final Phone phone = getPhone(subId); |
| 7879 | if (phone == null) { |
| 7880 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7881 | return; |
| 7882 | } |
| 7883 | try { |
| 7884 | phone.carrierActionResetAll(); |
| 7885 | } catch (Exception e) { |
| 7886 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7887 | } |
| 7888 | } |
| 7889 | |
| 7890 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7891 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7892 | * bug report is being generated. |
| 7893 | */ |
| 7894 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7895 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7896 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7897 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7898 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7899 | + Binder.getCallingPid() |
| 7900 | + ", uid=" + Binder.getCallingUid() |
| 7901 | + "without permission " |
| 7902 | + android.Manifest.permission.DUMP); |
| 7903 | return; |
| 7904 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7905 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7906 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7907 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7908 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 7909 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 7910 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 7911 | @NonNull String[] args) { |
| 7912 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 7913 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 7914 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7915 | } |
| 7916 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7917 | /** |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7918 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7919 | * @param subId Subscription index |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7920 | * @param reason the reason the data enable change is taking place |
| 7921 | * @param enabled True if enabling the data, otherwise disabling. |
| 7922 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7923 | */ |
| 7924 | @Override |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7925 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7926 | boolean enabled) { |
| 7927 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 7928 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7929 | try { |
| 7930 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7931 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7932 | } catch (SecurityException se) { |
| 7933 | enforceModifyPermission(); |
| 7934 | } |
| 7935 | } else { |
| 7936 | enforceModifyPermission(); |
| 7937 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7938 | |
| 7939 | final long identity = Binder.clearCallingIdentity(); |
| 7940 | try { |
| 7941 | Phone phone = getPhone(subId); |
| 7942 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7943 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7944 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7945 | } else { |
| 7946 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 7947 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7948 | } |
| 7949 | } finally { |
| 7950 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7951 | } |
| 7952 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7953 | |
| 7954 | /** |
| 7955 | * Get Client request stats |
| 7956 | * @return List of Client Request Stats |
| 7957 | * @hide |
| 7958 | */ |
| 7959 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7960 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7961 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7962 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7963 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7964 | return null; |
| 7965 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7966 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7967 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7968 | final long identity = Binder.clearCallingIdentity(); |
| 7969 | try { |
| 7970 | if (phone != null) { |
| 7971 | return phone.getClientRequestStats(); |
| 7972 | } |
| 7973 | |
| 7974 | return null; |
| 7975 | } finally { |
| 7976 | Binder.restoreCallingIdentity(identity); |
| 7977 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7978 | } |
| 7979 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7980 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7981 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7982 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7983 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7984 | |
| 7985 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7986 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7987 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7988 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7989 | * @param state State of SIM (power down, power up, pass through) |
| 7990 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7991 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7992 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7993 | * |
| 7994 | **/ |
| 7995 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7996 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7997 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7998 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7999 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8000 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8001 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8002 | final long identity = Binder.clearCallingIdentity(); |
| 8003 | try { |
| 8004 | if (phone != null) { |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8005 | phone.setSimPowerState(state, null, workSource); |
| 8006 | } |
| 8007 | } finally { |
| 8008 | Binder.restoreCallingIdentity(identity); |
| 8009 | } |
| 8010 | } |
| 8011 | |
| 8012 | /** |
| 8013 | * Set SIM card power state. |
| 8014 | * |
| 8015 | * @param slotIndex SIM slot id. |
| 8016 | * @param state State of SIM (power down, power up, pass through) |
| 8017 | * @param callback callback to trigger after success or failure |
| 8018 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8019 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8020 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8021 | * |
| 8022 | **/ |
| 8023 | @Override |
| 8024 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8025 | IIntegerConsumer callback) { |
| 8026 | enforceModifyPermission(); |
| 8027 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8028 | |
| 8029 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8030 | |
| 8031 | final long identity = Binder.clearCallingIdentity(); |
| 8032 | try { |
| 8033 | if (phone != null) { |
| 8034 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8035 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8036 | } |
| 8037 | } finally { |
| 8038 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8039 | } |
| 8040 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8041 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8042 | private boolean isUssdApiAllowed(int subId) { |
| 8043 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8044 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8045 | if (configManager == null) { |
| 8046 | return false; |
| 8047 | } |
| 8048 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8049 | if (pb == null) { |
| 8050 | return false; |
| 8051 | } |
| 8052 | return pb.getBoolean( |
| 8053 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8054 | } |
| 8055 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8056 | /** |
| 8057 | * Check if phone is in emergency callback mode |
| 8058 | * @return true if phone is in emergency callback mode |
| 8059 | * @param subId sub id |
| 8060 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8061 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8062 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8063 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8064 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8065 | |
| 8066 | final long identity = Binder.clearCallingIdentity(); |
| 8067 | try { |
| 8068 | if (phone != null) { |
| 8069 | return phone.isInEcm(); |
| 8070 | } else { |
| 8071 | return false; |
| 8072 | } |
| 8073 | } finally { |
| 8074 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8075 | } |
| 8076 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8077 | |
| 8078 | /** |
| 8079 | * Get the current signal strength information for the given subscription. |
| 8080 | * Because this information is not updated when the device is in a low power state |
| 8081 | * it should not be relied-upon to be current. |
| 8082 | * @param subId Subscription index |
| 8083 | * @return the most recent cached signal strength info from the modem |
| 8084 | */ |
| 8085 | @Override |
| 8086 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8087 | final long identity = Binder.clearCallingIdentity(); |
| 8088 | try { |
| 8089 | Phone p = getPhone(subId); |
| 8090 | if (p == null) { |
| 8091 | return null; |
| 8092 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8093 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8094 | return p.getSignalStrength(); |
| 8095 | } finally { |
| 8096 | Binder.restoreCallingIdentity(identity); |
| 8097 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8098 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8099 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8100 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8101 | * Get the current modem radio state for the given slot. |
| 8102 | * @param slotIndex slot index. |
| 8103 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8104 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8105 | * @return the current radio power state from the modem |
| 8106 | */ |
| 8107 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8108 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8109 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8110 | if (phone != null) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8111 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8112 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8113 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8114 | } |
| 8115 | |
| 8116 | final long identity = Binder.clearCallingIdentity(); |
| 8117 | try { |
| 8118 | return phone.getRadioPowerState(); |
| 8119 | } finally { |
| 8120 | Binder.restoreCallingIdentity(identity); |
| 8121 | } |
| 8122 | } |
| 8123 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8124 | } |
| 8125 | |
| 8126 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8127 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8128 | * |
| 8129 | * <p>Requires one of the following permissions: |
| 8130 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 8131 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8132 | * privileges. |
| 8133 | * |
| 8134 | * @param subId subscription id |
| 8135 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8136 | * {@code false}. |
| 8137 | */ |
| 8138 | @Override |
| 8139 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 11263f3 | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8140 | try { |
| 8141 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8142 | null); |
| 8143 | } catch (Exception e) { |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8144 | TelephonyPermissions.enforceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
Shuo Qian | 11263f3 | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8145 | mApp, subId, "isDataRoamingEnabled"); |
| 8146 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8147 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8148 | boolean isEnabled = false; |
| 8149 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8150 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8151 | Phone phone = getPhone(subId); |
| 8152 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8153 | } finally { |
| 8154 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8155 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8156 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8157 | } |
| 8158 | |
| 8159 | |
| 8160 | /** |
| 8161 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8162 | * |
| 8163 | * <p> Requires permission: |
| 8164 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8165 | * privileges. |
| 8166 | * |
| 8167 | * @param subId subscription id |
| 8168 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8169 | */ |
| 8170 | @Override |
| 8171 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8172 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8173 | mApp, subId, "setDataRoamingEnabled"); |
| 8174 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8175 | final long identity = Binder.clearCallingIdentity(); |
| 8176 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8177 | Phone phone = getPhone(subId); |
| 8178 | if (phone != null) { |
| 8179 | phone.setDataRoamingEnabled(isEnabled); |
| 8180 | } |
| 8181 | } finally { |
| 8182 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8183 | } |
| 8184 | } |
| 8185 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8186 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8187 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8188 | TelephonyPermissions |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8189 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8190 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8191 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8192 | boolean isAllowed = true; |
| 8193 | final long identity = Binder.clearCallingIdentity(); |
| 8194 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8195 | Phone phone = getPhone(subId); |
| 8196 | if (phone != null) { |
| 8197 | isAllowed = phone.isCspPlmnEnabled(); |
| 8198 | } |
| 8199 | } finally { |
| 8200 | Binder.restoreCallingIdentity(identity); |
| 8201 | } |
| 8202 | return isAllowed; |
| 8203 | } |
| 8204 | |
| 8205 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8206 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | cfdfe3a | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8207 | // Verify that tha callingPackage belongs to the calling UID |
| 8208 | mApp.getSystemService(AppOpsManager.class) |
| 8209 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8210 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8211 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8212 | try { |
| 8213 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8214 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8215 | } catch (SecurityException e) { |
| 8216 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8217 | // has carrier privileges on an active UICC |
| 8218 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8219 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8220 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8221 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8222 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8223 | |
| 8224 | final long identity = Binder.clearCallingIdentity(); |
| 8225 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8226 | UiccController uiccController = UiccController.getInstance(); |
| 8227 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8228 | if (hasReadPermission) { |
| 8229 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8230 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8231 | |
| 8232 | // Remove private info if the caller doesn't have access |
| 8233 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8234 | for (UiccCardInfo cardInfo : cardInfos) { |
| 8235 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8236 | // is available |
| 8237 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 8238 | if (card == null || card.getUiccProfile() == null) { |
| 8239 | // assume no access if the card or profile is unavailable |
| 8240 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8241 | continue; |
| 8242 | } |
| 8243 | UiccProfile profile = card.getUiccProfile(); |
| 8244 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8245 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8246 | filteredInfos.add(cardInfo); |
| 8247 | } else { |
| 8248 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8249 | } |
| 8250 | } |
| 8251 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8252 | } finally { |
| 8253 | Binder.restoreCallingIdentity(identity); |
| 8254 | } |
| 8255 | } |
| 8256 | |
| 8257 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8258 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8259 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8260 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8261 | final long identity = Binder.clearCallingIdentity(); |
| 8262 | try { |
| 8263 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8264 | if (slots == null) { |
| 8265 | Rlog.i(LOG_TAG, "slots is null."); |
| 8266 | return null; |
| 8267 | } |
| 8268 | |
| 8269 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8270 | for (int i = 0; i < slots.length; i++) { |
| 8271 | UiccSlot slot = slots[i]; |
| 8272 | if (slot == null) { |
| 8273 | continue; |
| 8274 | } |
| 8275 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8276 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8277 | UiccCard card = slot.getUiccCard(); |
| 8278 | if (card != null) { |
| 8279 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8280 | } else { |
Jordan Liu | d96b529 | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8281 | cardId = slot.getEid(); |
| 8282 | if (TextUtils.isEmpty(cardId)) { |
| 8283 | cardId = slot.getIccId(); |
| 8284 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8285 | } |
| 8286 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8287 | if (cardId != null) { |
| 8288 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8289 | // if cardId is an EID, it's all digits so this is fine |
| 8290 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8291 | } |
| 8292 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8293 | int cardState = 0; |
| 8294 | switch (slot.getCardState()) { |
| 8295 | case CARDSTATE_ABSENT: |
| 8296 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8297 | break; |
| 8298 | case CARDSTATE_PRESENT: |
| 8299 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8300 | break; |
| 8301 | case CARDSTATE_ERROR: |
| 8302 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8303 | break; |
| 8304 | case CARDSTATE_RESTRICTED: |
| 8305 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8306 | break; |
| 8307 | default: |
| 8308 | break; |
| 8309 | |
| 8310 | } |
| 8311 | |
| 8312 | infos[i] = new UiccSlotInfo( |
| 8313 | slot.isActive(), |
| 8314 | slot.isEuicc(), |
| 8315 | cardId, |
| 8316 | cardState, |
| 8317 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8318 | slot.isExtendedApduSupported(), |
| 8319 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8320 | } |
| 8321 | return infos; |
| 8322 | } finally { |
| 8323 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8324 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8325 | } |
| 8326 | |
| 8327 | @Override |
| 8328 | public boolean switchSlots(int[] physicalSlots) { |
| 8329 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8330 | |
| 8331 | final long identity = Binder.clearCallingIdentity(); |
| 8332 | try { |
| 8333 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8334 | } finally { |
| 8335 | Binder.restoreCallingIdentity(identity); |
| 8336 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8337 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8338 | |
| 8339 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8340 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8341 | final long identity = Binder.clearCallingIdentity(); |
| 8342 | try { |
| 8343 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8344 | } finally { |
| 8345 | Binder.restoreCallingIdentity(identity); |
| 8346 | } |
| 8347 | } |
| 8348 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8349 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8350 | * A test API to reload the UICC profile. |
| 8351 | * |
| 8352 | * <p>Requires that the calling app has permission |
| 8353 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8354 | * @hide |
| 8355 | */ |
| 8356 | @Override |
| 8357 | public void refreshUiccProfile(int subId) { |
| 8358 | enforceModifyPermission(); |
| 8359 | |
| 8360 | final long identity = Binder.clearCallingIdentity(); |
| 8361 | try { |
| 8362 | Phone phone = getPhone(subId); |
| 8363 | if (phone == null) { |
| 8364 | return; |
| 8365 | } |
| 8366 | UiccCard uiccCard = phone.getUiccCard(); |
| 8367 | if (uiccCard == null) { |
| 8368 | return; |
| 8369 | } |
| 8370 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8371 | if (uiccProfile == null) { |
| 8372 | return; |
| 8373 | } |
| 8374 | uiccProfile.refresh(); |
| 8375 | } finally { |
| 8376 | Binder.restoreCallingIdentity(identity); |
| 8377 | } |
| 8378 | } |
| 8379 | |
| 8380 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8381 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8382 | */ |
| 8383 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8384 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8385 | } |
| 8386 | |
| 8387 | /** |
| 8388 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8389 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8390 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8391 | */ |
| 8392 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8393 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8394 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | faaa63d | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8395 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8396 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8397 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8398 | return isDataRoamingEnabled; |
| 8399 | } |
| 8400 | |
| 8401 | /** |
| 8402 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8403 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8404 | */ |
| 8405 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8406 | List<Integer> list = TelephonyProperties.default_network(); |
| 8407 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8408 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8409 | return list.get(phoneId); |
| 8410 | } |
| 8411 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8412 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8413 | |
| 8414 | @Override |
| 8415 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8416 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8417 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8418 | |
| 8419 | final long identity = Binder.clearCallingIdentity(); |
| 8420 | try { |
| 8421 | final Phone phone = getPhone(subId); |
| 8422 | if (phone == null) { |
| 8423 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8424 | return; |
| 8425 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8426 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8427 | carrierPrivilegeRules, apn); |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8428 | if (carrierPrivilegeRules == null) { |
| 8429 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8430 | } else { |
| 8431 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8432 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8433 | } finally { |
| 8434 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8435 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8436 | } |
| 8437 | |
| 8438 | @Override |
| 8439 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8440 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8441 | |
| 8442 | final long identity = Binder.clearCallingIdentity(); |
| 8443 | try { |
| 8444 | final Phone phone = getPhone(subId); |
| 8445 | if (phone == null) { |
| 8446 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 8447 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 8448 | } |
| 8449 | return phone.getCarrierIdListVersion(); |
| 8450 | } finally { |
| 8451 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8452 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8453 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8454 | |
| 8455 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8456 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 8457 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8458 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8459 | mApp, subId, callingPackage, callingFeatureId, |
| 8460 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8461 | return -1; |
| 8462 | } |
| 8463 | |
| 8464 | final long identity = Binder.clearCallingIdentity(); |
| 8465 | try { |
| 8466 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 8467 | } finally { |
| 8468 | Binder.restoreCallingIdentity(identity); |
| 8469 | } |
| 8470 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8471 | |
| 8472 | @Override |
| 8473 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 0723870 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 8474 | TelephonyPermissions |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8475 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8476 | mApp, subId, "getCdmaRoamingMode"); |
| 8477 | |
| 8478 | final long identity = Binder.clearCallingIdentity(); |
| 8479 | try { |
| 8480 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 8481 | } finally { |
| 8482 | Binder.restoreCallingIdentity(identity); |
| 8483 | } |
| 8484 | } |
| 8485 | |
| 8486 | @Override |
| 8487 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 8488 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8489 | mApp, subId, "setCdmaRoamingMode"); |
| 8490 | |
| 8491 | final long identity = Binder.clearCallingIdentity(); |
| 8492 | try { |
| 8493 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 8494 | } finally { |
| 8495 | Binder.restoreCallingIdentity(identity); |
| 8496 | } |
| 8497 | } |
| 8498 | |
| 8499 | @Override |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8500 | public int getCdmaSubscriptionMode(int subId) { |
| 8501 | TelephonyPermissions |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8502 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8503 | mApp, subId, "getCdmaSubscriptionMode"); |
| 8504 | |
| 8505 | final long identity = Binder.clearCallingIdentity(); |
| 8506 | try { |
| 8507 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 8508 | } finally { |
| 8509 | Binder.restoreCallingIdentity(identity); |
| 8510 | } |
| 8511 | } |
| 8512 | |
| 8513 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8514 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 8515 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8516 | mApp, subId, "setCdmaSubscriptionMode"); |
| 8517 | |
| 8518 | final long identity = Binder.clearCallingIdentity(); |
| 8519 | try { |
| 8520 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 8521 | } finally { |
| 8522 | Binder.restoreCallingIdentity(identity); |
| 8523 | } |
| 8524 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8525 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8526 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8527 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8528 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8529 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8530 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 8531 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8532 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8533 | } |
| 8534 | final long identity = Binder.clearCallingIdentity(); |
| 8535 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8536 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 8537 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8538 | if (phone.getEmergencyNumberTracker() != null |
| 8539 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 8540 | emergencyNumberListInternal.put( |
| 8541 | phone.getSubId(), |
| 8542 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 8543 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8544 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8545 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8546 | } finally { |
| 8547 | Binder.restoreCallingIdentity(identity); |
| 8548 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8549 | } |
| 8550 | |
| 8551 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8552 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8553 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8554 | if (!exactMatch) { |
| 8555 | TelephonyPermissions |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 8556 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8557 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8558 | } |
| 8559 | final long identity = Binder.clearCallingIdentity(); |
| 8560 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8561 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8562 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8563 | && phone.getEmergencyNumberTracker() |
| 8564 | .isEmergencyNumber(number, exactMatch)) { |
| 8565 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8566 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8567 | } |
| 8568 | return false; |
| 8569 | } finally { |
| 8570 | Binder.restoreCallingIdentity(identity); |
| 8571 | } |
| 8572 | } |
| 8573 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8574 | /** |
| 8575 | * Update emergency number list for test mode. |
| 8576 | */ |
| 8577 | @Override |
| 8578 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 8579 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8580 | "updateEmergencyNumberListTestMode"); |
| 8581 | |
| 8582 | final long identity = Binder.clearCallingIdentity(); |
| 8583 | try { |
| 8584 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8585 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8586 | if (tracker != null) { |
| 8587 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 8588 | } |
| 8589 | } |
| 8590 | } finally { |
| 8591 | Binder.restoreCallingIdentity(identity); |
| 8592 | } |
| 8593 | } |
| 8594 | |
| 8595 | /** |
| 8596 | * Get the full emergency number list for test mode. |
| 8597 | */ |
| 8598 | @Override |
| 8599 | public List<String> getEmergencyNumberListTestMode() { |
| 8600 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8601 | "getEmergencyNumberListTestMode"); |
| 8602 | |
| 8603 | final long identity = Binder.clearCallingIdentity(); |
| 8604 | try { |
| 8605 | Set<String> emergencyNumbers = new HashSet<>(); |
| 8606 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8607 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8608 | if (tracker != null) { |
| 8609 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 8610 | emergencyNumbers.add(num.getNumber()); |
| 8611 | } |
| 8612 | } |
| 8613 | } |
| 8614 | return new ArrayList<>(emergencyNumbers); |
| 8615 | } finally { |
| 8616 | Binder.restoreCallingIdentity(identity); |
| 8617 | } |
| 8618 | } |
| 8619 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8620 | @Override |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8621 | public int getEmergencyNumberDbVersion(int subId) { |
| 8622 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 8623 | |
| 8624 | final long identity = Binder.clearCallingIdentity(); |
| 8625 | try { |
| 8626 | final Phone phone = getPhone(subId); |
| 8627 | if (phone == null) { |
| 8628 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 8629 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 8630 | } |
| 8631 | return phone.getEmergencyNumberDbVersion(); |
| 8632 | } finally { |
| 8633 | Binder.restoreCallingIdentity(identity); |
| 8634 | } |
| 8635 | } |
| 8636 | |
| 8637 | @Override |
| 8638 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 8639 | enforceModifyPermission(); |
| 8640 | |
| 8641 | final long identity = Binder.clearCallingIdentity(); |
| 8642 | try { |
| 8643 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8644 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8645 | if (tracker != null) { |
| 8646 | tracker.updateOtaEmergencyNumberDatabase(); |
| 8647 | } |
| 8648 | } |
| 8649 | } finally { |
| 8650 | Binder.restoreCallingIdentity(identity); |
| 8651 | } |
| 8652 | } |
| 8653 | |
| 8654 | @Override |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8655 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8656 | enforceActiveEmergencySessionPermission(); |
| 8657 | |
| 8658 | final long identity = Binder.clearCallingIdentity(); |
| 8659 | try { |
| 8660 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8661 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8662 | if (tracker != null) { |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8663 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 8664 | } |
| 8665 | } |
| 8666 | } finally { |
| 8667 | Binder.restoreCallingIdentity(identity); |
| 8668 | } |
| 8669 | } |
| 8670 | |
| 8671 | @Override |
| 8672 | public void resetOtaEmergencyNumberDbFilePath() { |
| 8673 | enforceActiveEmergencySessionPermission(); |
| 8674 | |
| 8675 | final long identity = Binder.clearCallingIdentity(); |
| 8676 | try { |
| 8677 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8678 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8679 | if (tracker != null) { |
| 8680 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8681 | } |
| 8682 | } |
| 8683 | } finally { |
| 8684 | Binder.restoreCallingIdentity(identity); |
| 8685 | } |
| 8686 | } |
| 8687 | |
| 8688 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8689 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 8690 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 8691 | Phone phone = getPhone(subId); |
| 8692 | if (phone == null) { |
| 8693 | return null; |
| 8694 | } |
| 8695 | final long identity = Binder.clearCallingIdentity(); |
| 8696 | try { |
| 8697 | UiccProfile profile = UiccController.getInstance() |
| 8698 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 8699 | if (profile != null) { |
| 8700 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 8701 | } |
| 8702 | } finally { |
| 8703 | Binder.restoreCallingIdentity(identity); |
| 8704 | } |
| 8705 | return null; |
| 8706 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 8707 | |
| 8708 | /** |
| 8709 | * Enable or disable a modem stack. |
| 8710 | */ |
| 8711 | @Override |
| 8712 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 8713 | enforceModifyPermission(); |
| 8714 | |
| 8715 | final long identity = Binder.clearCallingIdentity(); |
| 8716 | try { |
| 8717 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8718 | if (phone == null) { |
| 8719 | return false; |
| 8720 | } else { |
| 8721 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 8722 | } |
| 8723 | } finally { |
| 8724 | Binder.restoreCallingIdentity(identity); |
| 8725 | } |
| 8726 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8727 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8728 | /** |
| 8729 | * Whether a modem stack is enabled or not. |
| 8730 | */ |
| 8731 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8732 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 8733 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8734 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8735 | if (phone == null) return false; |
| 8736 | |
| 8737 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8738 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 8739 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8740 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8741 | } |
| 8742 | |
| 8743 | final long identity = Binder.clearCallingIdentity(); |
| 8744 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8745 | try { |
| 8746 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 8747 | } catch (NoSuchElementException ex) { |
| 8748 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 8749 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8750 | } finally { |
| 8751 | Binder.restoreCallingIdentity(identity); |
| 8752 | } |
| 8753 | } |
| 8754 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8755 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8756 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8757 | enforceModifyPermission(); |
| 8758 | |
| 8759 | final long identity = Binder.clearCallingIdentity(); |
| 8760 | try { |
| 8761 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8762 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8763 | .commit(); |
| 8764 | } finally { |
| 8765 | Binder.restoreCallingIdentity(identity); |
| 8766 | } |
| 8767 | } |
| 8768 | |
| 8769 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8770 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8771 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8772 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8773 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8774 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8775 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8776 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8777 | |
| 8778 | final long identity = Binder.clearCallingIdentity(); |
| 8779 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8780 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8781 | } finally { |
| 8782 | Binder.restoreCallingIdentity(identity); |
| 8783 | } |
| 8784 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8785 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8786 | @TelephonyManager.IsMultiSimSupportedResult |
| 8787 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8788 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8789 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8790 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8791 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8792 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8793 | } |
| 8794 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8795 | // supported by the modem, indicate that it is restricted. |
| 8796 | PhoneCapability staticCapability = |
| 8797 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8798 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8799 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8800 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8801 | } |
Sarah Chin | 09f38ee | 2020-02-25 00:13:10 +0000 | [diff] [blame] | 8802 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8803 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8804 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8805 | } |
| 8806 | // Check if support of multiple SIMs is restricted by carrier |
| 8807 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8808 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8809 | } |
| 8810 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8811 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8812 | } |
| 8813 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8814 | /** |
| 8815 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8816 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8817 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8818 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8819 | * @param numOfSims number of active sims we want to switch to |
| 8820 | */ |
| 8821 | @Override |
| 8822 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8823 | if (numOfSims == 1) { |
| 8824 | enforceModifyPermission(); |
| 8825 | } else { |
| 8826 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8827 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8828 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8829 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8830 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8831 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8832 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8833 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8834 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8835 | return; |
| 8836 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8837 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8838 | } finally { |
| 8839 | Binder.restoreCallingIdentity(identity); |
| 8840 | } |
| 8841 | } |
| 8842 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8843 | @Override |
| 8844 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8845 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8846 | Phone phone = getPhone(subId); |
| 8847 | if (phone == null) { |
| 8848 | return false; |
| 8849 | } |
| 8850 | final long identity = Binder.clearCallingIdentity(); |
| 8851 | try { |
| 8852 | UiccCard uiccCard = phone.getUiccCard(); |
| 8853 | if (uiccCard == null) { |
| 8854 | return false; |
| 8855 | } |
| 8856 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8857 | if (uiccProfile == null) { |
| 8858 | return false; |
| 8859 | } |
| 8860 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8861 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8862 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8863 | } |
| 8864 | return false; |
| 8865 | } finally { |
| 8866 | Binder.restoreCallingIdentity(identity); |
| 8867 | } |
| 8868 | } |
| 8869 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8870 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8871 | * Get whether making changes to modem configurations will trigger reboot. |
| 8872 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8873 | */ |
| 8874 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8875 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8876 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8877 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8878 | mApp, subId, callingPackage, callingFeatureId, |
| 8879 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8880 | return false; |
| 8881 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8882 | final long identity = Binder.clearCallingIdentity(); |
| 8883 | try { |
| 8884 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8885 | } finally { |
| 8886 | Binder.restoreCallingIdentity(identity); |
| 8887 | } |
| 8888 | } |
| 8889 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8890 | private void updateModemStateMetrics() { |
| 8891 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8892 | // TODO: check the state for each modem if the api is ready. |
| 8893 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8894 | } |
| 8895 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8896 | @Override |
| 8897 | public int[] getSlotsMapping() { |
| 8898 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8899 | |
| 8900 | final long identity = Binder.clearCallingIdentity(); |
| 8901 | try { |
| 8902 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8903 | // All logical slots should have a mapping to a physical slot. |
| 8904 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8905 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8906 | for (int i = 0; i < slotInfos.length; i++) { |
| 8907 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8908 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8909 | } |
| 8910 | } |
| 8911 | return logicalSlotsMapping; |
| 8912 | } finally { |
| 8913 | Binder.restoreCallingIdentity(identity); |
| 8914 | } |
| 8915 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8916 | |
| 8917 | /** |
| 8918 | * Get the IRadio HAL Version |
| 8919 | */ |
| 8920 | @Override |
| 8921 | public int getRadioHalVersion() { |
| 8922 | Phone phone = getDefaultPhone(); |
| 8923 | if (phone == null) return -1; |
| 8924 | HalVersion hv = phone.getHalVersion(); |
| 8925 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8926 | return hv.major * 100 + hv.minor; |
| 8927 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8928 | |
| 8929 | /** |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8930 | * Get the current calling package name. |
| 8931 | * @return the current calling package name |
| 8932 | */ |
| 8933 | @Override |
| 8934 | public String getCurrentPackageName() { |
| 8935 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8936 | } |
| 8937 | |
| 8938 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8939 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8940 | * corresponding network requests on a subId. |
| 8941 | * |
| 8942 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8943 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8944 | * 2) APN is un-metered for this subscription, or |
| 8945 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | b48cf45 | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 8946 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8947 | * |
| 8948 | * @return whether data is allowed for a apn type. |
| 8949 | * |
| 8950 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8951 | */ |
| 8952 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8953 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | f250974 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8954 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8955 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8956 | |
| 8957 | // Now that all security checks passes, perform the operation as ourselves. |
| 8958 | final long identity = Binder.clearCallingIdentity(); |
| 8959 | try { |
| 8960 | Phone phone = getPhone(subId); |
| 8961 | if (phone == null) return false; |
| 8962 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8963 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8964 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8965 | } finally { |
| 8966 | Binder.restoreCallingIdentity(identity); |
| 8967 | } |
| 8968 | } |
| 8969 | |
| 8970 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8971 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8972 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8973 | |
| 8974 | // Now that all security checks passes, perform the operation as ourselves. |
| 8975 | final long identity = Binder.clearCallingIdentity(); |
| 8976 | try { |
| 8977 | Phone phone = getPhone(subId); |
| 8978 | if (phone == null) return true; // By default return true. |
| 8979 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8980 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8981 | } finally { |
| 8982 | Binder.restoreCallingIdentity(identity); |
| 8983 | } |
| 8984 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8985 | |
| 8986 | @Override |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 8987 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 8988 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 8989 | enforceModifyPermission(); |
| 8990 | long token = Binder.clearCallingIdentity(); |
| 8991 | try { |
| 8992 | Phone phone = getPhone(subscriptionId); |
| 8993 | if (phone == null) { |
| 8994 | try { |
| 8995 | if (resultCallback != null) { |
| 8996 | resultCallback.accept(false); |
| 8997 | } |
| 8998 | } catch (RemoteException e) { |
| 8999 | // ignore |
| 9000 | } |
| 9001 | return; |
| 9002 | } |
| 9003 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9004 | Pair.create(specifiers, (x) -> { |
| 9005 | try { |
| 9006 | if (resultCallback != null) { |
| 9007 | resultCallback.accept(x); |
| 9008 | } |
| 9009 | } catch (RemoteException e) { |
| 9010 | // ignore |
| 9011 | } |
| 9012 | }); |
| 9013 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9014 | } finally { |
| 9015 | Binder.restoreCallingIdentity(token); |
| 9016 | } |
| 9017 | } |
| 9018 | |
| 9019 | @Override |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9020 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9021 | TelephonyPermissions |
Nathan Harold | 75a9ff1 | 2021-04-06 11:26:02 -0700 | [diff] [blame] | 9022 | .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9023 | mApp, subId, "getSystemSelectionChannels"); |
| 9024 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9025 | final long identity = Binder.clearCallingIdentity(); |
| 9026 | try { |
| 9027 | List<RadioAccessSpecifier> specifiers = |
| 9028 | (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, |
| 9029 | null, subId, workSource); |
| 9030 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9031 | return specifiers; |
| 9032 | } finally { |
| 9033 | Binder.restoreCallingIdentity(identity); |
| 9034 | } |
| 9035 | } |
| 9036 | |
| 9037 | @Override |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9038 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9039 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9040 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 9041 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 9042 | if (iccRecords == null) { |
| 9043 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 9044 | return false; |
| 9045 | } |
| 9046 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9047 | } |
| 9048 | |
| 9049 | @Override |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9050 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9051 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9052 | if (callingPackage == null) { |
| 9053 | callingPackage = getCurrentPackageName(); |
| 9054 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9055 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9056 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9057 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9058 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9059 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9060 | } |
| 9061 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9062 | Intent intent = new Intent(); |
| 9063 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9064 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9065 | // Bring up choose default SMS subscription dialog right now |
| 9066 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9067 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9068 | mApp.startActivity(intent); |
| 9069 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9070 | |
| 9071 | @Override |
| 9072 | public String getMmsUAProfUrl(int subId) { |
| 9073 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9074 | final long identity = Binder.clearCallingIdentity(); |
| 9075 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9076 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9077 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9078 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9079 | return carrierUAProfUrl; |
| 9080 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9081 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9082 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 9083 | } finally { |
| 9084 | Binder.restoreCallingIdentity(identity); |
| 9085 | } |
| 9086 | } |
| 9087 | |
| 9088 | @Override |
| 9089 | public String getMmsUserAgent(int subId) { |
| 9090 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9091 | final long identity = Binder.clearCallingIdentity(); |
| 9092 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9093 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9094 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9095 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9096 | return carrierUserAgent; |
| 9097 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9098 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9099 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 9100 | } finally { |
| 9101 | Binder.restoreCallingIdentity(identity); |
| 9102 | } |
| 9103 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9104 | |
| 9105 | @Override |
Hall Liu | c041a55 | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9106 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9107 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
| 9108 | |
| 9109 | final long identity = Binder.clearCallingIdentity(); |
| 9110 | try { |
| 9111 | Phone phone = getPhone(subscriptionId); |
| 9112 | if (phone == null) return false; |
| 9113 | |
| 9114 | switch (policy) { |
| 9115 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9116 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9117 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9118 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9119 | default: |
| 9120 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9121 | } |
| 9122 | } finally { |
| 9123 | Binder.restoreCallingIdentity(identity); |
| 9124 | } |
| 9125 | } |
| 9126 | |
| 9127 | @Override |
| 9128 | public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy, |
| 9129 | boolean enabled) { |
| 9130 | enforceModifyPermission(); |
| 9131 | |
| 9132 | final long identity = Binder.clearCallingIdentity(); |
| 9133 | try { |
| 9134 | Phone phone = getPhone(subscriptionId); |
| 9135 | if (phone == null) return; |
| 9136 | |
| 9137 | switch (policy) { |
| 9138 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9139 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9140 | break; |
| 9141 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9142 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9143 | break; |
| 9144 | default: |
| 9145 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9146 | } |
| 9147 | } finally { |
| 9148 | Binder.restoreCallingIdentity(identity); |
| 9149 | } |
| 9150 | } |
| 9151 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9152 | /** |
Hall Liu | b48cf45 | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9153 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9154 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9155 | * otherwise. |
| 9156 | */ |
| 9157 | @Override |
| 9158 | public void setCepEnabled(boolean isCepEnabled) { |
| 9159 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9160 | |
| 9161 | final long identity = Binder.clearCallingIdentity(); |
| 9162 | try { |
| 9163 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9164 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9165 | Phone defaultPhone = phone.getImsPhone(); |
| 9166 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9167 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9168 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9169 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9170 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9171 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9172 | + imsPhone.getMsisdn()); |
| 9173 | } |
| 9174 | } |
| 9175 | } finally { |
| 9176 | Binder.restoreCallingIdentity(identity); |
| 9177 | } |
| 9178 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9179 | |
| 9180 | /** |
| 9181 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9182 | * |
| 9183 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9184 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9185 | * before being read. |
| 9186 | */ |
| 9187 | @Override |
| 9188 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9189 | isCompressed) { |
| 9190 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9191 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9192 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9193 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9194 | } |
| 9195 | if (!isImsAvailableOnDevice()) { |
| 9196 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9197 | "IMS not available on device."); |
| 9198 | } |
| 9199 | |
| 9200 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9201 | try { |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9202 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9203 | } finally { |
| 9204 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9205 | } |
| 9206 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9207 | |
| 9208 | @Override |
| 9209 | public boolean isIccLockEnabled(int subId) { |
| 9210 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9211 | |
| 9212 | // Now that all security checks passes, perform the operation as ourselves. |
| 9213 | final long identity = Binder.clearCallingIdentity(); |
| 9214 | try { |
| 9215 | Phone phone = getPhone(subId); |
| 9216 | if (phone != null && phone.getIccCard() != null) { |
| 9217 | return phone.getIccCard().getIccLockEnabled(); |
| 9218 | } else { |
| 9219 | return false; |
| 9220 | } |
| 9221 | } finally { |
| 9222 | Binder.restoreCallingIdentity(identity); |
| 9223 | } |
| 9224 | } |
| 9225 | |
| 9226 | /** |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9227 | * Set the ICC pin lock enabled or disabled. |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9228 | * |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9229 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9230 | * three cases: |
| 9231 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9232 | * successfully. |
| 9233 | * - Positive number and zero for remaining password attempts. |
| 9234 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9235 | * |
| 9236 | */ |
| 9237 | @Override |
| 9238 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9239 | enforceModifyPermission(); |
| 9240 | |
| 9241 | Phone phone = getPhone(subId); |
| 9242 | if (phone == null) { |
| 9243 | return 0; |
| 9244 | } |
| 9245 | // Now that all security checks passes, perform the operation as ourselves. |
| 9246 | final long identity = Binder.clearCallingIdentity(); |
| 9247 | try { |
| 9248 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9249 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9250 | return attemptsRemaining; |
| 9251 | |
| 9252 | } catch (Exception e) { |
| 9253 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9254 | } finally { |
| 9255 | Binder.restoreCallingIdentity(identity); |
| 9256 | } |
| 9257 | return 0; |
| 9258 | } |
| 9259 | |
| 9260 | /** |
| 9261 | * Change the ICC password used in ICC pin lock. |
| 9262 | * |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9263 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9264 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9265 | * - Positive number and zero for remaining password attempts. |
| 9266 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9267 | * |
| 9268 | */ |
| 9269 | @Override |
| 9270 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9271 | enforceModifyPermission(); |
| 9272 | |
| 9273 | Phone phone = getPhone(subId); |
| 9274 | if (phone == null) { |
| 9275 | return 0; |
| 9276 | } |
| 9277 | // Now that all security checks passes, perform the operation as ourselves. |
| 9278 | final long identity = Binder.clearCallingIdentity(); |
| 9279 | try { |
| 9280 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9281 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9282 | return attemptsRemaining; |
| 9283 | |
| 9284 | } catch (Exception e) { |
| 9285 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9286 | } finally { |
| 9287 | Binder.restoreCallingIdentity(identity); |
| 9288 | } |
| 9289 | return 0; |
| 9290 | } |
Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9291 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9292 | /** |
| 9293 | * Request for receiving user activity notification |
| 9294 | */ |
| 9295 | @Override |
| 9296 | public void requestUserActivityNotification() { |
| 9297 | if (!mNotifyUserActivity.get() |
| 9298 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9299 | mNotifyUserActivity.set(true); |
| 9300 | } |
| 9301 | } |
| 9302 | |
| 9303 | /** |
| 9304 | * Called when userActivity is signalled in the power manager. |
| 9305 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9306 | */ |
| 9307 | @Override |
| 9308 | public void userActivity() { |
| 9309 | // *************************************** |
| 9310 | // * Inherited from PhoneWindowManager * |
| 9311 | // *************************************** |
| 9312 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9313 | // WITH ITS LOCKS HELD. |
| 9314 | // |
| 9315 | // This code must be VERY careful about the locks |
| 9316 | // it acquires. |
| 9317 | // In fact, the current code acquires way too many, |
| 9318 | // and probably has lurking deadlocks. |
| 9319 | |
| 9320 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9321 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9322 | } |
| 9323 | |
| 9324 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9325 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9326 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9327 | } |
| 9328 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9329 | |
Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9330 | @Override |
| 9331 | public boolean canConnectTo5GInDsdsMode() { |
| 9332 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9333 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9334 | |
| 9335 | @Override |
| 9336 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 9337 | String callingFeatureId) { |
| 9338 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 9339 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 9340 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9341 | } |
| 9342 | |
| 9343 | Phone phone = getPhone(subId); |
| 9344 | if (phone == null) { |
| 9345 | throw new RuntimeException("phone is not available"); |
| 9346 | } |
| 9347 | // Now that all security checks passes, perform the operation as ourselves. |
| 9348 | final long identity = Binder.clearCallingIdentity(); |
| 9349 | try { |
| 9350 | return phone.getEquivalentHomePlmns(); |
| 9351 | } finally { |
| 9352 | Binder.restoreCallingIdentity(identity); |
| 9353 | } |
| 9354 | } |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9355 | |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9356 | @Override |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9357 | public boolean isRadioInterfaceCapabilitySupported( |
| 9358 | @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
Daniel Bright | 0176b32 | 2021-02-24 21:03:28 +0000 | [diff] [blame] | 9359 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | fe1e6ac | 2021-03-12 10:25:03 -0800 | [diff] [blame] | 9360 | mRadioInterfaceCapabilities.getCapabilities(); |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9361 | if (radioInterfaceCapabilities == null) { |
| 9362 | throw new RuntimeException("radio interface capabilities are not available"); |
| 9363 | } else { |
Daniel Bright | 0176b32 | 2021-02-24 21:03:28 +0000 | [diff] [blame] | 9364 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9365 | } |
| 9366 | } |
| 9367 | |
| 9368 | @Override |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9369 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 9370 | UaSecurityProtocolIdentifier securityProtocol, |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9371 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) { |
| 9372 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9373 | Binder.getCallingUid(), "bootstrapAuthenticationRequest", |
| 9374 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9375 | Manifest.permission.MODIFY_PHONE_STATE); |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9376 | if (DBG) { |
| 9377 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 9378 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 9379 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 9380 | } |
| 9381 | |
| 9382 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 9383 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 9384 | || appType > TelephonyManager.APPTYPE_ISIM |
| 9385 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 9386 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 9387 | if (callback != null) { |
| 9388 | try { |
| 9389 | callback.onAuthenticationFailure( |
| 9390 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 9391 | } catch (RemoteException exception) { |
| 9392 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 9393 | } |
| 9394 | return; |
| 9395 | } |
| 9396 | } |
| 9397 | |
| 9398 | final long token = Binder.clearCallingIdentity(); |
| 9399 | try { |
| 9400 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 9401 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 9402 | forceBootStrapping, callback)); |
| 9403 | } finally { |
| 9404 | Binder.restoreCallingIdentity(token); |
| 9405 | } |
| 9406 | } |
| 9407 | |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9408 | /** |
| 9409 | * Attempts to set the radio power state for thermal reason. This does not guarantee that the |
| 9410 | * requested radio power state will actually be set. See {@link |
| 9411 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 9412 | * |
| 9413 | * @param subId the subscription ID of the phone requesting to set the radio power state. |
| 9414 | * @param enable {@code true} if trying to turn radio on. |
| 9415 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 9416 | * false}. |
| 9417 | */ |
| 9418 | private boolean setRadioPowerForThermal(int subId, boolean enable) { |
| 9419 | Phone phone = getPhone(subId); |
| 9420 | if (phone != null) { |
| 9421 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 9422 | return true; |
| 9423 | } |
| 9424 | return false; |
| 9425 | } |
| 9426 | |
| 9427 | private int handleDataThrottlingRequest(int subId, |
| 9428 | DataThrottlingRequest dataThrottlingRequest) { |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 9429 | boolean isDataThrottlingSupported = isRadioInterfaceCapabilitySupported( |
| 9430 | TelephonyManager.CAPABILITY_THERMAL_MITIGATION_DATA_THROTTLING); |
| 9431 | if (!isDataThrottlingSupported && dataThrottlingRequest.getDataThrottlingAction() |
| 9432 | != DataThrottlingRequest.DATA_THROTTLING_ACTION_NO_DATA_THROTTLING) { |
| 9433 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 9434 | } |
| 9435 | |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9436 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 9437 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9438 | if (!setRadioPowerForThermal(subId, true)) { |
| 9439 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9440 | } |
| 9441 | |
| 9442 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 9443 | |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 9444 | if (isDataThrottlingSupported) { |
| 9445 | int thermalMitigationResult = |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9446 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 9447 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 9448 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 9449 | } else if (thermalMitigationResult |
| 9450 | == MODEM_DOES_NOT_SUPPORT_DATA_THROTTLING_ERROR_CODE) { |
| 9451 | throw new IllegalArgumentException("modem does not support data throttling"); |
| 9452 | } |
| 9453 | return thermalMitigationResult; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9454 | } |
Jack Nudelman | 5d6a98b | 2021-03-04 14:26:25 -0800 | [diff] [blame] | 9455 | |
| 9456 | return TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9457 | } |
| 9458 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 9459 | private static List<String> getThermalMitigationAllowlist(Context context) { |
| 9460 | if (sThermalMitigationAllowlistedPackages.isEmpty()) { |
| 9461 | for (String pckg : context.getResources() |
| 9462 | .getStringArray(R.array.thermal_mitigation_allowlisted_packages)) { |
| 9463 | sThermalMitigationAllowlistedPackages.add(pckg); |
| 9464 | } |
| 9465 | } |
| 9466 | |
| 9467 | return sThermalMitigationAllowlistedPackages; |
| 9468 | } |
| 9469 | |
| 9470 | /** |
| 9471 | * Used by shell commands to add an authorized package name for thermal mitigation. |
| 9472 | * @param packageName name of package to be allowlisted |
| 9473 | * @param context |
| 9474 | */ |
| 9475 | static void addPackageToThermalMitigationAllowlist(String packageName, Context context) { |
| 9476 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 9477 | sThermalMitigationAllowlistedPackages.add(packageName); |
| 9478 | } |
| 9479 | |
| 9480 | /** |
| 9481 | * Used by shell commands to remove an authorized package name for thermal mitigation. |
| 9482 | * @param packageName name of package to remove from allowlist |
| 9483 | * @param context |
| 9484 | */ |
| 9485 | static void removePackageFromThermalMitigationAllowlist(String packageName, Context context) { |
| 9486 | sThermalMitigationAllowlistedPackages = getThermalMitigationAllowlist(context); |
| 9487 | sThermalMitigationAllowlistedPackages.remove(packageName); |
| 9488 | } |
| 9489 | |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9490 | /** |
| 9491 | * Thermal mitigation request to control functionalities at modem. |
| 9492 | * |
| 9493 | * @param subId the id of the subscription. |
| 9494 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 9495 | * @param callingPackage the package name of the calling package. |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9496 | * |
| 9497 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 9498 | */ |
| 9499 | @Override |
| 9500 | @ThermalMitigationResult |
| 9501 | public int sendThermalMitigationRequest( |
| 9502 | int subId, |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 9503 | ThermalMitigationRequest thermalMitigationRequest, |
| 9504 | String callingPackage) throws IllegalArgumentException { |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9505 | enforceModifyPermission(); |
| 9506 | |
Jack Nudelman | 644b91a | 2021-03-12 14:09:48 -0800 | [diff] [blame] | 9507 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 9508 | if (!getThermalMitigationAllowlist(getDefaultPhone().getContext()) |
| 9509 | .contains(callingPackage)) { |
| 9510 | throw new SecurityException("Calling package must be configured in the device config. " |
| 9511 | + "calling package: " + callingPackage); |
| 9512 | } |
| 9513 | |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9514 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9515 | final long identity = Binder.clearCallingIdentity(); |
| 9516 | |
| 9517 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 9518 | try { |
| 9519 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 9520 | switch (thermalMitigationAction) { |
| 9521 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 9522 | thermalMitigationResult = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9523 | handleDataThrottlingRequest(subId, |
| 9524 | thermalMitigationRequest.getDataThrottlingRequest()); |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9525 | break; |
| 9526 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 9527 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9528 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 9529 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 9530 | } |
| 9531 | |
| 9532 | // Ensure that radio is on. If not able to power on due to phone being |
| 9533 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9534 | if (!setRadioPowerForThermal(subId, true)) { |
| 9535 | thermalMitigationResult = |
| 9536 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9537 | break; |
| 9538 | } |
| 9539 | |
| 9540 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 9541 | false); |
| 9542 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9543 | break; |
| 9544 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 9545 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9546 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 9547 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 9548 | } |
| 9549 | |
| 9550 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 9551 | if (registry != null) { |
| 9552 | TelephonyConnectionService service = |
| 9553 | registry.getTelephonyConnectionService(); |
| 9554 | Phone phone = getPhone(subId); |
| 9555 | if (phone == null) { |
| 9556 | thermalMitigationResult = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9557 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9558 | break; |
| 9559 | } |
| 9560 | |
| 9561 | if (PhoneConstantConversions.convertCallState(phone.getState()) |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9562 | != TelephonyManager.CALL_STATE_IDLE |
| 9563 | || phone.isInEmergencySmsMode() || phone.isInEcm() |
| 9564 | || (service != null && service.isEmergencyCallPending())) { |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9565 | String errorMessage = "Phone state is not valid. call state = " |
| 9566 | + PhoneConstantConversions.convertCallState(phone.getState()) |
| 9567 | + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode() |
| 9568 | + " isInEmergencyCallbackMode = " + phone.isInEcm(); |
| 9569 | errorMessage += service == null |
| 9570 | ? " TelephonyConnectionService is null" |
| 9571 | : " isEmergencyCallPending = " |
| 9572 | + service.isEmergencyCallPending(); |
| 9573 | Log.e(LOG_TAG, errorMessage); |
| 9574 | thermalMitigationResult = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9575 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9576 | break; |
| 9577 | } |
| 9578 | } else { |
| 9579 | thermalMitigationResult = |
| 9580 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9581 | break; |
| 9582 | } |
| 9583 | |
| 9584 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 9585 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9586 | if (!setRadioPowerForThermal(subId, false)) { |
| 9587 | thermalMitigationResult = |
| 9588 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9589 | break; |
| 9590 | } |
| 9591 | thermalMitigationResult = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9592 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9593 | break; |
| 9594 | default: |
| 9595 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 9596 | + "not exist. Requested action: " + thermalMitigationAction); |
| 9597 | } |
| 9598 | } catch (IllegalArgumentException e) { |
| 9599 | throw e; |
| 9600 | } catch (Exception e) { |
| 9601 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 9602 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 9603 | } finally { |
| 9604 | Binder.restoreCallingIdentity(identity); |
| 9605 | } |
| 9606 | |
| 9607 | if (DBG) { |
| 9608 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 9609 | + thermalMitigationResult); |
| 9610 | } |
| 9611 | |
| 9612 | return thermalMitigationResult; |
| 9613 | } |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9614 | |
| 9615 | /** |
| 9616 | * Set the GbaService Package Name that Telephony will bind to. |
| 9617 | * |
| 9618 | * @param subId The sim that the GbaService is associated with. |
| 9619 | * @param packageName The name of the package to be replaced with. |
| 9620 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9621 | */ |
| 9622 | @Override |
| 9623 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 9624 | enforceModifyPermission(); |
| 9625 | |
| 9626 | final long identity = Binder.clearCallingIdentity(); |
| 9627 | try { |
| 9628 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 9629 | } finally { |
| 9630 | Binder.restoreCallingIdentity(identity); |
| 9631 | } |
| 9632 | } |
| 9633 | |
| 9634 | /** |
| 9635 | * Return the package name of the currently bound GbaService. |
| 9636 | * |
| 9637 | * @param subId The sim that the GbaService is associated with. |
| 9638 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 9639 | */ |
| 9640 | @Override |
| 9641 | public String getBoundGbaService(int subId) { |
| 9642 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 9643 | |
| 9644 | final long identity = Binder.clearCallingIdentity(); |
| 9645 | try { |
| 9646 | return getGbaManager(subId).getServicePackage(); |
| 9647 | } finally { |
| 9648 | Binder.restoreCallingIdentity(identity); |
| 9649 | } |
| 9650 | } |
| 9651 | |
| 9652 | /** |
| 9653 | * Set the release time for telephony to unbind GbaService. |
| 9654 | * |
| 9655 | * @param subId The sim that the GbaService is associated with. |
| 9656 | * @param interval The release time to unbind GbaService by millisecond. |
| 9657 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9658 | */ |
| 9659 | @Override |
| 9660 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 9661 | enforceModifyPermission(); |
| 9662 | |
| 9663 | final long identity = Binder.clearCallingIdentity(); |
| 9664 | try { |
| 9665 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 9666 | } finally { |
| 9667 | Binder.restoreCallingIdentity(identity); |
| 9668 | } |
| 9669 | } |
| 9670 | |
| 9671 | /** |
| 9672 | * Return the release time for telephony to unbind GbaService. |
| 9673 | * |
| 9674 | * @param subId The sim that the GbaService is associated with. |
| 9675 | * @return The release time to unbind GbaService by millisecond. |
| 9676 | */ |
| 9677 | @Override |
| 9678 | public int getGbaReleaseTime(int subId) { |
| 9679 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 9680 | |
| 9681 | final long identity = Binder.clearCallingIdentity(); |
| 9682 | try { |
| 9683 | return getGbaManager(subId).getReleaseTime(); |
| 9684 | } finally { |
| 9685 | Binder.restoreCallingIdentity(identity); |
| 9686 | } |
| 9687 | } |
| 9688 | |
| 9689 | private GbaManager getGbaManager(int subId) { |
| 9690 | GbaManager instance = GbaManager.getInstance(subId); |
| 9691 | if (instance == null) { |
| 9692 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 9693 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 9694 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 9695 | } |
| 9696 | return instance; |
| 9697 | } |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9698 | |
| 9699 | /** |
| 9700 | * indicate whether the device and the carrier can support |
| 9701 | * RCS VoLTE single registration. |
| 9702 | */ |
| 9703 | @Override |
| 9704 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9705 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
| 9706 | Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable", |
| 9707 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9708 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9709 | |
| 9710 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9711 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9712 | } |
| 9713 | |
| 9714 | final long identity = Binder.clearCallingIdentity(); |
| 9715 | try { |
| 9716 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 9717 | if (rpm != null) { |
| 9718 | return rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 9719 | } |
| 9720 | return false; |
| 9721 | } finally { |
| 9722 | Binder.restoreCallingIdentity(identity); |
| 9723 | } |
| 9724 | } |
| 9725 | |
| 9726 | /** |
| 9727 | * Register RCS provisioning callback. |
| 9728 | */ |
| 9729 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9730 | public void registerRcsProvisioningCallback(int subId, |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9731 | IRcsConfigCallback callback) { |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9732 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9733 | Binder.getCallingUid(), "registerRcsProvisioningCallback", |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9734 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9735 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9736 | |
| 9737 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9738 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9739 | } |
| 9740 | if (!isImsAvailableOnDevice()) { |
| 9741 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9742 | "IMS not available on device."); |
| 9743 | } |
| 9744 | |
| 9745 | final long identity = Binder.clearCallingIdentity(); |
| 9746 | try { |
Hui Wang | 713d45f | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9747 | if (!RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9748 | .registerRcsProvisioningCallback(subId, callback)) { |
Hui Wang | 713d45f | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9749 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9750 | "Service not available for the subscription."); |
| 9751 | } |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9752 | } finally { |
| 9753 | Binder.restoreCallingIdentity(identity); |
| 9754 | } |
| 9755 | } |
| 9756 | |
| 9757 | /** |
| 9758 | * Unregister RCS provisioning callback. |
| 9759 | */ |
| 9760 | @Override |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9761 | public void unregisterRcsProvisioningCallback(int subId, |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9762 | IRcsConfigCallback callback) { |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9763 | TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId, |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9764 | Binder.getCallingUid(), "unregisterRcsProvisioningCallback", |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9765 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION, |
| 9766 | permission.READ_PRIVILEGED_PHONE_STATE); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9767 | |
| 9768 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9769 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9770 | } |
| 9771 | if (!isImsAvailableOnDevice()) { |
| 9772 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9773 | "IMS not available on device."); |
| 9774 | } |
| 9775 | |
| 9776 | final long identity = Binder.clearCallingIdentity(); |
| 9777 | try { |
Hui Wang | 713d45f | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9778 | RcsProvisioningMonitor.getInstance() |
Hui Wang | 3cac7e5 | 2021-01-27 14:45:25 -0800 | [diff] [blame] | 9779 | .unregisterRcsProvisioningCallback(subId, callback); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9780 | } finally { |
| 9781 | Binder.restoreCallingIdentity(identity); |
| 9782 | } |
| 9783 | } |
| 9784 | |
| 9785 | /** |
| 9786 | * trigger RCS reconfiguration. |
| 9787 | */ |
| 9788 | public void triggerRcsReconfiguration(int subId) { |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9789 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 9790 | "triggerRcsReconfiguration", |
| 9791 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9792 | |
| 9793 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9794 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9795 | } |
| 9796 | if (!isImsAvailableOnDevice()) { |
| 9797 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9798 | "IMS not available on device."); |
| 9799 | } |
| 9800 | |
| 9801 | final long identity = Binder.clearCallingIdentity(); |
| 9802 | try { |
| 9803 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 9804 | } finally { |
| 9805 | Binder.restoreCallingIdentity(identity); |
| 9806 | } |
| 9807 | } |
| 9808 | |
| 9809 | /** |
| 9810 | * Provide the client configuration parameters of the RCS application. |
| 9811 | */ |
| 9812 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
Brad Ebinger | 4df7e24 | 2021-02-17 23:23:21 +0000 | [diff] [blame] | 9813 | TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(), |
| 9814 | "setRcsClientConfiguration", |
| 9815 | Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9816 | |
| 9817 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9818 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9819 | } |
| 9820 | if (!isImsAvailableOnDevice()) { |
| 9821 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9822 | "IMS not available on device."); |
| 9823 | } |
| 9824 | |
| 9825 | final long identity = Binder.clearCallingIdentity(); |
| 9826 | |
| 9827 | try { |
| 9828 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 9829 | if (configBinder == null) { |
| 9830 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
| 9831 | } else { |
| 9832 | configBinder.setRcsClientConfiguration(rcc); |
| 9833 | } |
| 9834 | } catch (RemoteException e) { |
| 9835 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
| 9836 | } finally { |
| 9837 | Binder.restoreCallingIdentity(identity); |
| 9838 | } |
| 9839 | } |
| 9840 | |
| 9841 | /** |
Hui Wang | 19a2187 | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 9842 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 9843 | */ |
| 9844 | @Override |
| 9845 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 9846 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9847 | "setRcsSingleRegistrationTestModeEnabled"); |
| 9848 | |
| 9849 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 9850 | } |
| 9851 | |
| 9852 | /** |
| 9853 | * Gets the test mode for RCS VoLTE single registration. |
| 9854 | */ |
| 9855 | @Override |
| 9856 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 9857 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9858 | "getRcsSingleRegistrationTestModeEnabled"); |
| 9859 | |
| 9860 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 9861 | } |
| 9862 | |
| 9863 | /** |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9864 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 9865 | */ |
| 9866 | @Override |
| 9867 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 9868 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9869 | "setDeviceSingleRegistrationEnabledOverride"); |
| 9870 | enforceModifyPermission(); |
| 9871 | |
| 9872 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9873 | : Boolean.parseBoolean(enabledStr); |
| 9874 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 9875 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9876 | } |
| 9877 | |
| 9878 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 9879 | * Sends a device to device communication message. Only usable via shell. |
| 9880 | * @param message message to send. |
| 9881 | * @param value message value. |
| 9882 | */ |
| 9883 | @Override |
| 9884 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 9885 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9886 | "setCarrierSingleRegistrationEnabledOverride"); |
| 9887 | enforceModifyPermission(); |
| 9888 | |
| 9889 | final long identity = Binder.clearCallingIdentity(); |
| 9890 | try { |
| 9891 | TelephonyConnectionService service = |
| 9892 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 9893 | if (service == null) { |
| 9894 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 9895 | return; |
| 9896 | } |
| 9897 | service.sendTestDeviceToDeviceMessage(message, value); |
| 9898 | } finally { |
| 9899 | Binder.restoreCallingIdentity(identity); |
| 9900 | } |
| 9901 | } |
| 9902 | |
| 9903 | |
| 9904 | /** |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9905 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 9906 | */ |
| 9907 | @Override |
| 9908 | public boolean getDeviceSingleRegistrationEnabled() { |
| 9909 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 9910 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 9911 | } |
| 9912 | |
| 9913 | /** |
| 9914 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 9915 | */ |
| 9916 | @Override |
| 9917 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 9918 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9919 | "setCarrierSingleRegistrationEnabledOverride"); |
| 9920 | enforceModifyPermission(); |
| 9921 | |
| 9922 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9923 | : Boolean.parseBoolean(enabledStr); |
| 9924 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 9925 | subId, enabled); |
| 9926 | } |
| 9927 | |
| 9928 | /** |
| 9929 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 9930 | */ |
| 9931 | @Override |
| 9932 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 9933 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 9934 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 9935 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 9936 | |
| 9937 | /** |
Hui Wang | eadb256 | 2021-02-26 09:33:38 -0800 | [diff] [blame] | 9938 | * Overrides the ims feature validation result |
| 9939 | */ |
| 9940 | @Override |
| 9941 | public boolean setImsFeatureValidationOverride(int subId, String enabledStr) { |
| 9942 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9943 | "setImsFeatureValidationOverride"); |
| 9944 | |
| 9945 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9946 | : Boolean.parseBoolean(enabledStr); |
| 9947 | return RcsProvisioningMonitor.getInstance().overrideImsFeatureValidation( |
| 9948 | subId, enabled); |
| 9949 | } |
| 9950 | |
| 9951 | /** |
| 9952 | * Gets the ims feature validation override value |
| 9953 | */ |
| 9954 | @Override |
| 9955 | public boolean getImsFeatureValidationOverride(int subId) { |
| 9956 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9957 | "getImsFeatureValidationOverride"); |
| 9958 | return RcsProvisioningMonitor.getInstance().getImsFeatureValidationOverride(subId); |
| 9959 | } |
| 9960 | |
| 9961 | /** |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 9962 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 9963 | * their mobile plan. |
| 9964 | */ |
| 9965 | @Override |
| 9966 | public String getMobileProvisioningUrl() { |
| 9967 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 9968 | final long identity = Binder.clearCallingIdentity(); |
| 9969 | try { |
| 9970 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 9971 | } finally { |
| 9972 | Binder.restoreCallingIdentity(identity); |
| 9973 | } |
| 9974 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 9975 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 9976 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 9977 | * Get the EAB contact from the EAB database. |
| 9978 | */ |
| 9979 | @Override |
| 9980 | public String getContactFromEab(String contact) { |
| 9981 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 9982 | enforceModifyPermission(); |
| 9983 | final long identity = Binder.clearCallingIdentity(); |
| 9984 | try { |
| 9985 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 9986 | } finally { |
| 9987 | Binder.restoreCallingIdentity(identity); |
| 9988 | } |
| 9989 | } |
| 9990 | |
| 9991 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 9992 | * Remove the EAB contacts from the EAB database. |
| 9993 | */ |
| 9994 | @Override |
| 9995 | public int removeContactFromEab(int subId, String contacts) { |
| 9996 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 9997 | enforceModifyPermission(); |
| 9998 | final long identity = Binder.clearCallingIdentity(); |
| 9999 | try { |
| 10000 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 10001 | } finally { |
| 10002 | Binder.restoreCallingIdentity(identity); |
| 10003 | } |
| 10004 | } |
| 10005 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10006 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10007 | public boolean getDeviceUceEnabled() { |
| 10008 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 10009 | final long identity = Binder.clearCallingIdentity(); |
| 10010 | try { |
| 10011 | return mApp.getDeviceUceEnabled(); |
| 10012 | } finally { |
| 10013 | Binder.restoreCallingIdentity(identity); |
| 10014 | } |
| 10015 | } |
| 10016 | |
| 10017 | @Override |
| 10018 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 10019 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 10020 | final long identity = Binder.clearCallingIdentity(); |
| 10021 | try { |
| 10022 | mApp.setDeviceUceEnabled(isEnabled); |
| 10023 | } finally { |
| 10024 | Binder.restoreCallingIdentity(identity); |
| 10025 | } |
| 10026 | } |
| 10027 | |
Brad Ebinger | d4c5bde | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10028 | /** |
| 10029 | * Add new feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10030 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10031 | */ |
| 10032 | // Used for SHELL command only right now. |
| 10033 | @Override |
| 10034 | public RcsContactUceCapability addUceRegistrationOverrideShell(int subId, |
| 10035 | List<String> featureTags) { |
| 10036 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10037 | "addUceRegistrationOverrideShell"); |
| 10038 | final long identity = Binder.clearCallingIdentity(); |
| 10039 | try { |
| 10040 | return mApp.imsRcsController.addUceRegistrationOverrideShell(subId, |
| 10041 | new ArraySet<>(featureTags)); |
| 10042 | } catch (ImsException e) { |
| 10043 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10044 | } finally { |
| 10045 | Binder.restoreCallingIdentity(identity); |
| 10046 | } |
| 10047 | } |
| 10048 | |
| 10049 | /** |
| 10050 | * Remove existing feature tags to the Set used to calculate the capabilities in PUBLISH. |
| 10051 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10052 | */ |
| 10053 | // Used for SHELL command only right now. |
| 10054 | @Override |
| 10055 | public RcsContactUceCapability removeUceRegistrationOverrideShell(int subId, |
| 10056 | List<String> featureTags) { |
| 10057 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10058 | "removeUceRegistrationOverrideShell"); |
| 10059 | final long identity = Binder.clearCallingIdentity(); |
| 10060 | try { |
| 10061 | return mApp.imsRcsController.removeUceRegistrationOverrideShell(subId, |
| 10062 | new ArraySet<>(featureTags)); |
| 10063 | } catch (ImsException e) { |
| 10064 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10065 | } finally { |
| 10066 | Binder.restoreCallingIdentity(identity); |
| 10067 | } |
| 10068 | } |
| 10069 | |
| 10070 | /** |
| 10071 | * Clear all overrides in the Set used to calculate the capabilities in PUBLISH. |
| 10072 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10073 | */ |
| 10074 | // Used for SHELL command only right now. |
| 10075 | @Override |
| 10076 | public RcsContactUceCapability clearUceRegistrationOverrideShell(int subId) { |
| 10077 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10078 | "clearUceRegistrationOverrideShell"); |
| 10079 | final long identity = Binder.clearCallingIdentity(); |
| 10080 | try { |
| 10081 | return mApp.imsRcsController.clearUceRegistrationOverrideShell(subId); |
| 10082 | } catch (ImsException e) { |
| 10083 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10084 | } finally { |
| 10085 | Binder.restoreCallingIdentity(identity); |
| 10086 | } |
| 10087 | } |
| 10088 | |
| 10089 | /** |
| 10090 | * @return current RcsContactUceCapability instance that will be used for PUBLISH. |
| 10091 | */ |
| 10092 | // Used for SHELL command only right now. |
| 10093 | @Override |
| 10094 | public RcsContactUceCapability getLatestRcsContactUceCapabilityShell(int subId) { |
| 10095 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 10096 | "getLatestRcsContactUceCapabilityShell"); |
| 10097 | final long identity = Binder.clearCallingIdentity(); |
| 10098 | try { |
| 10099 | return mApp.imsRcsController.getLatestRcsContactUceCapabilityShell(subId); |
| 10100 | } catch (ImsException e) { |
| 10101 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10102 | } finally { |
| 10103 | Binder.restoreCallingIdentity(identity); |
| 10104 | } |
| 10105 | } |
| 10106 | |
| 10107 | /** |
| 10108 | * Returns the last PIDF XML sent to the network during the last PUBLISH or "none" if the |
| 10109 | * device does not have an active PUBLISH. |
| 10110 | */ |
| 10111 | // Used for SHELL command only right now. |
| 10112 | @Override |
| 10113 | public String getLastUcePidfXmlShell(int subId) { |
| 10114 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceGetLastPidfXml"); |
| 10115 | final long identity = Binder.clearCallingIdentity(); |
| 10116 | try { |
| 10117 | return mApp.imsRcsController.getLastUcePidfXmlShell(subId); |
| 10118 | } catch (ImsException e) { |
| 10119 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10120 | } finally { |
| 10121 | Binder.restoreCallingIdentity(identity); |
| 10122 | } |
| 10123 | } |
| 10124 | |
James.cf Lin | e8713a4 | 2021-04-29 16:04:26 +0800 | [diff] [blame^] | 10125 | /** |
| 10126 | * Remove UCE requests cannot be sent to the network status. |
| 10127 | */ |
| 10128 | // Used for SHELL command only right now. |
| 10129 | @Override |
| 10130 | public boolean removeUceRequestDisallowedStatus(int subId) { |
| 10131 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "uceRemoveDisallowedStatus"); |
| 10132 | final long identity = Binder.clearCallingIdentity(); |
| 10133 | try { |
| 10134 | return mApp.imsRcsController.removeUceRequestDisallowedStatus(subId); |
| 10135 | } catch (ImsException e) { |
| 10136 | throw new ServiceSpecificException(e.getCode(), e.getMessage()); |
| 10137 | } finally { |
| 10138 | Binder.restoreCallingIdentity(identity); |
| 10139 | } |
| 10140 | } |
| 10141 | |
Brad Ebinger | d4c5bde | 2021-02-12 06:18:28 +0000 | [diff] [blame] | 10142 | |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 10143 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10144 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10145 | String callingPackage) { |
| 10146 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10147 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 10148 | |
| 10149 | final int callingUid = Binder.getCallingUid(); |
| 10150 | // Verify that tha callingPackage belongs to the calling UID |
| 10151 | mApp.getSystemService(AppOpsManager.class) |
| 10152 | .checkPackage(callingUid, callingPackage); |
| 10153 | |
| 10154 | validateSignalStrengthUpdateRequest(request, callingUid); |
| 10155 | |
| 10156 | final long identity = Binder.clearCallingIdentity(); |
| 10157 | try { |
| 10158 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10159 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10160 | |
| 10161 | if (result instanceof IllegalStateException) { |
| 10162 | throw (IllegalStateException) result; |
| 10163 | } |
| 10164 | } finally { |
| 10165 | Binder.restoreCallingIdentity(identity); |
| 10166 | } |
| 10167 | } |
| 10168 | |
| 10169 | @Override |
| 10170 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10171 | String callingPackage) { |
| 10172 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10173 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 10174 | |
| 10175 | final int callingUid = Binder.getCallingUid(); |
| 10176 | // Verify that tha callingPackage belongs to the calling UID |
| 10177 | mApp.getSystemService(AppOpsManager.class) |
| 10178 | .checkPackage(callingUid, callingPackage); |
| 10179 | |
| 10180 | final long identity = Binder.clearCallingIdentity(); |
| 10181 | try { |
| 10182 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10183 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10184 | |
| 10185 | if (result instanceof IllegalStateException) { |
| 10186 | throw (IllegalStateException) result; |
| 10187 | } |
| 10188 | } finally { |
| 10189 | Binder.restoreCallingIdentity(identity); |
| 10190 | } |
| 10191 | } |
| 10192 | |
| 10193 | private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request, |
| 10194 | int callingUid) { |
| 10195 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 10196 | // phone/system process do not have further restriction on request |
| 10197 | return; |
| 10198 | } |
| 10199 | |
| 10200 | // Applications has restrictions on how to use the request: |
| 10201 | // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle |
| 10202 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
| 10203 | // This is not system caller which has been checked above |
| 10204 | throw new IllegalArgumentException( |
| 10205 | "Only system can set isSystemThresholdReportingRequestedWhileIdle"); |
| 10206 | } |
| 10207 | |
| 10208 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 10209 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 10210 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 10211 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 10212 | || info.isEnabled()) { |
| 10213 | throw new IllegalArgumentException( |
| 10214 | "Only system can set hide fields in SignalThresholdInfo"); |
| 10215 | } |
| 10216 | |
| 10217 | // Thresholds length for each RAN need in range. This has been validated in |
| 10218 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 10219 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 10220 | final int[] thresholds = info.getThresholds(); |
| 10221 | Objects.requireNonNull(thresholds); |
| 10222 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 10223 | || thresholds.length |
| 10224 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 10225 | throw new IllegalArgumentException( |
| 10226 | "thresholds length is out of range: " + thresholds.length); |
| 10227 | } |
| 10228 | } |
| 10229 | } |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 10230 | |
| 10231 | /** |
| 10232 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 10233 | * required to be done shortly after the API is invoked. |
| 10234 | */ |
| 10235 | @Override |
| 10236 | @TelephonyManager.PrepareUnattendedRebootResult |
| 10237 | public int prepareForUnattendedReboot() { |
| 10238 | enforceRebootPermission(); |
| 10239 | |
| 10240 | final long identity = Binder.clearCallingIdentity(); |
| 10241 | try { |
| 10242 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null); |
| 10243 | } finally { |
| 10244 | Binder.restoreCallingIdentity(identity); |
| 10245 | } |
| 10246 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 10247 | } |