Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.phone; |
| 18 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
| 20 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 21 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 22 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
| 23 | |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 24 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 25 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 26 | import android.annotation.Nullable; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 27 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 28 | import android.app.PendingIntent; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 29 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 30 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 31 | import android.content.Context; |
| 32 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 33 | import android.content.SharedPreferences; |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 34 | import android.content.pm.ApplicationInfo; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 35 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 36 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 37 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 38 | import android.net.Uri; |
| 39 | import android.os.AsyncResult; |
| 40 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 41 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 42 | import android.os.Bundle; |
| 43 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 44 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.os.Looper; |
| 46 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 47 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 48 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 49 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 50 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 51 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 52 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 53 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 54 | import android.os.ServiceSpecificException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 55 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 56 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 57 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 58 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 59 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 60 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 61 | import android.provider.Telephony; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 62 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 63 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 64 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 65 | import android.telecom.TelecomManager; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 66 | import android.telephony.Annotation.ApnType; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 67 | import android.telephony.CallForwardingInfo; |
Sooraj Sasindran | 4deb887 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 68 | import android.telephony.CarrierBandwidth; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 69 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 70 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 71 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 72 | import android.telephony.CellIdentityCdma; |
| 73 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 74 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 75 | import android.telephony.CellInfoGsm; |
| 76 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 77 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 78 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 79 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 80 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 81 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 82 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 83 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 84 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 85 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 86 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 87 | import android.telephony.RadioAccessSpecifier; |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame^] | 88 | import android.telephony.RadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 89 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 90 | import android.telephony.SignalStrength; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 91 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 92 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 93 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 94 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 95 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 96 | import android.telephony.TelephonyScanManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 97 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 98 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 99 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 100 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 101 | import android.telephony.data.ApnSetting; |
| 102 | import android.telephony.emergency.EmergencyNumber; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 103 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 104 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 105 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 106 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 107 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 108 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 109 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 110 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 111 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 112 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 113 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 114 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 115 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 116 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 117 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 118 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 119 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 120 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 121 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 122 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 123 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 124 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 127 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 128 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 130 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 131 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 132 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 133 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 134 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 137 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 139 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 145 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 155 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 156 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 158 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 160 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 162 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 163 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 166 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 168 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 170 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 172 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 173 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 174 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 175 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 176 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 177 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 178 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 179 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 180 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 181 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 182 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 183 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 184 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 185 | import java.io.FileDescriptor; |
| 186 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 187 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 188 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 189 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 190 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 191 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 192 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 193 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 194 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 195 | import java.util.Set; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 196 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 197 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 198 | |
| 199 | /** |
| 200 | * Implementation of the ITelephony interface. |
| 201 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 202 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 203 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 204 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 205 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 206 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 207 | |
| 208 | // Message codes used with mMainThreadHandler |
| 209 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 210 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 211 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 212 | private static final int CMD_OPEN_CHANNEL = 9; |
| 213 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 214 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 215 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 216 | private static final int CMD_NV_READ_ITEM = 13; |
| 217 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 218 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 219 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 220 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 221 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 222 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 223 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 224 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 225 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 226 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 227 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 228 | private static final int CMD_SEND_ENVELOPE = 25; |
| 229 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 230 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 231 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 232 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 233 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 234 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 235 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 236 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 237 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 238 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 239 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 240 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 241 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 242 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 243 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 244 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 245 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 246 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 247 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 248 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 249 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 250 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 251 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 252 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 253 | private static final int CMD_SWITCH_SLOTS = 50; |
| 254 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 255 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 256 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 257 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 258 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 259 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 260 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 261 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 262 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 263 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 264 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 265 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 266 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 267 | private static final int CMD_MODEM_REBOOT = 64; |
| 268 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 269 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 270 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 271 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 272 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 273 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 274 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 275 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 276 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 277 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 278 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 279 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 280 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 281 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 282 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 283 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 284 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 285 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 286 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 287 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 288 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 289 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 290 | private static final int CMD_GET_CALL_WAITING = 87; |
| 291 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 292 | private static final int CMD_SET_CALL_WAITING = 89; |
| 293 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 294 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 295 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 296 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 297 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 298 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 299 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 300 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 301 | // Parameters of select command. |
| 302 | private static final int SELECT_COMMAND = 0xA4; |
| 303 | private static final int SELECT_P1 = 0x04; |
| 304 | private static final int SELECT_P2 = 0; |
| 305 | private static final int SELECT_P3 = 0x10; |
| 306 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 307 | /** The singleton instance. */ |
| 308 | private static PhoneInterfaceManager sInstance; |
| 309 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 310 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 311 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 312 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 313 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 314 | private AppOpsManager mAppOps; |
| 315 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 316 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 317 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 318 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 319 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 320 | /** User Activity */ |
| 321 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 322 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 323 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 324 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 325 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 326 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 327 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 328 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 329 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 330 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 331 | // String to store multi SIM allowed |
| 332 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 333 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 334 | // The AID of ISD-R. |
| 335 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 336 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 337 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 338 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 339 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 340 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 341 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 342 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 343 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 344 | */ |
| 345 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 346 | "reset_network_erase_modem_config_enabled"; |
| 347 | |
| 348 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 349 | * A request object to use for transmitting data to an ICC. |
| 350 | */ |
| 351 | private static final class IccAPDUArgument { |
| 352 | public int channel, cla, command, p1, p2, p3; |
| 353 | public String data; |
| 354 | |
| 355 | public IccAPDUArgument(int channel, int cla, int command, |
| 356 | int p1, int p2, int p3, String data) { |
| 357 | this.channel = channel; |
| 358 | this.cla = cla; |
| 359 | this.command = command; |
| 360 | this.p1 = p1; |
| 361 | this.p2 = p2; |
| 362 | this.p3 = p3; |
| 363 | this.data = data; |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 368 | * A request object to use for transmitting data to an ICC. |
| 369 | */ |
| 370 | private static final class ManualNetworkSelectionArgument { |
| 371 | public OperatorInfo operatorInfo; |
| 372 | public boolean persistSelection; |
| 373 | |
| 374 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 375 | this.operatorInfo = operatorInfo; |
| 376 | this.persistSelection = persistSelection; |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 381 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 382 | * request after sending. The main thread will notify the request when it is complete. |
| 383 | */ |
| 384 | private static final class MainThreadRequest { |
| 385 | /** The argument to use for the request */ |
| 386 | public Object argument; |
| 387 | /** The result of the request that is run on the main thread */ |
| 388 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 389 | // The subscriber id that this request applies to. Defaults to |
| 390 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 391 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 392 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 393 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 394 | public Phone phone; |
| 395 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 396 | public WorkSource workSource; |
| 397 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 398 | public MainThreadRequest(Object argument) { |
| 399 | this.argument = argument; |
| 400 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 401 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 402 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 403 | this.argument = argument; |
| 404 | if (phone != null) { |
| 405 | this.phone = phone; |
| 406 | } |
| 407 | this.workSource = workSource; |
| 408 | } |
| 409 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 410 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 411 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 412 | if (subId != null) { |
| 413 | this.subId = subId; |
| 414 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 415 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 416 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 417 | } |
| 418 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 419 | private static final class IncomingThirdPartyCallArgs { |
| 420 | public final ComponentName component; |
| 421 | public final String callId; |
| 422 | public final String callerDisplayName; |
| 423 | |
| 424 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 425 | String callerDisplayName) { |
| 426 | this.component = component; |
| 427 | this.callId = callId; |
| 428 | this.callerDisplayName = callerDisplayName; |
| 429 | } |
| 430 | } |
| 431 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 432 | /** |
| 433 | * A handler that processes messages on the main thread in the phone process. Since many |
| 434 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 435 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 436 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 437 | * on, which will be notified when the operation completes and will contain the result of the |
| 438 | * request. |
| 439 | * |
| 440 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 441 | * note that request.result must be set to something non-null for the calling thread to |
| 442 | * unblock. |
| 443 | */ |
| 444 | private final class MainThreadHandler extends Handler { |
| 445 | @Override |
| 446 | public void handleMessage(Message msg) { |
| 447 | MainThreadRequest request; |
| 448 | Message onCompleted; |
| 449 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 450 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 451 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 452 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 453 | |
| 454 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 455 | case CMD_HANDLE_USSD_REQUEST: { |
| 456 | request = (MainThreadRequest) msg.obj; |
| 457 | final Phone phone = getPhoneFromRequest(request); |
| 458 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 459 | String ussdRequest = ussdObject.first; |
| 460 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 461 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 462 | if (!isUssdApiAllowed(request.subId)) { |
| 463 | // Carrier does not support use of this API, return failure. |
| 464 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 465 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 466 | Bundle returnData = new Bundle(); |
| 467 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 468 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 469 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 470 | request.result = true; |
| 471 | notifyRequester(request); |
| 472 | return; |
| 473 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 474 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 475 | try { |
| 476 | request.result = phone != null |
| 477 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 478 | } catch (CallStateException cse) { |
| 479 | request.result = false; |
| 480 | } |
| 481 | // Wake up the requesting thread |
| 482 | notifyRequester(request); |
| 483 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 484 | } |
| 485 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 486 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 487 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 488 | final Phone phone = getPhoneFromRequest(request); |
| 489 | request.result = phone != null ? |
| 490 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 491 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 492 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 493 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 494 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 495 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 496 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 497 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 498 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 499 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 500 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 501 | if (uiccCard == null) { |
| 502 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 503 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 504 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 505 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 506 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 507 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 508 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 509 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 510 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 511 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 512 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 513 | break; |
| 514 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 515 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 516 | ar = (AsyncResult) msg.obj; |
| 517 | request = (MainThreadRequest) ar.userObj; |
| 518 | if (ar.exception == null && ar.result != null) { |
| 519 | request.result = ar.result; |
| 520 | } else { |
| 521 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 522 | if (ar.result == null) { |
| 523 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 524 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 525 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 526 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 527 | } else { |
| 528 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 529 | } |
| 530 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 531 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 532 | break; |
| 533 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 534 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 535 | request = (MainThreadRequest) msg.obj; |
| 536 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 537 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 538 | if (uiccCard == null) { |
| 539 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 540 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 541 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 542 | } else { |
| 543 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 544 | request); |
| 545 | uiccCard.iccTransmitApduBasicChannel( |
| 546 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 547 | iccArgument.p3, iccArgument.data, onCompleted); |
| 548 | } |
| 549 | break; |
| 550 | |
| 551 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 552 | ar = (AsyncResult) msg.obj; |
| 553 | request = (MainThreadRequest) ar.userObj; |
| 554 | if (ar.exception == null && ar.result != null) { |
| 555 | request.result = ar.result; |
| 556 | } else { |
| 557 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 558 | if (ar.result == null) { |
| 559 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 560 | } else if (ar.exception instanceof CommandException) { |
| 561 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 562 | ar.exception); |
| 563 | } else { |
| 564 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 565 | } |
| 566 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 567 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 568 | break; |
| 569 | |
| 570 | case CMD_EXCHANGE_SIM_IO: |
| 571 | request = (MainThreadRequest) msg.obj; |
| 572 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 573 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 574 | if (uiccCard == null) { |
| 575 | loge("iccExchangeSimIO: No UICC"); |
| 576 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 577 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 578 | } else { |
| 579 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 580 | request); |
| 581 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 582 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 583 | iccArgument.data, onCompleted); |
| 584 | } |
| 585 | break; |
| 586 | |
| 587 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 588 | ar = (AsyncResult) msg.obj; |
| 589 | request = (MainThreadRequest) ar.userObj; |
| 590 | if (ar.exception == null && ar.result != null) { |
| 591 | request.result = ar.result; |
| 592 | } else { |
| 593 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 594 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 595 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 596 | break; |
| 597 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 598 | case CMD_SEND_ENVELOPE: |
| 599 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 600 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 601 | if (uiccCard == null) { |
| 602 | loge("sendEnvelopeWithStatus: No UICC"); |
| 603 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 604 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 605 | } else { |
| 606 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 607 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 608 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 609 | break; |
| 610 | |
| 611 | case EVENT_SEND_ENVELOPE_DONE: |
| 612 | ar = (AsyncResult) msg.obj; |
| 613 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 614 | if (ar.exception == null && ar.result != null) { |
| 615 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 616 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 617 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 618 | if (ar.result == null) { |
| 619 | loge("sendEnvelopeWithStatus: Empty response"); |
| 620 | } else if (ar.exception instanceof CommandException) { |
| 621 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 622 | ar.exception); |
| 623 | } else { |
| 624 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 625 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 626 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 627 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 628 | break; |
| 629 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 630 | case CMD_OPEN_CHANNEL: |
| 631 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 632 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 633 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 634 | if (uiccCard == null) { |
| 635 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 636 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 637 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 638 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 639 | } else { |
| 640 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 641 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 642 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 643 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 644 | break; |
| 645 | |
| 646 | case EVENT_OPEN_CHANNEL_DONE: |
| 647 | ar = (AsyncResult) msg.obj; |
| 648 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 649 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 650 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 651 | int[] result = (int[]) ar.result; |
| 652 | int channelId = result[0]; |
| 653 | byte[] selectResponse = null; |
| 654 | if (result.length > 1) { |
| 655 | selectResponse = new byte[result.length - 1]; |
| 656 | for (int i = 1; i < result.length; ++i) { |
| 657 | selectResponse[i - 1] = (byte) result[i]; |
| 658 | } |
| 659 | } |
| 660 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 661 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 662 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 663 | if (ar.result == null) { |
| 664 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 665 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 666 | if (ar.exception != null) { |
| 667 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 668 | } |
| 669 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 670 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 671 | if (ar.exception instanceof CommandException) { |
| 672 | CommandException.Error error = |
| 673 | ((CommandException) (ar.exception)).getCommandError(); |
| 674 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 675 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 676 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 677 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 678 | } |
| 679 | } |
| 680 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 681 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 682 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 683 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 684 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 685 | break; |
| 686 | |
| 687 | case CMD_CLOSE_CHANNEL: |
| 688 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 689 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 690 | if (uiccCard == null) { |
| 691 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 692 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 693 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 694 | } else { |
| 695 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 696 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 697 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 698 | break; |
| 699 | |
| 700 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 701 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 702 | break; |
| 703 | |
| 704 | case CMD_NV_READ_ITEM: |
| 705 | request = (MainThreadRequest) msg.obj; |
| 706 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 707 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 708 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 709 | break; |
| 710 | |
| 711 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 712 | ar = (AsyncResult) msg.obj; |
| 713 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 714 | if (ar.exception == null && ar.result != null) { |
| 715 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 716 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 717 | request.result = ""; |
| 718 | if (ar.result == null) { |
| 719 | loge("nvReadItem: Empty response"); |
| 720 | } else if (ar.exception instanceof CommandException) { |
| 721 | loge("nvReadItem: CommandException: " + |
| 722 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 723 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 724 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 725 | } |
| 726 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 727 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 728 | break; |
| 729 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 730 | case CMD_NV_WRITE_ITEM: |
| 731 | request = (MainThreadRequest) msg.obj; |
| 732 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 733 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 734 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 735 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 736 | break; |
| 737 | |
| 738 | case EVENT_NV_WRITE_ITEM_DONE: |
| 739 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 740 | break; |
| 741 | |
| 742 | case CMD_NV_WRITE_CDMA_PRL: |
| 743 | request = (MainThreadRequest) msg.obj; |
| 744 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 745 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 746 | break; |
| 747 | |
| 748 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 749 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 750 | break; |
| 751 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 752 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 753 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 754 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 755 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 756 | break; |
| 757 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 758 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 759 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 760 | break; |
| 761 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 762 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 763 | request = (MainThreadRequest) msg.obj; |
| 764 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 765 | request); |
| 766 | Phone phone = getPhoneFromRequest(request); |
| 767 | if (phone != null) { |
| 768 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 769 | } else { |
| 770 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 771 | request.result = false; |
| 772 | notifyRequester(request); |
| 773 | } |
| 774 | break; |
| 775 | } |
| 776 | |
| 777 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 778 | ar = (AsyncResult) msg.obj; |
| 779 | request = (MainThreadRequest) ar.userObj; |
| 780 | if (ar.exception == null && ar.result != null) { |
| 781 | request.result = ar.result; |
| 782 | } else { |
| 783 | // request.result must be set to something non-null |
| 784 | // for the calling thread to unblock |
| 785 | if (request.result != null) { |
| 786 | request.result = ar.result; |
| 787 | } else { |
| 788 | request.result = false; |
| 789 | } |
| 790 | if (ar.result == null) { |
| 791 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 792 | } else if (ar.exception instanceof CommandException) { |
| 793 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 794 | + ar.exception); |
| 795 | } else { |
| 796 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 797 | } |
| 798 | } |
| 799 | notifyRequester(request); |
| 800 | break; |
| 801 | |
| 802 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 803 | request = (MainThreadRequest) msg.obj; |
| 804 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 805 | Phone phone = getPhoneFromRequest(request); |
| 806 | if (phone != null) { |
| 807 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 808 | request.workSource); |
| 809 | } else { |
| 810 | loge("enableNrDualConnectivity: No phone object"); |
| 811 | request.result = |
| 812 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 813 | notifyRequester(request); |
| 814 | } |
| 815 | break; |
| 816 | } |
| 817 | |
| 818 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 819 | ar = (AsyncResult) msg.obj; |
| 820 | request = (MainThreadRequest) ar.userObj; |
| 821 | if (ar.exception == null) { |
| 822 | request.result = |
| 823 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 824 | } else { |
| 825 | request.result = |
| 826 | TelephonyManager |
| 827 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 828 | if (ar.exception instanceof CommandException) { |
| 829 | CommandException.Error error = |
| 830 | ((CommandException) (ar.exception)).getCommandError(); |
| 831 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 832 | request.result = |
| 833 | TelephonyManager |
| 834 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 835 | } |
| 836 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 837 | + ar.exception); |
| 838 | } else { |
| 839 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 840 | } |
| 841 | } |
| 842 | notifyRequester(request); |
| 843 | break; |
| 844 | } |
| 845 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 846 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 847 | request = (MainThreadRequest) msg.obj; |
| 848 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 849 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 850 | break; |
| 851 | |
| 852 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 853 | ar = (AsyncResult) msg.obj; |
| 854 | request = (MainThreadRequest) ar.userObj; |
| 855 | if (ar.exception == null && ar.result != null) { |
| 856 | request.result = ar.result; // Integer |
| 857 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 858 | // request.result must be set to something non-null |
| 859 | // for the calling thread to unblock |
| 860 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 861 | if (ar.result == null) { |
| 862 | loge("getPreferredNetworkType: Empty response"); |
| 863 | } else if (ar.exception instanceof CommandException) { |
| 864 | loge("getPreferredNetworkType: CommandException: " + |
| 865 | ar.exception); |
| 866 | } else { |
| 867 | loge("getPreferredNetworkType: Unknown exception"); |
| 868 | } |
| 869 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 870 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 871 | break; |
| 872 | |
| 873 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 874 | request = (MainThreadRequest) msg.obj; |
| 875 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 876 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 877 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 878 | break; |
| 879 | |
| 880 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 881 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 882 | break; |
| 883 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 884 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 885 | request = (MainThreadRequest)msg.obj; |
| 886 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 887 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 888 | break; |
| 889 | |
| 890 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 891 | ar = (AsyncResult)msg.obj; |
| 892 | request = (MainThreadRequest)ar.userObj; |
| 893 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 894 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 895 | break; |
| 896 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 897 | case CMD_SET_VOICEMAIL_NUMBER: |
| 898 | request = (MainThreadRequest) msg.obj; |
| 899 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 900 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 901 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 902 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 903 | break; |
| 904 | |
| 905 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 906 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 907 | break; |
| 908 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 909 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 910 | request = (MainThreadRequest) msg.obj; |
| 911 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 912 | request); |
| 913 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 914 | break; |
| 915 | |
| 916 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 917 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 918 | break; |
| 919 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 920 | case CMD_PERFORM_NETWORK_SCAN: |
| 921 | request = (MainThreadRequest) msg.obj; |
| 922 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 923 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 924 | break; |
| 925 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 926 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 927 | request = (MainThreadRequest) msg.obj; |
| 928 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 929 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 930 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 931 | request.argument; |
| 932 | int callForwardingReason = args.first; |
| 933 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 934 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 935 | } |
| 936 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 937 | ar = (AsyncResult) msg.obj; |
| 938 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 939 | TelephonyManager.CallForwardingInfoCallback callback = |
| 940 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 941 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 942 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 943 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 944 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 945 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 946 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 947 | // any service for voice call. |
| 948 | if ((callForwardInfo.serviceClass |
| 949 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 950 | callForwardingInfo = new CallForwardingInfo(true, |
| 951 | callForwardInfo.reason, |
| 952 | callForwardInfo.number, |
| 953 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 954 | break; |
| 955 | } |
| 956 | } |
| 957 | // Didn't find a call forward info for voice call. |
| 958 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 959 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 960 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 961 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 962 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 963 | } else { |
| 964 | if (ar.result == null) { |
| 965 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 966 | } |
| 967 | if (ar.exception != null) { |
| 968 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 969 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 970 | int errorCode = TelephonyManager |
| 971 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 972 | if (ar.exception instanceof CommandException) { |
| 973 | CommandException.Error error = |
| 974 | ((CommandException) (ar.exception)).getCommandError(); |
| 975 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 976 | errorCode = TelephonyManager |
| 977 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 978 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 979 | errorCode = TelephonyManager |
| 980 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 981 | } |
| 982 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 983 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 984 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 985 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 986 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 987 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 988 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 989 | request = (MainThreadRequest) msg.obj; |
| 990 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 991 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 992 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 993 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 994 | request.argument).first; |
| 995 | request.phone.setCallForwardingOption( |
| 996 | callForwardingInfoToSet.isEnabled() |
| 997 | ? CommandsInterface.CF_ACTION_ENABLE |
| 998 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 999 | callForwardingInfoToSet.getReason(), |
| 1000 | callForwardingInfoToSet.getNumber(), |
| 1001 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1002 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1003 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1004 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1005 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1006 | ar = (AsyncResult) msg.obj; |
| 1007 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1008 | Consumer<Integer> callback = |
| 1009 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1010 | request.argument).second; |
| 1011 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1012 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1013 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1014 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1015 | if (ar.exception instanceof CommandException) { |
| 1016 | CommandException.Error error = |
| 1017 | ((CommandException) (ar.exception)).getCommandError(); |
| 1018 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1019 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1020 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1021 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1022 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1023 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1024 | } |
| 1025 | } |
| 1026 | callback.accept(errorCode); |
| 1027 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1028 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1029 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1030 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1031 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1032 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1033 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1034 | request = (MainThreadRequest) msg.obj; |
| 1035 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1036 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1037 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1038 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1039 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1040 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1041 | ar = (AsyncResult) msg.obj; |
| 1042 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1043 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1044 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1045 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1046 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1047 | // Service Class is a bit mask per 3gpp 27.007. |
| 1048 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1049 | if (callForwardResults.length > 1 |
| 1050 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1051 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1052 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1053 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1054 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1055 | } else { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1056 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1057 | } |
| 1058 | } else { |
| 1059 | if (ar.result == null) { |
| 1060 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1061 | } |
| 1062 | if (ar.exception != null) { |
| 1063 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1064 | } |
| 1065 | if (ar.exception instanceof CommandException) { |
| 1066 | CommandException.Error error = |
| 1067 | ((CommandException) (ar.exception)).getCommandError(); |
| 1068 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1069 | callForwardingStatus = |
| 1070 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1071 | } |
| 1072 | } |
| 1073 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1074 | callback.accept(callForwardingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1075 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1076 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1077 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1078 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1079 | request = (MainThreadRequest) msg.obj; |
| 1080 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1081 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1082 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1083 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1084 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1085 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1086 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1087 | ar = (AsyncResult) msg.obj; |
| 1088 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1089 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1090 | Consumer<Integer> callback = |
| 1091 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1092 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1093 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1094 | if (ar.exception instanceof CommandException) { |
| 1095 | CommandException.Error error = |
| 1096 | ((CommandException) (ar.exception)).getCommandError(); |
| 1097 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1098 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1099 | } else { |
| 1100 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1101 | } |
| 1102 | } else { |
| 1103 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1104 | } |
| 1105 | } else { |
| 1106 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1107 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1108 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1109 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1110 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1111 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1112 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1113 | ar = (AsyncResult) msg.obj; |
| 1114 | request = (MainThreadRequest) ar.userObj; |
| 1115 | CellNetworkScanResult cellScanResult; |
| 1116 | if (ar.exception == null && ar.result != null) { |
| 1117 | cellScanResult = new CellNetworkScanResult( |
| 1118 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1119 | (List<OperatorInfo>) ar.result); |
| 1120 | } else { |
| 1121 | if (ar.result == null) { |
| 1122 | loge("getCellNetworkScanResults: Empty response"); |
| 1123 | } |
| 1124 | if (ar.exception != null) { |
| 1125 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1126 | } |
| 1127 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1128 | if (ar.exception instanceof CommandException) { |
| 1129 | CommandException.Error error = |
| 1130 | ((CommandException) (ar.exception)).getCommandError(); |
| 1131 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1132 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1133 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1134 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1135 | } |
| 1136 | } |
| 1137 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1138 | } |
| 1139 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1140 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1141 | break; |
| 1142 | |
| 1143 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1144 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1145 | ManualNetworkSelectionArgument selArg = |
| 1146 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1147 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1148 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1149 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1150 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1151 | break; |
| 1152 | |
| 1153 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1154 | ar = (AsyncResult) msg.obj; |
| 1155 | request = (MainThreadRequest) ar.userObj; |
| 1156 | if (ar.exception == null) { |
| 1157 | request.result = true; |
| 1158 | } else { |
| 1159 | request.result = false; |
| 1160 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1161 | } |
| 1162 | notifyRequester(request); |
| 1163 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1164 | break; |
| 1165 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1166 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1167 | request = (MainThreadRequest) msg.obj; |
| 1168 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1169 | if (defaultPhone != null) { |
| 1170 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1171 | } else { |
| 1172 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1173 | Bundle bundle = new Bundle(); |
| 1174 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1175 | new ModemActivityInfo(0, 0, 0, |
| 1176 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1177 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1178 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1179 | break; |
| 1180 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1181 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1182 | ar = (AsyncResult) msg.obj; |
| 1183 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1184 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1185 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1186 | ModemActivityInfo ret = null; |
| 1187 | int error = 0; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1188 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1189 | // Update the last modem activity info and the result of the request. |
| 1190 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1191 | if (isModemActivityInfoValid(info)) { |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1192 | int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()]; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1193 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1194 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1195 | .getTransmitTimeMillis(); |
| 1196 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1197 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1198 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1199 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1200 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1201 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1202 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1203 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1204 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1205 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1206 | info.getReceiveTimeMillis() |
| 1207 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1208 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1209 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(), |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1210 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1211 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1212 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1213 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1214 | } else { |
| 1215 | if (ar.result == null) { |
| 1216 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1217 | error = TelephonyManager.ModemActivityInfoException |
| 1218 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1219 | } else if (ar.exception instanceof CommandException) { |
| 1220 | loge("queryModemActivityInfo: CommandException: " + |
| 1221 | ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1222 | error = TelephonyManager.ModemActivityInfoException |
| 1223 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1224 | } else { |
| 1225 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1226 | error = TelephonyManager.ModemActivityInfoException |
| 1227 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1228 | } |
| 1229 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1230 | Bundle bundle = new Bundle(); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1231 | if (ret != null) { |
| 1232 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1233 | } else { |
| 1234 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1235 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1236 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1237 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1238 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1239 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1240 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1241 | case CMD_SET_ALLOWED_CARRIERS: |
| 1242 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1243 | CarrierRestrictionRules argument = |
| 1244 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1245 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1246 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1247 | break; |
| 1248 | |
| 1249 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1250 | ar = (AsyncResult) msg.obj; |
| 1251 | request = (MainThreadRequest) ar.userObj; |
| 1252 | if (ar.exception == null && ar.result != null) { |
| 1253 | request.result = ar.result; |
| 1254 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1255 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1256 | if (ar.exception instanceof CommandException) { |
| 1257 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1258 | CommandException.Error error = |
| 1259 | ((CommandException) (ar.exception)).getCommandError(); |
| 1260 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1261 | request.result = |
| 1262 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1263 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1264 | } else { |
| 1265 | loge("setAllowedCarriers: Unknown exception"); |
| 1266 | } |
| 1267 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1268 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1269 | break; |
| 1270 | |
| 1271 | case CMD_GET_ALLOWED_CARRIERS: |
| 1272 | request = (MainThreadRequest) msg.obj; |
| 1273 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1274 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1275 | break; |
| 1276 | |
| 1277 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1278 | ar = (AsyncResult) msg.obj; |
| 1279 | request = (MainThreadRequest) ar.userObj; |
| 1280 | if (ar.exception == null && ar.result != null) { |
| 1281 | request.result = ar.result; |
| 1282 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1283 | request.result = new IllegalStateException( |
| 1284 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1285 | if (ar.result == null) { |
| 1286 | loge("getAllowedCarriers: Empty response"); |
| 1287 | } else if (ar.exception instanceof CommandException) { |
| 1288 | loge("getAllowedCarriers: CommandException: " + |
| 1289 | ar.exception); |
| 1290 | } else { |
| 1291 | loge("getAllowedCarriers: Unknown exception"); |
| 1292 | } |
| 1293 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1294 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1295 | break; |
| 1296 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1297 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1298 | ar = (AsyncResult) msg.obj; |
| 1299 | request = (MainThreadRequest) ar.userObj; |
| 1300 | if (ar.exception == null && ar.result != null) { |
| 1301 | request.result = ar.result; |
| 1302 | } else { |
| 1303 | request.result = new IllegalArgumentException( |
| 1304 | "Failed to retrieve Forbidden Plmns"); |
| 1305 | if (ar.result == null) { |
| 1306 | loge("getForbiddenPlmns: Empty response"); |
| 1307 | } else { |
| 1308 | loge("getForbiddenPlmns: Unknown exception"); |
| 1309 | } |
| 1310 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1311 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1312 | break; |
| 1313 | |
| 1314 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1315 | request = (MainThreadRequest) msg.obj; |
| 1316 | uiccCard = getUiccCardFromRequest(request); |
| 1317 | if (uiccCard == null) { |
| 1318 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1319 | request.result = new IllegalArgumentException( |
| 1320 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1321 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1322 | break; |
| 1323 | } |
| 1324 | Integer appType = (Integer) request.argument; |
| 1325 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1326 | if (uiccApp == null) { |
| 1327 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1328 | + appType); |
| 1329 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1330 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1331 | break; |
| 1332 | } else { |
| 1333 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1334 | + " specified type -- " + appType); |
| 1335 | } |
| 1336 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1337 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1338 | onCompleted); |
| 1339 | break; |
| 1340 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1341 | case CMD_SWITCH_SLOTS: |
| 1342 | request = (MainThreadRequest) msg.obj; |
| 1343 | int[] physicalSlots = (int[]) request.argument; |
| 1344 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1345 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1346 | break; |
| 1347 | |
| 1348 | case EVENT_SWITCH_SLOTS_DONE: |
| 1349 | ar = (AsyncResult) msg.obj; |
| 1350 | request = (MainThreadRequest) ar.userObj; |
| 1351 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1352 | notifyRequester(request); |
| 1353 | break; |
| 1354 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1355 | request = (MainThreadRequest) msg.obj; |
| 1356 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1357 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1358 | break; |
| 1359 | |
| 1360 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1361 | ar = (AsyncResult) msg.obj; |
| 1362 | request = (MainThreadRequest) ar.userObj; |
| 1363 | if (ar.exception != null) { |
| 1364 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1365 | } else { |
| 1366 | int mode = ((int[]) ar.result)[0]; |
| 1367 | if (mode == 0) { |
| 1368 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1369 | } else { |
| 1370 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1371 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1372 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1373 | notifyRequester(request); |
| 1374 | break; |
| 1375 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1376 | request = (MainThreadRequest) msg.obj; |
| 1377 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1378 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1379 | break; |
| 1380 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1381 | ar = (AsyncResult) msg.obj; |
| 1382 | request = (MainThreadRequest) ar.userObj; |
| 1383 | if (ar.exception != null) { |
| 1384 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1385 | } else { |
| 1386 | request.result = ((int[]) ar.result)[0]; |
| 1387 | } |
| 1388 | notifyRequester(request); |
| 1389 | break; |
| 1390 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1391 | request = (MainThreadRequest) msg.obj; |
| 1392 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1393 | int mode = (int) request.argument; |
| 1394 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1395 | break; |
| 1396 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1397 | ar = (AsyncResult) msg.obj; |
| 1398 | request = (MainThreadRequest) ar.userObj; |
| 1399 | request.result = ar.exception == null; |
| 1400 | notifyRequester(request); |
| 1401 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1402 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1403 | request = (MainThreadRequest) msg.obj; |
| 1404 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1405 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1406 | break; |
| 1407 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1408 | ar = (AsyncResult) msg.obj; |
| 1409 | request = (MainThreadRequest) ar.userObj; |
| 1410 | if (ar.exception != null) { |
| 1411 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1412 | } else { |
| 1413 | request.result = ((int[]) ar.result)[0]; |
| 1414 | } |
| 1415 | notifyRequester(request); |
| 1416 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1417 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1418 | request = (MainThreadRequest) msg.obj; |
| 1419 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1420 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1421 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1422 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1423 | break; |
| 1424 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1425 | ar = (AsyncResult) msg.obj; |
| 1426 | request = (MainThreadRequest) ar.userObj; |
| 1427 | request.result = ar.exception == null; |
| 1428 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1429 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1430 | case CMD_GET_ALL_CELL_INFO: |
| 1431 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1432 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1433 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1434 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1435 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1436 | ar = (AsyncResult) msg.obj; |
| 1437 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1438 | // If a timeout occurs, the response will be null |
| 1439 | request.result = (ar.exception == null && ar.result != null) |
| 1440 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1441 | synchronized (request) { |
| 1442 | request.notifyAll(); |
| 1443 | } |
| 1444 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1445 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1446 | request = (MainThreadRequest) msg.obj; |
| 1447 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1448 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1449 | break; |
| 1450 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1451 | ar = (AsyncResult) msg.obj; |
| 1452 | request = (MainThreadRequest) ar.userObj; |
| 1453 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1454 | try { |
| 1455 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1456 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1457 | cb.onError( |
| 1458 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1459 | ar.exception.getClass().getName(), |
| 1460 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1461 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1462 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1463 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1464 | } else { |
| 1465 | // use the result as returned |
| 1466 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1467 | } |
| 1468 | } catch (RemoteException re) { |
| 1469 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1470 | } |
| 1471 | break; |
| 1472 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1473 | request = (MainThreadRequest) msg.obj; |
| 1474 | WorkSource ws = (WorkSource) request.argument; |
| 1475 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1476 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1477 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1478 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1479 | ar = (AsyncResult) msg.obj; |
| 1480 | request = (MainThreadRequest) ar.userObj; |
| 1481 | if (ar.exception == null) { |
| 1482 | request.result = ar.result; |
| 1483 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1484 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1485 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1486 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | synchronized (request) { |
| 1490 | request.notifyAll(); |
| 1491 | } |
| 1492 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1493 | case CMD_MODEM_REBOOT: |
| 1494 | request = (MainThreadRequest) msg.obj; |
| 1495 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1496 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1497 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1498 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1499 | handleNullReturnEvent(msg, "rebootModem"); |
| 1500 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1501 | case CMD_REQUEST_ENABLE_MODEM: |
| 1502 | request = (MainThreadRequest) msg.obj; |
| 1503 | boolean enable = (boolean) request.argument; |
| 1504 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1505 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1506 | PhoneConfigurationManager.getInstance() |
| 1507 | .enablePhone(request.phone, enable, onCompleted); |
| 1508 | break; |
| 1509 | case EVENT_ENABLE_MODEM_DONE: |
| 1510 | ar = (AsyncResult) msg.obj; |
| 1511 | request = (MainThreadRequest) ar.userObj; |
| 1512 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1513 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1514 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1515 | if ((boolean) request.result) { |
| 1516 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1517 | updateModemStateMetrics(); |
| 1518 | } else { |
| 1519 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1520 | + ar.exception); |
| 1521 | } |
| 1522 | notifyRequester(request); |
| 1523 | break; |
| 1524 | case CMD_GET_MODEM_STATUS: |
| 1525 | request = (MainThreadRequest) msg.obj; |
| 1526 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1527 | PhoneConfigurationManager.getInstance() |
| 1528 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1529 | break; |
| 1530 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1531 | ar = (AsyncResult) msg.obj; |
| 1532 | request = (MainThreadRequest) ar.userObj; |
| 1533 | int id = request.phone.getPhoneId(); |
| 1534 | if (ar.exception == null && ar.result != null) { |
| 1535 | request.result = ar.result; |
| 1536 | //update the cache as modem status has changed |
| 1537 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1538 | (boolean) request.result); |
| 1539 | } else { |
| 1540 | // Return true if modem status cannot be retrieved. For most cases, |
| 1541 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1542 | // and disable modem are not supported. Modem is always on. |
| 1543 | // TODO: this should be fixed in R to support a third |
| 1544 | // status UNKNOWN b/131631629 |
| 1545 | request.result = true; |
| 1546 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1547 | + ar.exception); |
| 1548 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1549 | notifyRequester(request); |
| 1550 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1551 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1552 | request = (MainThreadRequest) msg.obj; |
| 1553 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1554 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1555 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1556 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1557 | break; |
| 1558 | } |
| 1559 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1560 | ar = (AsyncResult) msg.obj; |
| 1561 | request = (MainThreadRequest) ar.userObj; |
| 1562 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1563 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1564 | args.second.accept(ar.exception == null); |
| 1565 | notifyRequester(request); |
| 1566 | break; |
| 1567 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1568 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1569 | ar = (AsyncResult) msg.obj; |
| 1570 | request = (MainThreadRequest) ar.userObj; |
| 1571 | if (ar.exception == null && ar.result != null) { |
| 1572 | request.result = ar.result; |
| 1573 | } else { |
| 1574 | request.result = -1; |
| 1575 | loge("Failed to set Forbidden Plmns"); |
| 1576 | if (ar.result == null) { |
| 1577 | loge("setForbidenPlmns: Empty response"); |
| 1578 | } else if (ar.exception != null) { |
| 1579 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1580 | request.result = -1; |
| 1581 | } else { |
| 1582 | loge("setForbiddenPlmns: Unknown exception"); |
| 1583 | } |
| 1584 | } |
| 1585 | notifyRequester(request); |
| 1586 | break; |
| 1587 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1588 | request = (MainThreadRequest) msg.obj; |
| 1589 | uiccCard = getUiccCardFromRequest(request); |
| 1590 | if (uiccCard == null) { |
| 1591 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1592 | request.result = -1; |
| 1593 | notifyRequester(request); |
| 1594 | break; |
| 1595 | } |
| 1596 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1597 | (Pair<Integer, List<String>>) request.argument; |
| 1598 | appType = setFplmnsArgs.first; |
| 1599 | List<String> fplmns = setFplmnsArgs.second; |
| 1600 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1601 | if (uiccApp == null) { |
| 1602 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1603 | request.result = -1; |
| 1604 | loge("Failed to get UICC App"); |
| 1605 | notifyRequester(request); |
| 1606 | } else { |
| 1607 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1608 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1609 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1610 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1611 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1612 | case CMD_ERASE_MODEM_CONFIG: |
| 1613 | request = (MainThreadRequest) msg.obj; |
| 1614 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1615 | defaultPhone.eraseModemConfig(onCompleted); |
| 1616 | break; |
| 1617 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1618 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1619 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1620 | |
| 1621 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1622 | request = (MainThreadRequest) msg.obj; |
| 1623 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1624 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1625 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1626 | changed.first, changed.second, onCompleted); |
| 1627 | break; |
| 1628 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1629 | ar = (AsyncResult) msg.obj; |
| 1630 | request = (MainThreadRequest) ar.userObj; |
| 1631 | if (ar.exception == null) { |
| 1632 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1633 | } else { |
| 1634 | request.result = msg.arg1; |
| 1635 | } |
| 1636 | notifyRequester(request); |
| 1637 | break; |
| 1638 | |
| 1639 | case CMD_SET_ICC_LOCK_ENABLED: |
| 1640 | request = (MainThreadRequest) msg.obj; |
| 1641 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1642 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1643 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1644 | enabled.first, enabled.second, onCompleted); |
| 1645 | break; |
| 1646 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1647 | ar = (AsyncResult) msg.obj; |
| 1648 | request = (MainThreadRequest) ar.userObj; |
| 1649 | if (ar.exception == null) { |
| 1650 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1651 | } else { |
| 1652 | request.result = msg.arg1; |
| 1653 | } |
| 1654 | notifyRequester(request); |
| 1655 | break; |
| 1656 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1657 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1658 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1659 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1660 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1661 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1662 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1663 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1664 | default: |
| 1665 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1666 | break; |
| 1667 | } |
| 1668 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1669 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1670 | private void notifyRequester(MainThreadRequest request) { |
| 1671 | synchronized (request) { |
| 1672 | request.notifyAll(); |
| 1673 | } |
| 1674 | } |
| 1675 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1676 | private void handleNullReturnEvent(Message msg, String command) { |
| 1677 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1678 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1679 | if (ar.exception == null) { |
| 1680 | request.result = true; |
| 1681 | } else { |
| 1682 | request.result = false; |
| 1683 | if (ar.exception instanceof CommandException) { |
| 1684 | loge(command + ": CommandException: " + ar.exception); |
| 1685 | } else { |
| 1686 | loge(command + ": Unknown exception"); |
| 1687 | } |
| 1688 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1689 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1690 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1691 | } |
| 1692 | |
| 1693 | /** |
| 1694 | * Posts the specified command to be executed on the main thread, |
| 1695 | * waits for the request to complete, and returns the result. |
| 1696 | * @see #sendRequestAsync |
| 1697 | */ |
| 1698 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1699 | return sendRequest( |
| 1700 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1701 | } |
| 1702 | |
| 1703 | /** |
| 1704 | * Posts the specified command to be executed on the main thread, |
| 1705 | * waits for the request to complete, and returns the result. |
| 1706 | * @see #sendRequestAsync |
| 1707 | */ |
| 1708 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1709 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1710 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1711 | } |
| 1712 | |
| 1713 | /** |
| 1714 | * Posts the specified command to be executed on the main thread, |
| 1715 | * waits for the request to complete, and returns the result. |
| 1716 | * @see #sendRequestAsync |
| 1717 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1718 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1719 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1720 | } |
| 1721 | |
| 1722 | /** |
| 1723 | * Posts the specified command to be executed on the main thread, |
| 1724 | * waits for the request to complete, and returns the result. |
| 1725 | * @see #sendRequestAsync |
| 1726 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1727 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1728 | return sendRequest(command, argument, subId, null, workSource); |
| 1729 | } |
| 1730 | |
| 1731 | /** |
| 1732 | * Posts the specified command to be executed on the main thread, |
| 1733 | * waits for the request to complete, and returns the result. |
| 1734 | * @see #sendRequestAsync |
| 1735 | */ |
| 1736 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1737 | return sendRequest( |
| 1738 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1739 | } |
| 1740 | |
| 1741 | /** |
| 1742 | * Posts the specified command to be executed on the main thread, |
| 1743 | * waits for the request to complete, and returns the result. |
| 1744 | * @see #sendRequestAsync |
| 1745 | */ |
| 1746 | private Object sendRequest( |
| 1747 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1748 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1749 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1750 | } |
| 1751 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1752 | MainThreadRequest request = null; |
| 1753 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1754 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1755 | } else if (phone != null) { |
| 1756 | request = new MainThreadRequest(argument, phone, workSource); |
| 1757 | } else { |
| 1758 | request = new MainThreadRequest(argument, subId, workSource); |
| 1759 | } |
| 1760 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1761 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1762 | msg.sendToTarget(); |
| 1763 | |
| 1764 | // Wait for the request to complete |
| 1765 | synchronized (request) { |
| 1766 | while (request.result == null) { |
| 1767 | try { |
| 1768 | request.wait(); |
| 1769 | } catch (InterruptedException e) { |
| 1770 | // Do nothing, go back and wait until the request is complete |
| 1771 | } |
| 1772 | } |
| 1773 | } |
| 1774 | return request.result; |
| 1775 | } |
| 1776 | |
| 1777 | /** |
| 1778 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1779 | * Posts the specified command to be executed on the main thread, and |
| 1780 | * returns immediately. |
| 1781 | * @see #sendRequest |
| 1782 | */ |
| 1783 | private void sendRequestAsync(int command) { |
| 1784 | mMainThreadHandler.sendEmptyMessage(command); |
| 1785 | } |
| 1786 | |
| 1787 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1788 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1789 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1790 | */ |
| 1791 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1792 | sendRequestAsync(command, argument, null, null); |
| 1793 | } |
| 1794 | |
| 1795 | /** |
| 1796 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1797 | * @see {@link #sendRequest(int,Object)} |
| 1798 | */ |
| 1799 | private void sendRequestAsync( |
| 1800 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1801 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1802 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1803 | msg.sendToTarget(); |
| 1804 | } |
| 1805 | |
| 1806 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1807 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1808 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1809 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1810 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1811 | synchronized (PhoneInterfaceManager.class) { |
| 1812 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1813 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1814 | } else { |
| 1815 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1816 | } |
| 1817 | return sInstance; |
| 1818 | } |
| 1819 | } |
| 1820 | |
| 1821 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 1822 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1823 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1824 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1825 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1826 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1827 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1828 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1829 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1830 | mTelephonySharedPreferences = |
| 1831 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1832 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1833 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 1834 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1835 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1836 | publish(); |
| 1837 | } |
| 1838 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1839 | private Phone getDefaultPhone() { |
| 1840 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1841 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1842 | } |
| 1843 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1844 | private void publish() { |
| 1845 | if (DBG) log("publish: " + this); |
| 1846 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 1847 | TelephonyFrameworkInitializer |
| 1848 | .getTelephonyServiceManager() |
| 1849 | .getTelephonyServiceRegisterer() |
| 1850 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1851 | } |
| 1852 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1853 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1854 | if (request.phone != null) { |
| 1855 | return request.phone; |
| 1856 | } else { |
| 1857 | return getPhoneFromSubId(request.subId); |
| 1858 | } |
| 1859 | } |
| 1860 | |
| 1861 | private Phone getPhoneFromSubId(int subId) { |
| 1862 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1863 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1864 | } |
| 1865 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1866 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1867 | Phone phone = getPhoneFromRequest(request); |
| 1868 | return phone == null ? null : |
| 1869 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1870 | } |
| 1871 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1872 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1873 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1874 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1875 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1876 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1877 | private void sendEraseModemConfig(Phone phone) { |
| 1878 | if (phone != null) { |
| 1879 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 1880 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 1881 | final long identity = Binder.clearCallingIdentity(); |
| 1882 | try { |
| 1883 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 1884 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 1885 | } finally { |
| 1886 | Binder.restoreCallingIdentity(identity); |
| 1887 | } |
| 1888 | } |
| 1889 | } |
| 1890 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 1891 | private boolean isImsAvailableOnDevice() { |
| 1892 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 1893 | if (pm == null) { |
| 1894 | // For some reason package manger is not available.. This will fail internally anyway, |
| 1895 | // so do not throw error and allow. |
| 1896 | return true; |
| 1897 | } |
| 1898 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 1899 | } |
| 1900 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1901 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1902 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1903 | } |
| 1904 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1905 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1906 | if (DBG) log("dial: " + number); |
| 1907 | // No permission check needed here: This is just a wrapper around the |
| 1908 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1909 | // the UI before it does anything. |
| 1910 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1911 | final long identity = Binder.clearCallingIdentity(); |
| 1912 | try { |
| 1913 | String url = createTelUrl(number); |
| 1914 | if (url == null) { |
| 1915 | return; |
| 1916 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1917 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1918 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1919 | PhoneConstants.State state = mCM.getState(subId); |
| 1920 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1921 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1922 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1923 | mApp.startActivity(intent); |
| 1924 | } |
| 1925 | } finally { |
| 1926 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1927 | } |
| 1928 | } |
| 1929 | |
| 1930 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1931 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1932 | } |
| 1933 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1934 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1935 | if (DBG) log("call: " + number); |
| 1936 | |
| 1937 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1938 | // need to do a permission check since we're calling startActivity() |
| 1939 | // from the context of the phone app. |
| 1940 | enforceCallPermission(); |
| 1941 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 1942 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1943 | != AppOpsManager.MODE_ALLOWED) { |
| 1944 | return; |
| 1945 | } |
| 1946 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1947 | final long identity = Binder.clearCallingIdentity(); |
| 1948 | try { |
| 1949 | String url = createTelUrl(number); |
| 1950 | if (url == null) { |
| 1951 | return; |
| 1952 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1953 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1954 | boolean isValid = false; |
| 1955 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1956 | if (slist != null) { |
| 1957 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1958 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1959 | isValid = true; |
| 1960 | break; |
| 1961 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1962 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1963 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1964 | if (!isValid) { |
| 1965 | return; |
| 1966 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1967 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1968 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1969 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1970 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1971 | mApp.startActivity(intent); |
| 1972 | } finally { |
| 1973 | Binder.restoreCallingIdentity(identity); |
| 1974 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1975 | } |
| 1976 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1977 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1978 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1979 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1980 | } |
| 1981 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1982 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1983 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1984 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1985 | } |
| 1986 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1987 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1988 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1989 | |
| 1990 | final long identity = Binder.clearCallingIdentity(); |
| 1991 | try { |
| 1992 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1993 | checkSimPin.start(); |
| 1994 | return checkSimPin.unlockSim(null, pin); |
| 1995 | } finally { |
| 1996 | Binder.restoreCallingIdentity(identity); |
| 1997 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1998 | } |
| 1999 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2000 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2001 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2002 | |
| 2003 | final long identity = Binder.clearCallingIdentity(); |
| 2004 | try { |
| 2005 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 2006 | checkSimPuk.start(); |
| 2007 | return checkSimPuk.unlockSim(puk, pin); |
| 2008 | } finally { |
| 2009 | Binder.restoreCallingIdentity(identity); |
| 2010 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2011 | } |
| 2012 | |
| 2013 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2014 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2015 | * a synchronous one. |
| 2016 | */ |
| 2017 | private static class UnlockSim extends Thread { |
| 2018 | |
| 2019 | private final IccCard mSimCard; |
| 2020 | |
| 2021 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2022 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2023 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2024 | |
| 2025 | // For replies from SimCard interface |
| 2026 | private Handler mHandler; |
| 2027 | |
| 2028 | // For async handler to identify request type |
| 2029 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2030 | |
| 2031 | public UnlockSim(IccCard simCard) { |
| 2032 | mSimCard = simCard; |
| 2033 | } |
| 2034 | |
| 2035 | @Override |
| 2036 | public void run() { |
| 2037 | Looper.prepare(); |
| 2038 | synchronized (UnlockSim.this) { |
| 2039 | mHandler = new Handler() { |
| 2040 | @Override |
| 2041 | public void handleMessage(Message msg) { |
| 2042 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2043 | switch (msg.what) { |
| 2044 | case SUPPLY_PIN_COMPLETE: |
| 2045 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2046 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2047 | mRetryCount = msg.arg1; |
| 2048 | if (ar.exception != null) { |
| 2049 | if (ar.exception instanceof CommandException && |
| 2050 | ((CommandException)(ar.exception)).getCommandError() |
| 2051 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2052 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2053 | } //When UiccCardApp dispose,handle message and return exception |
| 2054 | else if (ar.exception instanceof CommandException && |
| 2055 | ((CommandException) (ar.exception)).getCommandError() |
| 2056 | == CommandException.Error.ABORTED) { |
| 2057 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2058 | } else { |
| 2059 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2060 | } |
| 2061 | } else { |
| 2062 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2063 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2064 | mDone = true; |
| 2065 | UnlockSim.this.notifyAll(); |
| 2066 | } |
| 2067 | break; |
| 2068 | } |
| 2069 | } |
| 2070 | }; |
| 2071 | UnlockSim.this.notifyAll(); |
| 2072 | } |
| 2073 | Looper.loop(); |
| 2074 | } |
| 2075 | |
| 2076 | /* |
| 2077 | * Use PIN or PUK to unlock SIM card |
| 2078 | * |
| 2079 | * If PUK is null, unlock SIM card with PIN |
| 2080 | * |
| 2081 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2082 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2083 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2084 | |
| 2085 | while (mHandler == null) { |
| 2086 | try { |
| 2087 | wait(); |
| 2088 | } catch (InterruptedException e) { |
| 2089 | Thread.currentThread().interrupt(); |
| 2090 | } |
| 2091 | } |
| 2092 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2093 | |
| 2094 | if (puk == null) { |
| 2095 | mSimCard.supplyPin(pin, callback); |
| 2096 | } else { |
| 2097 | mSimCard.supplyPuk(puk, pin, callback); |
| 2098 | } |
| 2099 | |
| 2100 | while (!mDone) { |
| 2101 | try { |
| 2102 | Log.d(LOG_TAG, "wait for done"); |
| 2103 | wait(); |
| 2104 | } catch (InterruptedException e) { |
| 2105 | // Restore the interrupted status |
| 2106 | Thread.currentThread().interrupt(); |
| 2107 | } |
| 2108 | } |
| 2109 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2110 | int[] resultArray = new int[2]; |
| 2111 | resultArray[0] = mResult; |
| 2112 | resultArray[1] = mRetryCount; |
| 2113 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2114 | } |
| 2115 | } |
| 2116 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2117 | /** |
| 2118 | * This method has been removed due to privacy and stability concerns. |
| 2119 | */ |
| 2120 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2121 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2122 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2123 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2124 | } |
| 2125 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2126 | @Override |
| 2127 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2128 | mApp.getSystemService(AppOpsManager.class) |
| 2129 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2130 | |
| 2131 | final int targetSdk = getTargetSdk(callingPackage); |
| 2132 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2133 | // Callers targeting S have no business invoking this method. |
| 2134 | return; |
| 2135 | } |
| 2136 | |
| 2137 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2138 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2139 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2140 | .setCallingPackage(callingPackage) |
| 2141 | .setCallingFeatureId(null) |
| 2142 | .setCallingPid(Binder.getCallingPid()) |
| 2143 | .setCallingUid(Binder.getCallingUid()) |
| 2144 | .setMethod("updateServiceLocation") |
| 2145 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2146 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2147 | .build()); |
| 2148 | // Apps that lack location permission have no business calling this method; |
| 2149 | // however, because no permission was declared in the public API, denials must |
| 2150 | // all be "soft". |
| 2151 | switch (locationResult) { |
| 2152 | case DENIED_HARD: /* fall through */ |
| 2153 | case DENIED_SOFT: |
| 2154 | return; |
| 2155 | } |
| 2156 | |
| 2157 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2158 | final long identity = Binder.clearCallingIdentity(); |
| 2159 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2160 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2161 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2162 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2163 | } |
| 2164 | } finally { |
| 2165 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2166 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2167 | } |
| 2168 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2169 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2170 | @Override |
| 2171 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2172 | return isRadioOnWithFeature(callingPackage, null); |
| 2173 | } |
| 2174 | |
| 2175 | |
| 2176 | @Override |
| 2177 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2178 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2179 | callingFeatureId); |
| 2180 | } |
| 2181 | |
| 2182 | @Deprecated |
| 2183 | @Override |
| 2184 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2185 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2186 | } |
| 2187 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2188 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2189 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2190 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2191 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2192 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2193 | return false; |
| 2194 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2195 | |
| 2196 | final long identity = Binder.clearCallingIdentity(); |
| 2197 | try { |
| 2198 | return isRadioOnForSubscriber(subId); |
| 2199 | } finally { |
| 2200 | Binder.restoreCallingIdentity(identity); |
| 2201 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2202 | } |
| 2203 | |
| 2204 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2205 | final long identity = Binder.clearCallingIdentity(); |
| 2206 | try { |
| 2207 | final Phone phone = getPhone(subId); |
| 2208 | if (phone != null) { |
| 2209 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2210 | } else { |
| 2211 | return false; |
| 2212 | } |
| 2213 | } finally { |
| 2214 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2215 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2216 | } |
| 2217 | |
| 2218 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2219 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2220 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2221 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2222 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2223 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2224 | |
| 2225 | final long identity = Binder.clearCallingIdentity(); |
| 2226 | try { |
| 2227 | final Phone phone = getPhone(subId); |
| 2228 | if (phone != null) { |
| 2229 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2230 | } |
| 2231 | } finally { |
| 2232 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2233 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2234 | } |
| 2235 | |
| 2236 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2237 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2238 | } |
| 2239 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2240 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2241 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2242 | |
| 2243 | final long identity = Binder.clearCallingIdentity(); |
| 2244 | try { |
| 2245 | final Phone phone = getPhone(subId); |
| 2246 | if (phone == null) { |
| 2247 | return false; |
| 2248 | } |
| 2249 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2250 | toggleRadioOnOffForSubscriber(subId); |
| 2251 | } |
| 2252 | return true; |
| 2253 | } finally { |
| 2254 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2255 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2256 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2257 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2258 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2259 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2260 | /* |
| 2261 | * If any of the Radios are available, it will need to be |
| 2262 | * shutdown. So return true if any Radio is available. |
| 2263 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2264 | final long identity = Binder.clearCallingIdentity(); |
| 2265 | try { |
| 2266 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2267 | Phone phone = PhoneFactory.getPhone(i); |
| 2268 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2269 | } |
| 2270 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2271 | return false; |
| 2272 | } finally { |
| 2273 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2274 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2275 | } |
| 2276 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2277 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2278 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2279 | enforceModifyPermission(); |
| 2280 | |
| 2281 | final long identity = Binder.clearCallingIdentity(); |
| 2282 | try { |
| 2283 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2284 | logv("Shutting down Phone " + i); |
| 2285 | shutdownRadioUsingPhoneId(i); |
| 2286 | } |
| 2287 | } finally { |
| 2288 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2289 | } |
| 2290 | } |
| 2291 | |
| 2292 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2293 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2294 | if (phone != null && phone.isRadioAvailable()) { |
| 2295 | phone.shutdownRadio(); |
| 2296 | } |
| 2297 | } |
| 2298 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2299 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2300 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2301 | |
| 2302 | final long identity = Binder.clearCallingIdentity(); |
| 2303 | try { |
| 2304 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2305 | if (defaultPhone != null) { |
| 2306 | defaultPhone.setRadioPower(turnOn); |
| 2307 | return true; |
| 2308 | } else { |
| 2309 | loge("There's no default phone."); |
| 2310 | return false; |
| 2311 | } |
| 2312 | } finally { |
| 2313 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2314 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2315 | } |
| 2316 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2317 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2318 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2319 | |
| 2320 | final long identity = Binder.clearCallingIdentity(); |
| 2321 | try { |
| 2322 | final Phone phone = getPhone(subId); |
| 2323 | if (phone != null) { |
| 2324 | phone.setRadioPower(turnOn); |
| 2325 | return true; |
| 2326 | } else { |
| 2327 | return false; |
| 2328 | } |
| 2329 | } finally { |
| 2330 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2331 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2332 | } |
| 2333 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2334 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2335 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2336 | public boolean enableDataConnectivity() { |
| 2337 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2338 | |
| 2339 | final long identity = Binder.clearCallingIdentity(); |
| 2340 | try { |
| 2341 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2342 | final Phone phone = getPhone(subId); |
| 2343 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2344 | phone.getDataEnabledSettings().setDataEnabled( |
| 2345 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2346 | return true; |
| 2347 | } else { |
| 2348 | return false; |
| 2349 | } |
| 2350 | } finally { |
| 2351 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2352 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2353 | } |
| 2354 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2355 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2356 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2357 | public boolean disableDataConnectivity() { |
| 2358 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2359 | |
| 2360 | final long identity = Binder.clearCallingIdentity(); |
| 2361 | try { |
| 2362 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2363 | final Phone phone = getPhone(subId); |
| 2364 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2365 | phone.getDataEnabledSettings().setDataEnabled( |
| 2366 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2367 | return true; |
| 2368 | } else { |
| 2369 | return false; |
| 2370 | } |
| 2371 | } finally { |
| 2372 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2373 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2374 | } |
| 2375 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2376 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2377 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2378 | final long identity = Binder.clearCallingIdentity(); |
| 2379 | try { |
| 2380 | final Phone phone = getPhone(subId); |
| 2381 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2382 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2383 | } else { |
| 2384 | return false; |
| 2385 | } |
| 2386 | } finally { |
| 2387 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2388 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2389 | } |
| 2390 | |
| 2391 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2392 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2393 | } |
| 2394 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2395 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2396 | enforceCallPermission(); |
| 2397 | |
| 2398 | final long identity = Binder.clearCallingIdentity(); |
| 2399 | try { |
| 2400 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2401 | return; |
| 2402 | } |
| 2403 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2404 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2405 | } finally { |
| 2406 | Binder.restoreCallingIdentity(identity); |
| 2407 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2408 | }; |
| 2409 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2410 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2411 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2412 | |
| 2413 | final long identity = Binder.clearCallingIdentity(); |
| 2414 | try { |
| 2415 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2416 | return false; |
| 2417 | } |
| 2418 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2419 | } finally { |
| 2420 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2421 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2422 | } |
| 2423 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2424 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2425 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2426 | } |
| 2427 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2428 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2429 | final long identity = Binder.clearCallingIdentity(); |
| 2430 | try { |
| 2431 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2432 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2433 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2434 | } finally { |
| 2435 | Binder.restoreCallingIdentity(identity); |
| 2436 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2437 | } |
| 2438 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2439 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2440 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2441 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2442 | } |
| 2443 | |
| 2444 | @Override |
| 2445 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2446 | final long identity = Binder.clearCallingIdentity(); |
| 2447 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2448 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2449 | if (phone != null) { |
| 2450 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2451 | } else { |
| 2452 | return PhoneConstantConversions.convertDataState( |
| 2453 | PhoneConstants.DataState.DISCONNECTED); |
| 2454 | } |
| 2455 | } finally { |
| 2456 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2457 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2458 | } |
| 2459 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2460 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2461 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2462 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2463 | } |
| 2464 | |
| 2465 | @Override |
| 2466 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2467 | final long identity = Binder.clearCallingIdentity(); |
| 2468 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2469 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2470 | if (phone != null) { |
| 2471 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2472 | } else { |
| 2473 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2474 | } |
| 2475 | } finally { |
| 2476 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2477 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2478 | } |
| 2479 | |
| 2480 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2481 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2482 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2483 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2484 | |
| 2485 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2486 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2487 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2488 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2489 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2490 | .setCallingPid(Binder.getCallingPid()) |
| 2491 | .setCallingUid(Binder.getCallingUid()) |
| 2492 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2493 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2494 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2495 | .build()); |
| 2496 | switch (locationResult) { |
| 2497 | case DENIED_HARD: |
| 2498 | throw new SecurityException("Not allowed to access cell location"); |
| 2499 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2500 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2501 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2502 | } |
| 2503 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2504 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2505 | final long identity = Binder.clearCallingIdentity(); |
| 2506 | try { |
| 2507 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2508 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2509 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2510 | } finally { |
| 2511 | Binder.restoreCallingIdentity(identity); |
| 2512 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2513 | } |
| 2514 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2515 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2516 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2517 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2518 | // registered cell info, so return a NULL country instead. |
| 2519 | final long identity = Binder.clearCallingIdentity(); |
| 2520 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2521 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2522 | // Get default phone in this case. |
| 2523 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2524 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2525 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2526 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2527 | if (phone == null) return ""; |
| 2528 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2529 | if (sst == null) return ""; |
| 2530 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2531 | if (lt == null) return ""; |
| 2532 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry(); |
| 2533 | EmergencyNumberTracker ent = phone.getEmergencyNumberTracker(); |
| 2534 | return (ent == null) ? "" : ent.getEmergencyCountryIso(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2535 | } finally { |
| 2536 | Binder.restoreCallingIdentity(identity); |
| 2537 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2538 | } |
| 2539 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2540 | /** |
| 2541 | * This method was removed due to potential issues caused by performing partial |
| 2542 | * updates of service state, and lack of a credible use case. |
| 2543 | * |
| 2544 | * This has the ability to break the telephony implementation by disabling notification of |
| 2545 | * changes in device connectivity. DO NOT USE THIS! |
| 2546 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2547 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2548 | public void enableLocationUpdates() { |
| 2549 | mApp.enforceCallingOrSelfPermission( |
| 2550 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2551 | } |
| 2552 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2553 | /** |
| 2554 | * This method was removed due to potential issues caused by performing partial |
| 2555 | * updates of service state, and lack of a credible use case. |
| 2556 | * |
| 2557 | * This has the ability to break the telephony implementation by disabling notification of |
| 2558 | * changes in device connectivity. DO NOT USE THIS! |
| 2559 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2560 | @Override |
| 2561 | public void disableLocationUpdates() { |
| 2562 | mApp.enforceCallingOrSelfPermission( |
| 2563 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2564 | } |
| 2565 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2566 | /** |
| 2567 | * Returns the target SDK version number for a given package name. |
| 2568 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2569 | * This call MUST be invoked before clearing the calling UID. |
| 2570 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2571 | * @return target SDK if the package is found or INT_MAX. |
| 2572 | */ |
| 2573 | private int getTargetSdk(String packageName) { |
| 2574 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2575 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 0150f0e | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2576 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2577 | if (ai != null) return ai.targetSdkVersion; |
| 2578 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2579 | loge("Failed to get package info for pkg=" |
| 2580 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2581 | } |
| 2582 | return Integer.MAX_VALUE; |
| 2583 | } |
| 2584 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2585 | @Override |
| 2586 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2587 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2588 | String callingFeatureId) { |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2589 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2590 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2591 | throw new SecurityException( |
| 2592 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2593 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2594 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2595 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2596 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2597 | return null; |
| 2598 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2599 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2600 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2601 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2602 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2603 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2604 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2605 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2606 | for (CellInfo ci : info) { |
| 2607 | if (ci instanceof CellInfoGsm) { |
| 2608 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2609 | } else if (ci instanceof CellInfoWcdma) { |
| 2610 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2611 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2612 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2613 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2614 | } |
| 2615 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2616 | private List<CellInfo> getCachedCellInfo() { |
| 2617 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2618 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2619 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2620 | if (info != null) cellInfos.addAll(info); |
| 2621 | } |
| 2622 | return cellInfos; |
| 2623 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2624 | |
| 2625 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2626 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2627 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2628 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2629 | |
| 2630 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2631 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2632 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2633 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2634 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2635 | .setCallingPid(Binder.getCallingPid()) |
| 2636 | .setCallingUid(Binder.getCallingUid()) |
| 2637 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2638 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2639 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2640 | .build()); |
| 2641 | switch (locationResult) { |
| 2642 | case DENIED_HARD: |
| 2643 | throw new SecurityException("Not allowed to access cell info"); |
| 2644 | case DENIED_SOFT: |
| 2645 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2646 | } |
| 2647 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2648 | final int targetSdk = getTargetSdk(callingPackage); |
| 2649 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2650 | return getCachedCellInfo(); |
| 2651 | } |
| 2652 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2653 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2654 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2655 | final long identity = Binder.clearCallingIdentity(); |
| 2656 | try { |
| 2657 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2658 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2659 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2660 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2661 | if (info != null) cellInfos.addAll(info); |
| 2662 | } |
| 2663 | return cellInfos; |
| 2664 | } finally { |
| 2665 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2666 | } |
| 2667 | } |
| 2668 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2669 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2670 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2671 | String callingFeatureId) { |
| 2672 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2673 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2674 | } |
| 2675 | |
| 2676 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2677 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2678 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2679 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2680 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2681 | } |
| 2682 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2683 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2684 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2685 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2686 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2687 | |
| 2688 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2689 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2690 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2691 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2692 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2693 | .setCallingPid(Binder.getCallingPid()) |
| 2694 | .setCallingUid(Binder.getCallingUid()) |
| 2695 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2696 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2697 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2698 | .build()); |
| 2699 | switch (locationResult) { |
| 2700 | case DENIED_HARD: |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2701 | if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) { |
| 2702 | // Safetynet logging for b/154934934 |
| 2703 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2704 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2705 | throw new SecurityException("Not allowed to access cell info"); |
| 2706 | case DENIED_SOFT: |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2707 | if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) { |
| 2708 | // Safetynet logging for b/154934934 |
| 2709 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2710 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2711 | try { |
| 2712 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2713 | } catch (RemoteException re) { |
| 2714 | // Drop without consequences |
| 2715 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2716 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2717 | } |
| 2718 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2719 | |
| 2720 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2721 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2722 | |
| 2723 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2724 | } |
| 2725 | |
| 2726 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2727 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2728 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2729 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2730 | |
| 2731 | final long identity = Binder.clearCallingIdentity(); |
| 2732 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2733 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2734 | } finally { |
| 2735 | Binder.restoreCallingIdentity(identity); |
| 2736 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2737 | } |
| 2738 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2739 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2740 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2741 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2742 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2743 | return null; |
| 2744 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2745 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2746 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2747 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2748 | return null; |
| 2749 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2750 | |
| 2751 | final long identity = Binder.clearCallingIdentity(); |
| 2752 | try { |
| 2753 | return phone.getImei(); |
| 2754 | } finally { |
| 2755 | Binder.restoreCallingIdentity(identity); |
| 2756 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2757 | } |
| 2758 | |
| 2759 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2760 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2761 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2762 | String tac = null; |
| 2763 | if (phone != null) { |
| 2764 | String imei = phone.getImei(); |
| 2765 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2766 | } |
| 2767 | return tac; |
| 2768 | } |
| 2769 | |
| 2770 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2771 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2772 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2773 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2774 | return null; |
| 2775 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2776 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2777 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2778 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2779 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2780 | return null; |
| 2781 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2782 | |
| 2783 | final long identity = Binder.clearCallingIdentity(); |
| 2784 | try { |
| 2785 | return phone.getMeid(); |
| 2786 | } finally { |
| 2787 | Binder.restoreCallingIdentity(identity); |
| 2788 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2789 | } |
| 2790 | |
| 2791 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2792 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2793 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2794 | String manufacturerCode = null; |
| 2795 | if (phone != null) { |
| 2796 | String meid = phone.getMeid(); |
| 2797 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2798 | } |
| 2799 | return manufacturerCode; |
| 2800 | } |
| 2801 | |
| 2802 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2803 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2804 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2805 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2806 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2807 | return null; |
| 2808 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2809 | int subId = phone.getSubId(); |
| 2810 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2811 | mApp, subId, callingPackage, callingFeatureId, |
| 2812 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2813 | return null; |
| 2814 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2815 | |
| 2816 | final long identity = Binder.clearCallingIdentity(); |
| 2817 | try { |
| 2818 | return phone.getDeviceSvn(); |
| 2819 | } finally { |
| 2820 | Binder.restoreCallingIdentity(identity); |
| 2821 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2822 | } |
| 2823 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2824 | @Override |
| 2825 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2826 | final long identity = Binder.clearCallingIdentity(); |
| 2827 | try { |
| 2828 | final Phone phone = getPhone(subId); |
| 2829 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2830 | } finally { |
| 2831 | Binder.restoreCallingIdentity(identity); |
| 2832 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2833 | } |
| 2834 | |
| 2835 | @Override |
| 2836 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2837 | final long identity = Binder.clearCallingIdentity(); |
| 2838 | try { |
| 2839 | final Phone phone = getPhone(subId); |
| 2840 | return phone == null ? null : phone.getCarrierName(); |
| 2841 | } finally { |
| 2842 | Binder.restoreCallingIdentity(identity); |
| 2843 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2844 | } |
| 2845 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2846 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2847 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2848 | final long identity = Binder.clearCallingIdentity(); |
| 2849 | try { |
| 2850 | final Phone phone = getPhone(subId); |
| 2851 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2852 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2853 | } finally { |
| 2854 | Binder.restoreCallingIdentity(identity); |
| 2855 | } |
| 2856 | } |
| 2857 | |
| 2858 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2859 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2860 | final long identity = Binder.clearCallingIdentity(); |
| 2861 | try { |
| 2862 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2863 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2864 | } finally { |
| 2865 | Binder.restoreCallingIdentity(identity); |
| 2866 | } |
| 2867 | } |
| 2868 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2869 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2870 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2871 | if (!isSubscriptionMccMnc) { |
| 2872 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2873 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2874 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2875 | if (phone == null) { |
| 2876 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2877 | } |
| 2878 | final long identity = Binder.clearCallingIdentity(); |
| 2879 | try { |
| 2880 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2881 | } finally { |
| 2882 | Binder.restoreCallingIdentity(identity); |
| 2883 | } |
| 2884 | } |
| 2885 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2886 | // |
| 2887 | // Internal helper methods. |
| 2888 | // |
| 2889 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2890 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2891 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2892 | * |
| 2893 | * @throws SecurityException if the caller does not have the required permission |
| 2894 | */ |
| 2895 | private void enforceModifyPermission() { |
| 2896 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2897 | } |
| 2898 | |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 2899 | /** |
| 2900 | * Make sure the caller is system. |
| 2901 | * |
| 2902 | * @throws SecurityException if the caller is not system. |
| 2903 | */ |
| 2904 | private void enforceSystemCaller() { |
| 2905 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 2906 | throw new SecurityException("Caller must be system"); |
| 2907 | } |
| 2908 | } |
| 2909 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 2910 | private void enforceActiveEmergencySessionPermission() { |
| 2911 | mApp.enforceCallingOrSelfPermission( |
| 2912 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 2913 | } |
| 2914 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2915 | /** |
| 2916 | * Make sure the caller has the CALL_PHONE permission. |
| 2917 | * |
| 2918 | * @throws SecurityException if the caller does not have the required permission |
| 2919 | */ |
| 2920 | private void enforceCallPermission() { |
| 2921 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2922 | } |
| 2923 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 2924 | private void enforceSettingsPermission() { |
| 2925 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2926 | } |
| 2927 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2928 | private String createTelUrl(String number) { |
| 2929 | if (TextUtils.isEmpty(number)) { |
| 2930 | return null; |
| 2931 | } |
| 2932 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2933 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2934 | } |
| 2935 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2936 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2937 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2938 | } |
| 2939 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2940 | private static void logv(String msg) { |
| 2941 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2942 | } |
| 2943 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2944 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2945 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2946 | } |
| 2947 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2948 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2949 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2950 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2951 | } |
| 2952 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2953 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2954 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2955 | final long identity = Binder.clearCallingIdentity(); |
| 2956 | try { |
| 2957 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2958 | if (phone == null) { |
| 2959 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2960 | } else { |
| 2961 | return phone.getPhoneType(); |
| 2962 | } |
| 2963 | } finally { |
| 2964 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2965 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2966 | } |
| 2967 | |
| 2968 | /** |
| 2969 | * Returns the CDMA ERI icon index to display |
| 2970 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2971 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2972 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 2973 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 2974 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2975 | } |
| 2976 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2977 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2978 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 2979 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2980 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2981 | mApp, subId, callingPackage, callingFeatureId, |
| 2982 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2983 | return -1; |
| 2984 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2985 | |
| 2986 | final long identity = Binder.clearCallingIdentity(); |
| 2987 | try { |
| 2988 | final Phone phone = getPhone(subId); |
| 2989 | if (phone != null) { |
| 2990 | return phone.getCdmaEriIconIndex(); |
| 2991 | } else { |
| 2992 | return -1; |
| 2993 | } |
| 2994 | } finally { |
| 2995 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2996 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2997 | } |
| 2998 | |
| 2999 | /** |
| 3000 | * Returns the CDMA ERI icon mode, |
| 3001 | * 0 - ON |
| 3002 | * 1 - FLASHING |
| 3003 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3004 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3005 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3006 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3007 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3008 | } |
| 3009 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3010 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3011 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3012 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3013 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3014 | mApp, subId, callingPackage, callingFeatureId, |
| 3015 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3016 | return -1; |
| 3017 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3018 | |
| 3019 | final long identity = Binder.clearCallingIdentity(); |
| 3020 | try { |
| 3021 | final Phone phone = getPhone(subId); |
| 3022 | if (phone != null) { |
| 3023 | return phone.getCdmaEriIconMode(); |
| 3024 | } else { |
| 3025 | return -1; |
| 3026 | } |
| 3027 | } finally { |
| 3028 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3029 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3030 | } |
| 3031 | |
| 3032 | /** |
| 3033 | * Returns the CDMA ERI text, |
| 3034 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3035 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3036 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3037 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3038 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3039 | } |
| 3040 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3041 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3042 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3043 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3044 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3045 | mApp, subId, callingPackage, callingFeatureId, |
| 3046 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3047 | return null; |
| 3048 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3049 | |
| 3050 | final long identity = Binder.clearCallingIdentity(); |
| 3051 | try { |
| 3052 | final Phone phone = getPhone(subId); |
| 3053 | if (phone != null) { |
| 3054 | return phone.getCdmaEriText(); |
| 3055 | } else { |
| 3056 | return null; |
| 3057 | } |
| 3058 | } finally { |
| 3059 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3060 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3061 | } |
| 3062 | |
| 3063 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3064 | * Returns the CDMA MDN. |
| 3065 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3066 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3067 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3068 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3069 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3070 | |
| 3071 | final long identity = Binder.clearCallingIdentity(); |
| 3072 | try { |
| 3073 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3074 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3075 | return phone.getLine1Number(); |
| 3076 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3077 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3078 | return null; |
| 3079 | } |
| 3080 | } finally { |
| 3081 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3082 | } |
| 3083 | } |
| 3084 | |
| 3085 | /** |
| 3086 | * Returns the CDMA MIN. |
| 3087 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3088 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3089 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3090 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3091 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3092 | |
| 3093 | final long identity = Binder.clearCallingIdentity(); |
| 3094 | try { |
| 3095 | final Phone phone = getPhone(subId); |
| 3096 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3097 | return phone.getCdmaMin(); |
| 3098 | } else { |
| 3099 | return null; |
| 3100 | } |
| 3101 | } finally { |
| 3102 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3103 | } |
| 3104 | } |
| 3105 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3106 | @Override |
| 3107 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3108 | INumberVerificationCallback callback, String callingPackage) { |
| 3109 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3110 | != PERMISSION_GRANTED) { |
| 3111 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3112 | } |
| 3113 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3114 | |
| 3115 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3116 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 3117 | throw new SecurityException("Calling package must be configured in the device config"); |
| 3118 | } |
| 3119 | |
| 3120 | if (range == null) { |
| 3121 | throw new NullPointerException("Range must be non-null"); |
| 3122 | } |
| 3123 | |
| 3124 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3125 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3126 | |
| 3127 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3128 | } |
| 3129 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3130 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3131 | * Returns true if CDMA provisioning needs to run. |
| 3132 | */ |
| 3133 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3134 | final long identity = Binder.clearCallingIdentity(); |
| 3135 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3136 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3137 | } finally { |
| 3138 | Binder.restoreCallingIdentity(identity); |
| 3139 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3140 | } |
| 3141 | |
| 3142 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3143 | * Sets the voice mail number of a given subId. |
| 3144 | */ |
| 3145 | @Override |
| 3146 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3147 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3148 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3149 | |
| 3150 | final long identity = Binder.clearCallingIdentity(); |
| 3151 | try { |
| 3152 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3153 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3154 | return success; |
| 3155 | } finally { |
| 3156 | Binder.restoreCallingIdentity(identity); |
| 3157 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3158 | } |
| 3159 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3160 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3161 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3162 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3163 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3164 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3165 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3166 | throw new SecurityException("caller must be system dialer"); |
| 3167 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3168 | |
| 3169 | final long identity = Binder.clearCallingIdentity(); |
| 3170 | try { |
| 3171 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3172 | if (phoneAccountHandle == null) { |
| 3173 | return null; |
| 3174 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3175 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3176 | } finally { |
| 3177 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3178 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3179 | } |
| 3180 | |
| 3181 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3182 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3183 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3184 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3185 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3186 | mApp, subId, callingPackage, callingFeatureId, |
| 3187 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3188 | return null; |
| 3189 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3190 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3191 | final long identity = Binder.clearCallingIdentity(); |
| 3192 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3193 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3194 | } finally { |
| 3195 | Binder.restoreCallingIdentity(identity); |
| 3196 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3197 | } |
| 3198 | |
| 3199 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3200 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3201 | VisualVoicemailSmsFilterSettings settings) { |
| 3202 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3203 | |
| 3204 | final long identity = Binder.clearCallingIdentity(); |
| 3205 | try { |
| 3206 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3207 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3208 | } finally { |
| 3209 | Binder.restoreCallingIdentity(identity); |
| 3210 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3211 | } |
| 3212 | |
| 3213 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3214 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3215 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3216 | |
| 3217 | final long identity = Binder.clearCallingIdentity(); |
| 3218 | try { |
| 3219 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3220 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3221 | } finally { |
| 3222 | Binder.restoreCallingIdentity(identity); |
| 3223 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3224 | } |
| 3225 | |
| 3226 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3227 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3228 | String callingPackage, int subId) { |
| 3229 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3230 | |
| 3231 | final long identity = Binder.clearCallingIdentity(); |
| 3232 | try { |
| 3233 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3234 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3235 | } finally { |
| 3236 | Binder.restoreCallingIdentity(identity); |
| 3237 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3238 | } |
| 3239 | |
| 3240 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3241 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3242 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3243 | |
| 3244 | final long identity = Binder.clearCallingIdentity(); |
| 3245 | try { |
| 3246 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3247 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3248 | } finally { |
| 3249 | Binder.restoreCallingIdentity(identity); |
| 3250 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3251 | } |
| 3252 | |
| 3253 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3254 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3255 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3256 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3257 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3258 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3259 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3260 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3261 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3262 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3263 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3264 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3265 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3266 | * Sets the voice activation state of a given subId. |
| 3267 | */ |
| 3268 | @Override |
| 3269 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3270 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3271 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3272 | |
| 3273 | final long identity = Binder.clearCallingIdentity(); |
| 3274 | try { |
| 3275 | final Phone phone = getPhone(subId); |
| 3276 | if (phone != null) { |
| 3277 | phone.setVoiceActivationState(activationState); |
| 3278 | } else { |
| 3279 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3280 | } |
| 3281 | } finally { |
| 3282 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3283 | } |
| 3284 | } |
| 3285 | |
| 3286 | /** |
| 3287 | * Sets the data activation state of a given subId. |
| 3288 | */ |
| 3289 | @Override |
| 3290 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3291 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3292 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3293 | |
| 3294 | final long identity = Binder.clearCallingIdentity(); |
| 3295 | try { |
| 3296 | final Phone phone = getPhone(subId); |
| 3297 | if (phone != null) { |
| 3298 | phone.setDataActivationState(activationState); |
| 3299 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3300 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3301 | } |
| 3302 | } finally { |
| 3303 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3304 | } |
| 3305 | } |
| 3306 | |
| 3307 | /** |
| 3308 | * Returns the voice activation state of a given subId. |
| 3309 | */ |
| 3310 | @Override |
| 3311 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3312 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3313 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3314 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3315 | final long identity = Binder.clearCallingIdentity(); |
| 3316 | try { |
| 3317 | if (phone != null) { |
| 3318 | return phone.getVoiceActivationState(); |
| 3319 | } else { |
| 3320 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3321 | } |
| 3322 | } finally { |
| 3323 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3324 | } |
| 3325 | } |
| 3326 | |
| 3327 | /** |
| 3328 | * Returns the data activation state of a given subId. |
| 3329 | */ |
| 3330 | @Override |
| 3331 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3332 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3333 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3334 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3335 | final long identity = Binder.clearCallingIdentity(); |
| 3336 | try { |
| 3337 | if (phone != null) { |
| 3338 | return phone.getDataActivationState(); |
| 3339 | } else { |
| 3340 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3341 | } |
| 3342 | } finally { |
| 3343 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3344 | } |
| 3345 | } |
| 3346 | |
| 3347 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3348 | * Returns the unread count of voicemails for a subId |
| 3349 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3350 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3351 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3352 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3353 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3354 | mApp, subId, callingPackage, callingFeatureId, |
| 3355 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3356 | return 0; |
| 3357 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3358 | final long identity = Binder.clearCallingIdentity(); |
| 3359 | try { |
| 3360 | final Phone phone = getPhone(subId); |
| 3361 | if (phone != null) { |
| 3362 | return phone.getVoiceMessageCount(); |
| 3363 | } else { |
| 3364 | return 0; |
| 3365 | } |
| 3366 | } finally { |
| 3367 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3368 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3369 | } |
| 3370 | |
| 3371 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3372 | * returns true, if the device is in a state where both voice and data |
| 3373 | * are supported simultaneously. This can change based on location or network condition. |
| 3374 | */ |
| 3375 | @Override |
| 3376 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3377 | final long identity = Binder.clearCallingIdentity(); |
| 3378 | try { |
| 3379 | final Phone phone = getPhone(subId); |
| 3380 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3381 | } finally { |
| 3382 | Binder.restoreCallingIdentity(identity); |
| 3383 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3384 | } |
| 3385 | |
| 3386 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3387 | * Send the dialer code if called from the current default dialer or the caller has |
| 3388 | * carrier privilege. |
| 3389 | * @param inputCode The dialer code to send |
| 3390 | */ |
| 3391 | @Override |
| 3392 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3393 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3394 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3395 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3396 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3397 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3398 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3399 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3400 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3401 | |
| 3402 | final long identity = Binder.clearCallingIdentity(); |
| 3403 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3404 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3405 | } finally { |
| 3406 | Binder.restoreCallingIdentity(identity); |
| 3407 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3408 | } |
| 3409 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3410 | @Override |
| 3411 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3412 | TelephonyPermissions |
| 3413 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3414 | mApp, subId, "getNetworkSelectionMode"); |
| 3415 | final long identity = Binder.clearCallingIdentity(); |
| 3416 | try { |
| 3417 | if (!isActiveSubscription(subId)) { |
| 3418 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3419 | } |
| 3420 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3421 | } finally { |
| 3422 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3423 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3424 | } |
| 3425 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3426 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3427 | public boolean isInEmergencySmsMode() { |
| 3428 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3429 | final long identity = Binder.clearCallingIdentity(); |
| 3430 | try { |
| 3431 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3432 | if (phone.isInEmergencySmsMode()) { |
| 3433 | return true; |
| 3434 | } |
| 3435 | } |
| 3436 | } finally { |
| 3437 | Binder.restoreCallingIdentity(identity); |
| 3438 | } |
| 3439 | return false; |
| 3440 | } |
| 3441 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3442 | /** |
| 3443 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3444 | * @param subId The subscription to use to check the configuration. |
| 3445 | * @param c The callback that will be used to send the result. |
| 3446 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3447 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3448 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3449 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3450 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3451 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3452 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3453 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3454 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3455 | "IMS not available on device."); |
| 3456 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3457 | final long token = Binder.clearCallingIdentity(); |
| 3458 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3459 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3460 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3461 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3462 | } catch (ImsException e) { |
| 3463 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3464 | } finally { |
| 3465 | Binder.restoreCallingIdentity(token); |
| 3466 | } |
| 3467 | } |
| 3468 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3469 | /** |
| 3470 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3471 | * @param subId The subscription to use to check the configuration. |
| 3472 | * @param c The callback that will be used to send the result. |
| 3473 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3474 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3475 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3476 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3477 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3478 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3479 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3480 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3481 | final long token = Binder.clearCallingIdentity(); |
| 3482 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3483 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3484 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3485 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3486 | } catch (ImsException e) { |
| 3487 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3488 | + "is inactive, ignoring unregister."); |
| 3489 | // If the subscription is no longer active, just return, since the callback |
| 3490 | // will already have been removed internally. |
| 3491 | } finally { |
| 3492 | Binder.restoreCallingIdentity(token); |
| 3493 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3494 | } |
| 3495 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3496 | /** |
| 3497 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3498 | */ |
| 3499 | @Override |
| 3500 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3501 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3502 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3503 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3504 | "IMS not available on device."); |
| 3505 | } |
| 3506 | final long token = Binder.clearCallingIdentity(); |
| 3507 | try { |
| 3508 | Phone phone = getPhone(subId); |
| 3509 | if (phone == null) { |
| 3510 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3511 | + subId + "'"); |
| 3512 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3513 | } |
| 3514 | phone.getImsRegistrationState(regState -> { |
| 3515 | try { |
| 3516 | consumer.accept((regState == null) |
| 3517 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3518 | } catch (RemoteException e) { |
| 3519 | // Ignore if the remote process is no longer available to call back. |
| 3520 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3521 | } |
| 3522 | }); |
| 3523 | } finally { |
| 3524 | Binder.restoreCallingIdentity(token); |
| 3525 | } |
| 3526 | } |
| 3527 | |
| 3528 | /** |
| 3529 | * Get the transport type for the IMS service registration state. |
| 3530 | */ |
| 3531 | @Override |
| 3532 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3533 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3534 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3535 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3536 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3537 | "IMS not available on device."); |
| 3538 | } |
| 3539 | final long token = Binder.clearCallingIdentity(); |
| 3540 | try { |
| 3541 | Phone phone = getPhone(subId); |
| 3542 | if (phone == null) { |
| 3543 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3544 | + subId + "'"); |
| 3545 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3546 | } |
| 3547 | phone.getImsRegistrationTech(regTech -> { |
| 3548 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3549 | int regTechConverted = (regTech == null) |
| 3550 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3551 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3552 | regTechConverted); |
| 3553 | try { |
| 3554 | consumer.accept(regTechConverted); |
| 3555 | } catch (RemoteException e) { |
| 3556 | // Ignore if the remote process is no longer available to call back. |
| 3557 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3558 | } |
| 3559 | }); |
| 3560 | } finally { |
| 3561 | Binder.restoreCallingIdentity(token); |
| 3562 | } |
| 3563 | } |
| 3564 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3565 | /** |
| 3566 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3567 | * @param subId The subscription to use to check the configuration. |
| 3568 | * @param c The callback that will be used to send the result. |
| 3569 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3570 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3571 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3572 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3573 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3574 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3575 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3576 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3577 | "IMS not available on device."); |
| 3578 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3579 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3580 | final long token = Binder.clearCallingIdentity(); |
| 3581 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3582 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3583 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3584 | } catch (ImsException e) { |
| 3585 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3586 | } finally { |
| 3587 | Binder.restoreCallingIdentity(token); |
| 3588 | } |
| 3589 | } |
| 3590 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3591 | /** |
| 3592 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3593 | * @param subId The subscription to use to check the configuration. |
| 3594 | * @param c The callback that will be used to send the result. |
| 3595 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3596 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3597 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3598 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3599 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3600 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3601 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3602 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3603 | |
| 3604 | final long token = Binder.clearCallingIdentity(); |
| 3605 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3606 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3607 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3608 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3609 | } catch (ImsException e) { |
| 3610 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3611 | + "is inactive, ignoring unregister."); |
| 3612 | // If the subscription is no longer active, just return, since the callback |
| 3613 | // will already have been removed internally. |
| 3614 | } finally { |
| 3615 | Binder.restoreCallingIdentity(token); |
| 3616 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3617 | } |
| 3618 | |
| 3619 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3620 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3621 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3622 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3623 | final long token = Binder.clearCallingIdentity(); |
| 3624 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3625 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3626 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3627 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3628 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3629 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3630 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3631 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3632 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3633 | } finally { |
| 3634 | Binder.restoreCallingIdentity(token); |
| 3635 | } |
| 3636 | } |
| 3637 | |
| 3638 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3639 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3640 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3641 | final long token = Binder.clearCallingIdentity(); |
| 3642 | try { |
| 3643 | Phone phone = getPhone(subId); |
| 3644 | if (phone == null) return false; |
| 3645 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3646 | } catch (com.android.ims.ImsException e) { |
| 3647 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3648 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3649 | } finally { |
| 3650 | Binder.restoreCallingIdentity(token); |
| 3651 | } |
| 3652 | } |
| 3653 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3654 | /** |
| 3655 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3656 | * subscription. |
| 3657 | * @param subId The subscription to use to check the configuration. |
| 3658 | * @param callback The callback that will be used to send the result. |
| 3659 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3660 | * @param transportType The transport type of the MmTelFeature capability. |
| 3661 | */ |
| 3662 | @Override |
| 3663 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3664 | int transportType) { |
| 3665 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3666 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3667 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3668 | "IMS not available on device."); |
| 3669 | } |
| 3670 | final long token = Binder.clearCallingIdentity(); |
| 3671 | try { |
| 3672 | int slotId = getSlotIndex(subId); |
| 3673 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3674 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3675 | + subId + "'"); |
| 3676 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3677 | } |
| 3678 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3679 | transportType, aBoolean -> { |
| 3680 | try { |
| 3681 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3682 | } catch (RemoteException e) { |
| 3683 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3684 | + "running. Ignore"); |
| 3685 | } |
| 3686 | }); |
| 3687 | } finally { |
| 3688 | Binder.restoreCallingIdentity(token); |
| 3689 | } |
| 3690 | } |
| 3691 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3692 | /** |
| 3693 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3694 | * @param subId The subscription to use to check the configuration. |
| 3695 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3696 | @Override |
| 3697 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3698 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3699 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3700 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3701 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3702 | final long token = Binder.clearCallingIdentity(); |
| 3703 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3704 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3705 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3706 | } catch (ImsException e) { |
| 3707 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3708 | } finally { |
| 3709 | Binder.restoreCallingIdentity(token); |
| 3710 | } |
| 3711 | } |
| 3712 | |
| 3713 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3714 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3715 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3716 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3717 | final long identity = Binder.clearCallingIdentity(); |
| 3718 | try { |
| 3719 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3720 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3721 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3722 | } catch (ImsException e) { |
| 3723 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3724 | } finally { |
| 3725 | Binder.restoreCallingIdentity(identity); |
| 3726 | } |
| 3727 | } |
| 3728 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3729 | /** |
| 3730 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3731 | * @param subId The subscription to use to check the configuration. |
| 3732 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3733 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3734 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3735 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3736 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3737 | final long identity = Binder.clearCallingIdentity(); |
| 3738 | try { |
| 3739 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3740 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3741 | } catch (ImsException e) { |
| 3742 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3743 | } finally { |
| 3744 | Binder.restoreCallingIdentity(identity); |
| 3745 | } |
| 3746 | } |
| 3747 | |
| 3748 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3749 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3750 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3751 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3752 | final long identity = Binder.clearCallingIdentity(); |
| 3753 | try { |
| 3754 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3755 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3756 | } catch (ImsException e) { |
| 3757 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3758 | } finally { |
| 3759 | Binder.restoreCallingIdentity(identity); |
| 3760 | } |
| 3761 | } |
| 3762 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3763 | /** |
| 3764 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3765 | * @param subId The subscription to use to check the configuration. |
| 3766 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3767 | @Override |
| 3768 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3769 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3770 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3771 | final long identity = Binder.clearCallingIdentity(); |
| 3772 | try { |
| 3773 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3774 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3775 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3776 | } catch (ImsException e) { |
| 3777 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3778 | } finally { |
| 3779 | Binder.restoreCallingIdentity(identity); |
| 3780 | } |
| 3781 | } |
| 3782 | |
| 3783 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3784 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3785 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3786 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3787 | final long identity = Binder.clearCallingIdentity(); |
| 3788 | try { |
| 3789 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3790 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3791 | } catch (ImsException e) { |
| 3792 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3793 | } finally { |
| 3794 | Binder.restoreCallingIdentity(identity); |
| 3795 | } |
| 3796 | } |
| 3797 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3798 | /** |
| 3799 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3800 | * @param subId The subscription to use to check the configuration. |
| 3801 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3802 | @Override |
| 3803 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3804 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3805 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3806 | final long identity = Binder.clearCallingIdentity(); |
| 3807 | try { |
| 3808 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3809 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3810 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3811 | } catch (ImsException e) { |
| 3812 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3813 | } finally { |
| 3814 | Binder.restoreCallingIdentity(identity); |
| 3815 | } |
| 3816 | } |
| 3817 | |
| 3818 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3819 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3820 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3821 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3822 | final long identity = Binder.clearCallingIdentity(); |
| 3823 | try { |
| 3824 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3825 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3826 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3827 | } catch (ImsException e) { |
| 3828 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3829 | } finally { |
| 3830 | Binder.restoreCallingIdentity(identity); |
| 3831 | } |
| 3832 | } |
| 3833 | |
| 3834 | @Override |
| 3835 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3836 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3837 | "setVoWiFiNonPersistent"); |
| 3838 | final long identity = Binder.clearCallingIdentity(); |
| 3839 | try { |
| 3840 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3841 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3842 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3843 | } catch (ImsException e) { |
| 3844 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3845 | } finally { |
| 3846 | Binder.restoreCallingIdentity(identity); |
| 3847 | } |
| 3848 | } |
| 3849 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3850 | /** |
| 3851 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3852 | * @param subId The subscription to use to check the configuration. |
| 3853 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3854 | @Override |
| 3855 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3856 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3857 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3858 | final long identity = Binder.clearCallingIdentity(); |
| 3859 | try { |
| 3860 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3861 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3862 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3863 | } catch (ImsException e) { |
| 3864 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3865 | } finally { |
| 3866 | Binder.restoreCallingIdentity(identity); |
| 3867 | } |
| 3868 | } |
| 3869 | |
| 3870 | @Override |
| 3871 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3872 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3873 | "setVoWiFiModeSetting"); |
| 3874 | final long identity = Binder.clearCallingIdentity(); |
| 3875 | try { |
| 3876 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3877 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3878 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3879 | } catch (ImsException e) { |
| 3880 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3881 | } finally { |
| 3882 | Binder.restoreCallingIdentity(identity); |
| 3883 | } |
| 3884 | } |
| 3885 | |
| 3886 | @Override |
| 3887 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3888 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3889 | final long identity = Binder.clearCallingIdentity(); |
| 3890 | try { |
| 3891 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3892 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3893 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3894 | } catch (ImsException e) { |
| 3895 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3896 | } finally { |
| 3897 | Binder.restoreCallingIdentity(identity); |
| 3898 | } |
| 3899 | } |
| 3900 | |
| 3901 | @Override |
| 3902 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3903 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3904 | "setVoWiFiRoamingModeSetting"); |
| 3905 | final long identity = Binder.clearCallingIdentity(); |
| 3906 | try { |
| 3907 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3908 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3909 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3910 | } catch (ImsException e) { |
| 3911 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3912 | } finally { |
| 3913 | Binder.restoreCallingIdentity(identity); |
| 3914 | } |
| 3915 | } |
| 3916 | |
| 3917 | @Override |
| 3918 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3919 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3920 | "setRttCapabilityEnabled"); |
| 3921 | final long identity = Binder.clearCallingIdentity(); |
| 3922 | try { |
| 3923 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3924 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3925 | } catch (ImsException e) { |
| 3926 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3927 | } finally { |
| 3928 | Binder.restoreCallingIdentity(identity); |
| 3929 | } |
| 3930 | } |
| 3931 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3932 | /** |
| 3933 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3934 | * @param subId The subscription to use to check the configuration. |
| 3935 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3936 | @Override |
| 3937 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3938 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3939 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3940 | final long identity = Binder.clearCallingIdentity(); |
| 3941 | try { |
| 3942 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3943 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3944 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3945 | } catch (ImsException e) { |
| 3946 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3947 | } finally { |
| 3948 | Binder.restoreCallingIdentity(identity); |
| 3949 | } |
| 3950 | } |
| 3951 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3952 | @Override |
| 3953 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3954 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3955 | final long identity = Binder.clearCallingIdentity(); |
| 3956 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 3957 | if (!isImsAvailableOnDevice()) { |
| 3958 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3959 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 3960 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3961 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3962 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3963 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3964 | } catch (ImsException e) { |
| 3965 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3966 | } finally { |
| 3967 | Binder.restoreCallingIdentity(identity); |
| 3968 | } |
| 3969 | } |
| 3970 | |
| 3971 | @Override |
| 3972 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3973 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3974 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3975 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3976 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3977 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3978 | try { |
| 3979 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3980 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3981 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3982 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3983 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3984 | + "is inactive, ignoring unregister."); |
| 3985 | // If the subscription is no longer active, just return, since the callback will already |
| 3986 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3987 | } finally { |
| 3988 | Binder.restoreCallingIdentity(identity); |
| 3989 | } |
| 3990 | } |
| 3991 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3992 | |
| 3993 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 3994 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3995 | message); |
| 3996 | } |
| 3997 | |
| 3998 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 3999 | boolean isMmtelCapability) { |
| 4000 | Phone phone = getPhone(subId); |
| 4001 | if (phone == null) { |
| 4002 | loge("phone instance null for subid " + subId); |
| 4003 | return false; |
| 4004 | } |
| 4005 | if (isMmtelCapability) { |
| 4006 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4007 | return false; |
| 4008 | } |
| 4009 | } else { |
| 4010 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4011 | return false; |
| 4012 | } |
| 4013 | } |
| 4014 | return true; |
| 4015 | } |
| 4016 | |
| 4017 | @Override |
| 4018 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4019 | boolean isProvisioned) { |
| 4020 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4021 | |
| 4022 | final long identity = Binder.clearCallingIdentity(); |
| 4023 | try { |
| 4024 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4025 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4026 | return; |
| 4027 | } |
| 4028 | |
| 4029 | // this capability requires provisioning, route to the correct API. |
| 4030 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4031 | switch (capability) { |
| 4032 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4033 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4034 | ims.setEabProvisioned(isProvisioned); |
| 4035 | break; |
| 4036 | default: { |
| 4037 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4038 | + "rcs capability '" + capability + "', which does not require " |
| 4039 | + "provisioning."); |
| 4040 | } |
| 4041 | } |
| 4042 | } finally { |
| 4043 | Binder.restoreCallingIdentity(identity); |
| 4044 | } |
| 4045 | |
| 4046 | } |
| 4047 | |
| 4048 | |
| 4049 | @Override |
| 4050 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4051 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4052 | final long identity = Binder.clearCallingIdentity(); |
| 4053 | try { |
| 4054 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4055 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4056 | return true; |
| 4057 | } |
| 4058 | |
| 4059 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4060 | switch (capability) { |
| 4061 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4062 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4063 | return ims.isEabProvisionedOnDevice(); |
| 4064 | |
| 4065 | default: { |
| 4066 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4067 | + "capability '" + capability + "', which does not require " |
| 4068 | + "provisioning."); |
| 4069 | } |
| 4070 | } |
| 4071 | |
| 4072 | } finally { |
| 4073 | Binder.restoreCallingIdentity(identity); |
| 4074 | } |
| 4075 | } |
| 4076 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4077 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4078 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4079 | boolean isProvisioned) { |
| 4080 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4081 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4082 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4083 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4084 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4085 | final long identity = Binder.clearCallingIdentity(); |
| 4086 | try { |
| 4087 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4088 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4089 | return; |
| 4090 | } |
| 4091 | |
| 4092 | // this capability requires provisioning, route to the correct API. |
| 4093 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4094 | switch (capability) { |
| 4095 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4096 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4097 | ims.setVolteProvisioned(isProvisioned); |
| 4098 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4099 | ims.setWfcProvisioned(isProvisioned); |
| 4100 | } |
| 4101 | break; |
| 4102 | } |
| 4103 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4104 | // There is currently no difference in VT provisioning type. |
| 4105 | ims.setVtProvisioned(isProvisioned); |
| 4106 | break; |
| 4107 | } |
| 4108 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4109 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4110 | // change the capability of the feature instead if needed. |
| 4111 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4112 | == isProvisioned) { |
| 4113 | // No change in provisioning. |
| 4114 | return; |
| 4115 | } |
| 4116 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4117 | try { |
| 4118 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4119 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4120 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4121 | + ", Exception" + e.getMessage()); |
| 4122 | } |
| 4123 | break; |
| 4124 | } |
| 4125 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4126 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4127 | + "MmTel capability '" + capability + "', which does not require " |
| 4128 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4129 | } |
| 4130 | } |
| 4131 | |
| 4132 | } finally { |
| 4133 | Binder.restoreCallingIdentity(identity); |
| 4134 | } |
| 4135 | } |
| 4136 | |
| 4137 | @Override |
| 4138 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4139 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4140 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4141 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4142 | } |
| 4143 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4144 | final long identity = Binder.clearCallingIdentity(); |
| 4145 | try { |
| 4146 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4147 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4148 | return true; |
| 4149 | } |
| 4150 | |
| 4151 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4152 | switch (capability) { |
| 4153 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4154 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4155 | return ims.isVolteProvisionedOnDevice(); |
| 4156 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4157 | return ims.isWfcProvisionedOnDevice(); |
| 4158 | } |
| 4159 | // This should never happen, since we are checking tech above to make sure it |
| 4160 | // is either LTE or IWLAN. |
| 4161 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4162 | + "capability."); |
| 4163 | } |
| 4164 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4165 | // There is currently no difference in VT provisioning type. |
| 4166 | return ims.isVtProvisionedOnDevice(); |
| 4167 | } |
| 4168 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4169 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4170 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4171 | } |
| 4172 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4173 | throw new IllegalArgumentException( |
| 4174 | "Tried to get provisioning for MmTel capability '" + capability |
| 4175 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4176 | } |
| 4177 | } |
| 4178 | |
| 4179 | } finally { |
| 4180 | Binder.restoreCallingIdentity(identity); |
| 4181 | } |
| 4182 | } |
| 4183 | |
| 4184 | @Override |
| 4185 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4186 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4187 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4188 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4189 | } |
| 4190 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4191 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4192 | return (provisionedBits & capability) > 0; |
| 4193 | } |
| 4194 | |
| 4195 | @Override |
| 4196 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4197 | boolean isProvisioned) { |
| 4198 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4199 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4200 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4201 | } |
| 4202 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4203 | "setProvisioningStatusForCapability"); |
| 4204 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4205 | // If the current provisioning status for capability already matches isProvisioned, |
| 4206 | // do nothing. |
| 4207 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4208 | return; |
| 4209 | } |
| 4210 | if (isProvisioned) { |
| 4211 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4212 | } else { |
| 4213 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4214 | } |
| 4215 | } |
| 4216 | |
| 4217 | /** |
| 4218 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4219 | * technology. The bitfield should mirror the bitfield defined by |
| 4220 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4221 | */ |
| 4222 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4223 | String key = getMmTelProvisioningKey(subId, tech); |
| 4224 | // Default is no capabilities are provisioned. |
| 4225 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4226 | } |
| 4227 | |
| 4228 | /** |
| 4229 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4230 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4231 | * technology specified. |
| 4232 | * |
| 4233 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4234 | */ |
| 4235 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4236 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4237 | String key = getMmTelProvisioningKey(subId, tech); |
| 4238 | editor.putInt(key, newField); |
| 4239 | editor.commit(); |
| 4240 | } |
| 4241 | |
| 4242 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4243 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4244 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4245 | } |
| 4246 | |
| 4247 | /** |
| 4248 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4249 | * carrier associated with the subscription id. |
| 4250 | */ |
| 4251 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4252 | int capability) { |
| 4253 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4254 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4255 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4256 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4257 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4258 | false); |
| 4259 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4260 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4261 | |
| 4262 | // First check to make sure that the capability requires provisioning. |
| 4263 | switch (capability) { |
| 4264 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4265 | // intentional fallthrough |
| 4266 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4267 | if (requireVoiceVtProvisioning) { |
| 4268 | // Voice and Video requires provisioning |
| 4269 | return true; |
| 4270 | } |
| 4271 | break; |
| 4272 | } |
| 4273 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4274 | if (requireUtProvisioning) { |
| 4275 | // UT requires provisioning |
| 4276 | return true; |
| 4277 | } |
| 4278 | break; |
| 4279 | } |
| 4280 | } |
| 4281 | return false; |
| 4282 | } |
| 4283 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4284 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4285 | int capability) { |
| 4286 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4287 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4288 | |
| 4289 | boolean requireRcsProvisioning = c.getBoolean( |
| 4290 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4291 | |
| 4292 | // First check to make sure that the capability requires provisioning. |
| 4293 | switch (capability) { |
| 4294 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4295 | // intentional fallthrough |
| 4296 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4297 | if (requireRcsProvisioning) { |
| 4298 | // OPTION or PRESENCE requires provisioning |
| 4299 | return true; |
| 4300 | } |
| 4301 | break; |
| 4302 | } |
| 4303 | } |
| 4304 | return false; |
| 4305 | } |
| 4306 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4307 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4308 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4309 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4310 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4311 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4312 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4313 | final long identity = Binder.clearCallingIdentity(); |
| 4314 | try { |
| 4315 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4316 | int slotId = getSlotIndex(subId); |
| 4317 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4318 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4319 | + subId + "' for key:" + key); |
| 4320 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4321 | } |
| 4322 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4323 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4324 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4325 | + subId + "' for key:" + key); |
| 4326 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4327 | } finally { |
| 4328 | Binder.restoreCallingIdentity(identity); |
| 4329 | } |
| 4330 | } |
| 4331 | |
| 4332 | @Override |
| 4333 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4334 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4335 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4336 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4337 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4338 | final long identity = Binder.clearCallingIdentity(); |
| 4339 | try { |
| 4340 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4341 | int slotId = getSlotIndex(subId); |
| 4342 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4343 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4344 | + subId + "' for key:" + key); |
| 4345 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4346 | } |
| 4347 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4348 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4349 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4350 | + subId + "' for key:" + key); |
| 4351 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4352 | } finally { |
| 4353 | Binder.restoreCallingIdentity(identity); |
| 4354 | } |
| 4355 | } |
| 4356 | |
| 4357 | @Override |
| 4358 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4359 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4360 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4361 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4362 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4363 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4364 | final long identity = Binder.clearCallingIdentity(); |
| 4365 | try { |
| 4366 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4367 | int slotId = getSlotIndex(subId); |
| 4368 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4369 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4370 | + subId + "' for key:" + key); |
| 4371 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4372 | } |
| 4373 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4374 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4375 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4376 | + "' for key:" + key); |
| 4377 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4378 | } finally { |
| 4379 | Binder.restoreCallingIdentity(identity); |
| 4380 | } |
| 4381 | } |
| 4382 | |
| 4383 | @Override |
| 4384 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4385 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4386 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4387 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4388 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4389 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4390 | final long identity = Binder.clearCallingIdentity(); |
| 4391 | try { |
| 4392 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4393 | int slotId = getSlotIndex(subId); |
| 4394 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4395 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4396 | + subId + "' for key:" + key); |
| 4397 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4398 | } |
| 4399 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4400 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4401 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4402 | + "' for key:" + key); |
| 4403 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4404 | } finally { |
| 4405 | Binder.restoreCallingIdentity(identity); |
| 4406 | } |
| 4407 | } |
| 4408 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4409 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4410 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4411 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4412 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4413 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4414 | } |
| 4415 | return slotId; |
| 4416 | } |
| 4417 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4418 | private int getSlotIndex(int subId) { |
| 4419 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4420 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4421 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4422 | } |
| 4423 | return slotId; |
| 4424 | } |
| 4425 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4426 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4427 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4428 | */ |
| 4429 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4430 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4431 | String callingFeatureId) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4432 | final int targetSdk = getTargetSdk(callingPackage); |
| 4433 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4434 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4435 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4436 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4437 | mApp, subId, callingPackage, callingFeatureId, |
| 4438 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4439 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4440 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4441 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4442 | final long identity = Binder.clearCallingIdentity(); |
| 4443 | try { |
| 4444 | final Phone phone = getPhone(subId); |
| 4445 | if (phone != null) { |
| 4446 | return phone.getServiceState().getDataNetworkType(); |
| 4447 | } else { |
| 4448 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4449 | } |
| 4450 | } finally { |
| 4451 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4452 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4453 | } |
| 4454 | |
| 4455 | /** |
| 4456 | * Returns the data network type |
| 4457 | */ |
| 4458 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4459 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4460 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4461 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4462 | } |
| 4463 | |
| 4464 | /** |
| 4465 | * Returns the data network type for a subId |
| 4466 | */ |
| 4467 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4468 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4469 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4470 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4471 | mApp, subId, callingPackage, callingFeatureId, |
| 4472 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4473 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4474 | } |
| 4475 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4476 | final long identity = Binder.clearCallingIdentity(); |
| 4477 | try { |
| 4478 | final Phone phone = getPhone(subId); |
| 4479 | if (phone != null) { |
| 4480 | return phone.getServiceState().getDataNetworkType(); |
| 4481 | } else { |
| 4482 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4483 | } |
| 4484 | } finally { |
| 4485 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4486 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4487 | } |
| 4488 | |
| 4489 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4490 | * Returns the Voice network type for a subId |
| 4491 | */ |
| 4492 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4493 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4494 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4495 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4496 | mApp, subId, callingPackage, callingFeatureId, |
| 4497 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4498 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4499 | } |
| 4500 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4501 | final long identity = Binder.clearCallingIdentity(); |
| 4502 | try { |
| 4503 | final Phone phone = getPhone(subId); |
| 4504 | if (phone != null) { |
| 4505 | return phone.getServiceState().getVoiceNetworkType(); |
| 4506 | } else { |
| 4507 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4508 | } |
| 4509 | } finally { |
| 4510 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4511 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4512 | } |
| 4513 | |
| 4514 | /** |
| 4515 | * @return true if a ICC card is present |
| 4516 | */ |
| 4517 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4518 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4519 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4520 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4521 | } |
| 4522 | |
| 4523 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4524 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4525 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4526 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4527 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4528 | final long identity = Binder.clearCallingIdentity(); |
| 4529 | try { |
| 4530 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4531 | if (phone != null) { |
| 4532 | return phone.getIccCard().hasIccCard(); |
| 4533 | } else { |
| 4534 | return false; |
| 4535 | } |
| 4536 | } finally { |
| 4537 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4538 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4539 | } |
| 4540 | |
| 4541 | /** |
| 4542 | * Return if the current radio is LTE on CDMA. This |
| 4543 | * is a tri-state return value as for a period of time |
| 4544 | * the mode may be unknown. |
| 4545 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4546 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4547 | * @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] | 4548 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4549 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4550 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4551 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4552 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4553 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4554 | } |
| 4555 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4556 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4557 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4558 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4559 | try { |
| 4560 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4561 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4562 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4563 | } |
| 4564 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4565 | final long identity = Binder.clearCallingIdentity(); |
| 4566 | try { |
| 4567 | final Phone phone = getPhone(subId); |
| 4568 | if (phone == null) { |
| 4569 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4570 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 4571 | return TelephonyProperties.lte_on_cdma_device() |
| 4572 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4573 | } |
| 4574 | } finally { |
| 4575 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4576 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4577 | } |
| 4578 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4579 | /** |
| 4580 | * {@hide} |
| 4581 | * Returns Default subId, 0 in the case of single standby. |
| 4582 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4583 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4584 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4585 | } |
| 4586 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4587 | private int getSlotForDefaultSubscription() { |
| 4588 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4589 | } |
| 4590 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4591 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4592 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4593 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4594 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4595 | private boolean isActiveSubscription(int subId) { |
| 4596 | return mSubscriptionController.isActiveSubId(subId); |
| 4597 | } |
| 4598 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4599 | /** |
| 4600 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4601 | */ |
| 4602 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4603 | final long identity = Binder.clearCallingIdentity(); |
| 4604 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4605 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4606 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4607 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4608 | } finally { |
| 4609 | Binder.restoreCallingIdentity(identity); |
| 4610 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4611 | } |
| 4612 | |
| 4613 | /** |
| 4614 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4615 | */ |
| 4616 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4617 | final long identity = Binder.clearCallingIdentity(); |
| 4618 | try { |
| 4619 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4620 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4621 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4622 | } finally { |
| 4623 | Binder.restoreCallingIdentity(identity); |
| 4624 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4625 | } |
| 4626 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4627 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4628 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4629 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4630 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4631 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4632 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4633 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4634 | if (phoneId == -1) { |
| 4635 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4636 | + " does not correspond to an active phone"); |
| 4637 | } |
| 4638 | return PhoneFactory.getPhone(phoneId); |
| 4639 | } |
| 4640 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4641 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4642 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4643 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4644 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4645 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4646 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4647 | if (DBG) { |
| 4648 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4649 | } |
| 4650 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4651 | p2); |
| 4652 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4653 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4654 | |
| 4655 | @Override |
| 4656 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4657 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4658 | enforceModifyPermission(); |
| 4659 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4660 | if (DBG) { |
| 4661 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4662 | } |
| 4663 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4664 | callingPackage, aid, p2); |
| 4665 | } |
| 4666 | |
| 4667 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4668 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4669 | final long identity = Binder.clearCallingIdentity(); |
| 4670 | try { |
| 4671 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4672 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4673 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4674 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4675 | if (bestComponent == null |
| 4676 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4677 | loge("The calling package is not allowed to access ISD-R."); |
| 4678 | throw new SecurityException( |
| 4679 | "The calling package is not allowed to access ISD-R."); |
| 4680 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4681 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4682 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4683 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4684 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4685 | null /* workSource */); |
| 4686 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4687 | return response; |
| 4688 | } finally { |
| 4689 | Binder.restoreCallingIdentity(identity); |
| 4690 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4691 | } |
| 4692 | |
| 4693 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4694 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4695 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4696 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4697 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4698 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4699 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4700 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4701 | @Override |
| 4702 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4703 | enforceModifyPermission(); |
| 4704 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4705 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4706 | channel); |
| 4707 | } |
| 4708 | |
| 4709 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4710 | final long identity = Binder.clearCallingIdentity(); |
| 4711 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4712 | if (channel < 0) { |
| 4713 | return false; |
| 4714 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4715 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4716 | null /* workSource */); |
| 4717 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4718 | return success; |
| 4719 | } finally { |
| 4720 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4721 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4722 | } |
| 4723 | |
| 4724 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4725 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4726 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4727 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4728 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4729 | if (DBG) { |
| 4730 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4731 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4732 | + p3 + " data=" + data); |
| 4733 | } |
| 4734 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4735 | command, p1, p2, p3, data); |
| 4736 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4737 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4738 | @Override |
| 4739 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4740 | int command, int p1, int p2, int p3, String data) { |
| 4741 | enforceModifyPermission(); |
| 4742 | if (DBG) { |
| 4743 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4744 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4745 | + p3 + " data=" + data); |
| 4746 | } |
| 4747 | return iccTransmitApduLogicalChannelWithPermission( |
| 4748 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4749 | data); |
| 4750 | } |
| 4751 | |
| 4752 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4753 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4754 | final long identity = Binder.clearCallingIdentity(); |
| 4755 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4756 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4757 | return ""; |
| 4758 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4759 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4760 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4761 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4762 | null /* workSource */); |
| 4763 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4764 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4765 | // Append the returned status code to the end of the response payload. |
| 4766 | String s = Integer.toHexString( |
| 4767 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4768 | if (response.payload != null) { |
| 4769 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4770 | } |
| 4771 | return s; |
| 4772 | } finally { |
| 4773 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4774 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4775 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4776 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4777 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4778 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4779 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4780 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4781 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4782 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4783 | if (DBG) { |
| 4784 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4785 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4786 | } |
| 4787 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4788 | cla, command, p1, p2, p3, data); |
| 4789 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4790 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4791 | @Override |
| 4792 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4793 | int command, int p1, int p2, int p3, String data) { |
| 4794 | enforceModifyPermission(); |
| 4795 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4796 | if (DBG) { |
| 4797 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4798 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4799 | + " data=" + data); |
| 4800 | } |
| 4801 | |
| 4802 | return iccTransmitApduBasicChannelWithPermission( |
| 4803 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4804 | p2, p3, data); |
| 4805 | } |
| 4806 | |
| 4807 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4808 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4809 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4810 | final long identity = Binder.clearCallingIdentity(); |
| 4811 | try { |
| 4812 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4813 | && TextUtils.equals(ISDR_AID, data)) { |
| 4814 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4815 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4816 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4817 | if (bestComponent == null |
| 4818 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4819 | loge("The calling package is not allowed to select ISD-R."); |
| 4820 | throw new SecurityException( |
| 4821 | "The calling package is not allowed to select ISD-R."); |
| 4822 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4823 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4824 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4825 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4826 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4827 | null /* workSource */); |
| 4828 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4829 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4830 | // Append the returned status code to the end of the response payload. |
| 4831 | String s = Integer.toHexString( |
| 4832 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4833 | if (response.payload != null) { |
| 4834 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4835 | } |
| 4836 | return s; |
| 4837 | } finally { |
| 4838 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4839 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4840 | } |
| 4841 | |
| 4842 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4843 | 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] | 4844 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4845 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4846 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4847 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4848 | final long identity = Binder.clearCallingIdentity(); |
| 4849 | try { |
| 4850 | if (DBG) { |
| 4851 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4852 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4853 | } |
| 4854 | |
| 4855 | IccIoResult response = |
| 4856 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4857 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4858 | subId); |
| 4859 | |
| 4860 | if (DBG) { |
| 4861 | log("Exchange SIM_IO [R]" + response); |
| 4862 | } |
| 4863 | |
| 4864 | byte[] result = null; |
| 4865 | int length = 2; |
| 4866 | if (response.payload != null) { |
| 4867 | length = 2 + response.payload.length; |
| 4868 | result = new byte[length]; |
| 4869 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4870 | } else { |
| 4871 | result = new byte[length]; |
| 4872 | } |
| 4873 | |
| 4874 | result[length - 1] = (byte) response.sw2; |
| 4875 | result[length - 2] = (byte) response.sw1; |
| 4876 | return result; |
| 4877 | } finally { |
| 4878 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4879 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4880 | } |
| 4881 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4882 | /** |
| 4883 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4884 | * on a particular subscription |
| 4885 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4886 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 4887 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4888 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4889 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4890 | return null; |
| 4891 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4892 | |
| 4893 | final long identity = Binder.clearCallingIdentity(); |
| 4894 | try { |
| 4895 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4896 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4897 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4898 | return null; |
| 4899 | } |
| 4900 | Object response = sendRequest( |
| 4901 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4902 | if (response instanceof String[]) { |
| 4903 | return (String[]) response; |
| 4904 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4905 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4906 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4907 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4908 | } finally { |
| 4909 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4910 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4911 | } |
| 4912 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4913 | /** |
| 4914 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 4915 | * subscription. |
| 4916 | * |
| 4917 | * @param subId the id of the subscription. |
| 4918 | * @param appType the uicc app type, must be USIM or SIM. |
| 4919 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 4920 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4921 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4922 | * @return number of fplmns that is successfully written to the SIM. |
| 4923 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4924 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 4925 | String callingFeatureId) { |
| 4926 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 4927 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4928 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 4929 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 4930 | } |
| 4931 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 4932 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4933 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 4934 | } |
| 4935 | if (fplmns == null) { |
| 4936 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 4937 | } |
| 4938 | for (String fplmn : fplmns) { |
| 4939 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 4940 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 4941 | } |
| 4942 | } |
| 4943 | final long identity = Binder.clearCallingIdentity(); |
| 4944 | try { |
| 4945 | Object response = sendRequest( |
| 4946 | CMD_SET_FORBIDDEN_PLMNS, |
| 4947 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 4948 | subId); |
| 4949 | return (int) response; |
| 4950 | } finally { |
| 4951 | Binder.restoreCallingIdentity(identity); |
| 4952 | } |
| 4953 | } |
| 4954 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4955 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4956 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4957 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4958 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4959 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4960 | final long identity = Binder.clearCallingIdentity(); |
| 4961 | try { |
| 4962 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4963 | if (response.payload == null) { |
| 4964 | return ""; |
| 4965 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4966 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4967 | // Append the returned status code to the end of the response payload. |
| 4968 | String s = Integer.toHexString( |
| 4969 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4970 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4971 | return s; |
| 4972 | } finally { |
| 4973 | Binder.restoreCallingIdentity(identity); |
| 4974 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4975 | } |
| 4976 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4977 | /** |
| 4978 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4979 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4980 | * |
| 4981 | * @param itemID the ID of the item to read |
| 4982 | * @return the NV item as a String, or null on error. |
| 4983 | */ |
| 4984 | @Override |
| 4985 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4986 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4987 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4988 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4989 | |
| 4990 | final long identity = Binder.clearCallingIdentity(); |
| 4991 | try { |
| 4992 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4993 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4994 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4995 | return value; |
| 4996 | } finally { |
| 4997 | Binder.restoreCallingIdentity(identity); |
| 4998 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4999 | } |
| 5000 | |
| 5001 | /** |
| 5002 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5003 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5004 | * |
| 5005 | * @param itemID the ID of the item to read |
| 5006 | * @param itemValue the value to write, as a String |
| 5007 | * @return true on success; false on any failure |
| 5008 | */ |
| 5009 | @Override |
| 5010 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5011 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5012 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5013 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5014 | |
| 5015 | final long identity = Binder.clearCallingIdentity(); |
| 5016 | try { |
| 5017 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5018 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5019 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5020 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5021 | return success; |
| 5022 | } finally { |
| 5023 | Binder.restoreCallingIdentity(identity); |
| 5024 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5025 | } |
| 5026 | |
| 5027 | /** |
| 5028 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5029 | * Used for device configuration by some CDMA operators. |
| 5030 | * |
| 5031 | * @param preferredRoamingList byte array containing the new PRL |
| 5032 | * @return true on success; false on any failure |
| 5033 | */ |
| 5034 | @Override |
| 5035 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5036 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5037 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5038 | |
| 5039 | final long identity = Binder.clearCallingIdentity(); |
| 5040 | try { |
| 5041 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5042 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5043 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5044 | return success; |
| 5045 | } finally { |
| 5046 | Binder.restoreCallingIdentity(identity); |
| 5047 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5048 | } |
| 5049 | |
| 5050 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5051 | * 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] | 5052 | * Used for device configuration by some CDMA operators. |
| 5053 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5054 | * @param slotIndex - device slot. |
| 5055 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5056 | * @return true on success; false on any failure |
| 5057 | */ |
| 5058 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5059 | public boolean resetModemConfig(int slotIndex) { |
| 5060 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5061 | if (phone != null) { |
| 5062 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5063 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5064 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5065 | final long identity = Binder.clearCallingIdentity(); |
| 5066 | try { |
| 5067 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5068 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5069 | return success; |
| 5070 | } finally { |
| 5071 | Binder.restoreCallingIdentity(identity); |
| 5072 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5073 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5074 | return false; |
| 5075 | } |
| 5076 | |
| 5077 | /** |
| 5078 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5079 | * |
| 5080 | * @param slotIndex - device slot. |
| 5081 | * |
| 5082 | * @return true on success; false on any failure |
| 5083 | */ |
| 5084 | @Override |
| 5085 | public boolean rebootModem(int slotIndex) { |
| 5086 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5087 | if (phone != null) { |
| 5088 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5089 | mApp, phone.getSubId(), "rebootModem"); |
| 5090 | |
| 5091 | final long identity = Binder.clearCallingIdentity(); |
| 5092 | try { |
| 5093 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5094 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5095 | return success; |
| 5096 | } finally { |
| 5097 | Binder.restoreCallingIdentity(identity); |
| 5098 | } |
| 5099 | } |
| 5100 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5101 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5102 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5103 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5104 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5105 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5106 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5107 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5108 | return new String[0]; |
| 5109 | } |
| 5110 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5111 | final long identity = Binder.clearCallingIdentity(); |
| 5112 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5113 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5114 | } finally { |
| 5115 | Binder.restoreCallingIdentity(identity); |
| 5116 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5117 | } |
| 5118 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5119 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5120 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5121 | * {@link #disableIms(int)}. |
| 5122 | * @param slotIndex device slot. |
| 5123 | */ |
| 5124 | public void resetIms(int slotIndex) { |
| 5125 | enforceModifyPermission(); |
| 5126 | |
| 5127 | final long identity = Binder.clearCallingIdentity(); |
| 5128 | try { |
| 5129 | if (mImsResolver == null) { |
| 5130 | // may happen if the does not support IMS. |
| 5131 | return; |
| 5132 | } |
| 5133 | mImsResolver.disableIms(slotIndex); |
| 5134 | mImsResolver.enableIms(slotIndex); |
| 5135 | } finally { |
| 5136 | Binder.restoreCallingIdentity(identity); |
| 5137 | } |
| 5138 | } |
| 5139 | |
| 5140 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5141 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5142 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5143 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5144 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5145 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5146 | |
| 5147 | final long identity = Binder.clearCallingIdentity(); |
| 5148 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5149 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5150 | // may happen if the device does not support IMS. |
| 5151 | return; |
| 5152 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5153 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5154 | } finally { |
| 5155 | Binder.restoreCallingIdentity(identity); |
| 5156 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5157 | } |
| 5158 | |
| 5159 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5160 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5161 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5162 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5163 | public void disableIms(int slotId) { |
| 5164 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5165 | |
| 5166 | final long identity = Binder.clearCallingIdentity(); |
| 5167 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5168 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5169 | // may happen if the device does not support IMS. |
| 5170 | return; |
| 5171 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5172 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5173 | } finally { |
| 5174 | Binder.restoreCallingIdentity(identity); |
| 5175 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5176 | } |
| 5177 | |
| 5178 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5179 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5180 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5181 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5182 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5183 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5184 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5185 | |
| 5186 | final long identity = Binder.clearCallingIdentity(); |
| 5187 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5188 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5189 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5190 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5191 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5192 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5193 | } finally { |
| 5194 | Binder.restoreCallingIdentity(identity); |
| 5195 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5196 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5197 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5198 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5199 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5200 | @Override |
| 5201 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5202 | enforceModifyPermission(); |
| 5203 | |
| 5204 | final long identity = Binder.clearCallingIdentity(); |
| 5205 | try { |
| 5206 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5207 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5208 | } finally { |
| 5209 | Binder.restoreCallingIdentity(identity); |
| 5210 | } |
| 5211 | } |
| 5212 | |
| 5213 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5214 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5215 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5216 | */ |
| 5217 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5218 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5219 | |
| 5220 | final long identity = Binder.clearCallingIdentity(); |
| 5221 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5222 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5223 | // may happen if the device does not support IMS. |
| 5224 | return null; |
| 5225 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5226 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5227 | } finally { |
| 5228 | Binder.restoreCallingIdentity(identity); |
| 5229 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5230 | } |
| 5231 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5232 | /** |
| 5233 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5234 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5235 | */ |
| 5236 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5237 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5238 | |
| 5239 | final long identity = Binder.clearCallingIdentity(); |
| 5240 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5241 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5242 | // may happen if the device does not support IMS. |
| 5243 | return null; |
| 5244 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5245 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5246 | } finally { |
| 5247 | Binder.restoreCallingIdentity(identity); |
| 5248 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5249 | } |
| 5250 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5251 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5252 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5253 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5254 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5255 | * @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] | 5256 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5257 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5258 | * @param packageName The name of the package that the current configuration will be replaced |
| 5259 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5260 | * @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] | 5261 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5262 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5263 | int[] featureTypes, String packageName) { |
| 5264 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5265 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5266 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5267 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5268 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5269 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5270 | final long identity = Binder.clearCallingIdentity(); |
| 5271 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5272 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5273 | // may happen if the device does not support IMS. |
| 5274 | return false; |
| 5275 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5276 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5277 | for (int featureType : featureTypes) { |
| 5278 | featureConfig.put(featureType, packageName); |
| 5279 | } |
| 5280 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5281 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5282 | } finally { |
| 5283 | Binder.restoreCallingIdentity(identity); |
| 5284 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5285 | } |
| 5286 | |
| 5287 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5288 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5289 | * |
| 5290 | * @param slotId The slot that the ImsService is associated with. |
| 5291 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5292 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5293 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5294 | * @return the package name of the ImsService configuration. |
| 5295 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5296 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5297 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5298 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5299 | TelephonyPermissions |
| 5300 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5301 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5302 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5303 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5304 | final long identity = Binder.clearCallingIdentity(); |
| 5305 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5306 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5307 | // may happen if the device does not support IMS. |
| 5308 | return ""; |
| 5309 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5310 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5311 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5312 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5313 | } finally { |
| 5314 | Binder.restoreCallingIdentity(identity); |
| 5315 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5316 | } |
| 5317 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5318 | /** |
| 5319 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5320 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5321 | * @param callback A callback with an integer containing the |
| 5322 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5323 | */ |
| 5324 | @Override |
| 5325 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5326 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5327 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5328 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5329 | "IMS not available on device."); |
| 5330 | } |
| 5331 | final long token = Binder.clearCallingIdentity(); |
| 5332 | try { |
| 5333 | int slotId = getSlotIndex(subId); |
| 5334 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5335 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5336 | + subId + "'"); |
| 5337 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5338 | } |
| 5339 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5340 | try { |
| 5341 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5342 | } catch (RemoteException e) { |
| 5343 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5344 | + "Ignore"); |
| 5345 | } |
| 5346 | }); |
| 5347 | } finally { |
| 5348 | Binder.restoreCallingIdentity(token); |
| 5349 | } |
| 5350 | } |
| 5351 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5352 | public void setImsRegistrationState(boolean registered) { |
| 5353 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5354 | |
| 5355 | final long identity = Binder.clearCallingIdentity(); |
| 5356 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5357 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5358 | } finally { |
| 5359 | Binder.restoreCallingIdentity(identity); |
| 5360 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5361 | } |
| 5362 | |
| 5363 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5364 | * Set the network selection mode to automatic. |
| 5365 | * |
| 5366 | */ |
| 5367 | @Override |
| 5368 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5369 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5370 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5371 | |
| 5372 | final long identity = Binder.clearCallingIdentity(); |
| 5373 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5374 | if (!isActiveSubscription(subId)) { |
| 5375 | return; |
| 5376 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5377 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 5378 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 5379 | } finally { |
| 5380 | Binder.restoreCallingIdentity(identity); |
| 5381 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5382 | } |
| 5383 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5384 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5385 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5386 | * |
| 5387 | * @param subId the id of the subscription. |
| 5388 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5389 | * the operator to attach to. |
| 5390 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5391 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5392 | * normal network selection next time. |
| 5393 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5394 | */ |
| 5395 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5396 | public boolean setNetworkSelectionModeManual( |
| 5397 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5398 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5399 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5400 | |
| 5401 | if (!isActiveSubscription(subId)) { |
| 5402 | return false; |
| 5403 | } |
| 5404 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5405 | final long identity = Binder.clearCallingIdentity(); |
| 5406 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5407 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5408 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5409 | if (DBG) { |
| 5410 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5411 | + " operator: " + operatorInfo); |
| 5412 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5413 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5414 | } finally { |
| 5415 | Binder.restoreCallingIdentity(identity); |
| 5416 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5417 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5418 | /** |
| 5419 | * Get the manual network selection |
| 5420 | * |
| 5421 | * @param subId the id of the subscription. |
| 5422 | * |
| 5423 | * @return the previously saved user selected PLMN |
| 5424 | */ |
| 5425 | @Override |
| 5426 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5427 | TelephonyPermissions |
| 5428 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5429 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5430 | |
| 5431 | final long identity = Binder.clearCallingIdentity(); |
| 5432 | try { |
| 5433 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5434 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5435 | } |
| 5436 | |
| 5437 | final Phone phone = getPhone(subId); |
| 5438 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5439 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5440 | } |
| 5441 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5442 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5443 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5444 | } finally { |
| 5445 | Binder.restoreCallingIdentity(identity); |
| 5446 | } |
| 5447 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5448 | |
| 5449 | /** |
| 5450 | * Scans for available networks. |
| 5451 | */ |
| 5452 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5453 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5454 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5455 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5456 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5457 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5458 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5459 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5460 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5461 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5462 | .setCallingPid(Binder.getCallingPid()) |
| 5463 | .setCallingUid(Binder.getCallingUid()) |
| 5464 | .setMethod("getCellNetworkScanResults") |
| 5465 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 5466 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5467 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5468 | .build()); |
| 5469 | switch (locationResult) { |
| 5470 | case DENIED_HARD: |
| 5471 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5472 | case DENIED_SOFT: |
| 5473 | return null; |
| 5474 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5475 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5476 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5477 | try { |
| 5478 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5479 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5480 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5481 | } finally { |
| 5482 | Binder.restoreCallingIdentity(identity); |
| 5483 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5484 | } |
| 5485 | |
| 5486 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5487 | * Get the call forwarding info, given the call forwarding reason. |
| 5488 | */ |
| 5489 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5490 | public void getCallForwarding(int subId, int callForwardingReason, |
| 5491 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5492 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5493 | long identity = Binder.clearCallingIdentity(); |
| 5494 | try { |
| 5495 | if (DBG) { |
| 5496 | log("getCallForwarding: subId " + subId |
| 5497 | + " callForwardingReason" + callForwardingReason); |
| 5498 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5499 | |
| 5500 | Phone phone = getPhone(subId); |
| 5501 | if (phone == null) { |
| 5502 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5503 | callback.onError( |
| 5504 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5505 | } catch (RemoteException e) { |
| 5506 | // ignore |
| 5507 | } |
| 5508 | return; |
| 5509 | } |
| 5510 | |
| 5511 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 5512 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 5513 | @Override |
| 5514 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 5515 | try { |
| 5516 | callback.onCallForwardingInfoAvailable(info); |
| 5517 | } catch (RemoteException e) { |
| 5518 | // ignore |
| 5519 | } |
| 5520 | } |
| 5521 | |
| 5522 | @Override |
| 5523 | public void onError(int error) { |
| 5524 | try { |
| 5525 | callback.onError(error); |
| 5526 | } catch (RemoteException e) { |
| 5527 | // ignore |
| 5528 | } |
| 5529 | } |
| 5530 | }); |
| 5531 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5532 | } finally { |
| 5533 | Binder.restoreCallingIdentity(identity); |
| 5534 | } |
| 5535 | } |
| 5536 | |
| 5537 | /** |
| 5538 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5539 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5540 | */ |
| 5541 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5542 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 5543 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5544 | enforceModifyPermission(); |
| 5545 | long identity = Binder.clearCallingIdentity(); |
| 5546 | try { |
| 5547 | if (DBG) { |
| 5548 | log("setCallForwarding: subId " + subId |
| 5549 | + " callForwardingInfo" + callForwardingInfo); |
| 5550 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5551 | |
| 5552 | Phone phone = getPhone(subId); |
| 5553 | if (phone == null) { |
| 5554 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5555 | callback.accept( |
| 5556 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5557 | } catch (RemoteException e) { |
| 5558 | // ignore |
| 5559 | } |
| 5560 | return; |
| 5561 | } |
| 5562 | |
| 5563 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 5564 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5565 | |
| 5566 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5567 | } finally { |
| 5568 | Binder.restoreCallingIdentity(identity); |
| 5569 | } |
| 5570 | } |
| 5571 | |
| 5572 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5573 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5574 | */ |
| 5575 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5576 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5577 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5578 | long identity = Binder.clearCallingIdentity(); |
| 5579 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5580 | |
| 5581 | Phone phone = getPhone(subId); |
| 5582 | if (phone == null) { |
| 5583 | try { |
| 5584 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5585 | } catch (RemoteException e) { |
| 5586 | // ignore |
| 5587 | } |
| 5588 | return; |
| 5589 | } |
| 5590 | |
| 5591 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 5592 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5593 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5594 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5595 | } finally { |
| 5596 | Binder.restoreCallingIdentity(identity); |
| 5597 | } |
| 5598 | } |
| 5599 | |
| 5600 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5601 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5602 | */ |
| 5603 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5604 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5605 | enforceModifyPermission(); |
| 5606 | long identity = Binder.clearCallingIdentity(); |
| 5607 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5608 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 5609 | |
| 5610 | Phone phone = getPhone(subId); |
| 5611 | if (phone == null) { |
| 5612 | try { |
| 5613 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5614 | } catch (RemoteException e) { |
| 5615 | // ignore |
| 5616 | } |
| 5617 | return; |
| 5618 | } |
| 5619 | |
| 5620 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 5621 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5622 | |
| 5623 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5624 | } finally { |
| 5625 | Binder.restoreCallingIdentity(identity); |
| 5626 | } |
| 5627 | } |
| 5628 | |
| 5629 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5630 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5631 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5632 | * @param subId id of the subscription |
| 5633 | * @param request contains the radio access networks with bands/channels to scan |
| 5634 | * @param messenger callback messenger for scan results or errors |
| 5635 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5636 | * @return the id of the requested scan which can be used to stop the scan. |
| 5637 | */ |
| 5638 | @Override |
| 5639 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5640 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5641 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5642 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5643 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5644 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5645 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5646 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5647 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5648 | .setCallingPid(Binder.getCallingPid()) |
| 5649 | .setCallingUid(Binder.getCallingUid()) |
| 5650 | .setMethod("requestNetworkScan") |
| 5651 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
James.cf Lin | 1d4d739 | 2020-07-03 18:22:53 +0800 | [diff] [blame] | 5652 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5653 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5654 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5655 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5656 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 5657 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5658 | if (e != null) { |
| 5659 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5660 | throw e; |
| 5661 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5662 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5663 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5664 | } |
| 5665 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5666 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5667 | int callingUid = Binder.getCallingUid(); |
| 5668 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5669 | final long identity = Binder.clearCallingIdentity(); |
| 5670 | try { |
| 5671 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5672 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5673 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5674 | } finally { |
| 5675 | Binder.restoreCallingIdentity(identity); |
| 5676 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5677 | } |
| 5678 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5679 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5680 | NetworkScanRequest request, int subId, String callingPackage) { |
| 5681 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5682 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5683 | boolean hasNetworkScanPermission = |
| 5684 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5685 | == PERMISSION_GRANTED; |
| 5686 | |
| 5687 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5688 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5689 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5690 | } |
| 5691 | |
| 5692 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5693 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5694 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5695 | return new SecurityException("Specific channels must not be" |
| 5696 | + " scanned without location access."); |
| 5697 | } |
| 5698 | } |
| 5699 | } |
| 5700 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5701 | return null; |
| 5702 | } |
| 5703 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5704 | /** |
| 5705 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5706 | * |
| 5707 | * @param subId id of the subscription |
| 5708 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5709 | */ |
| 5710 | @Override |
| 5711 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5712 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5713 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5714 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5715 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5716 | final long identity = Binder.clearCallingIdentity(); |
| 5717 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5718 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5719 | } finally { |
| 5720 | Binder.restoreCallingIdentity(identity); |
| 5721 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5722 | } |
| 5723 | |
| 5724 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5725 | * Get the calculated preferred network type. |
| 5726 | * Used for debugging incorrect network type. |
| 5727 | * |
| 5728 | * @return the preferred network type, defined in RILConstants.java. |
| 5729 | */ |
| 5730 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5731 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5732 | final Phone defaultPhone = getDefaultPhone(); |
| 5733 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5734 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5735 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5736 | } |
| 5737 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5738 | final long identity = Binder.clearCallingIdentity(); |
| 5739 | try { |
| 5740 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5741 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5742 | } finally { |
| 5743 | Binder.restoreCallingIdentity(identity); |
| 5744 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5745 | } |
| 5746 | |
| 5747 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5748 | * Get the preferred network type. |
| 5749 | * Used for device configuration by some CDMA operators. |
| 5750 | * |
| 5751 | * @return the preferred network type, defined in RILConstants.java. |
| 5752 | */ |
| 5753 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5754 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5755 | TelephonyPermissions |
| 5756 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5757 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5758 | |
| 5759 | final long identity = Binder.clearCallingIdentity(); |
| 5760 | try { |
| 5761 | if (DBG) log("getPreferredNetworkType"); |
| 5762 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5763 | int networkType = (result != null ? result[0] : -1); |
| 5764 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5765 | return networkType; |
| 5766 | } finally { |
| 5767 | Binder.restoreCallingIdentity(identity); |
| 5768 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5769 | } |
| 5770 | |
| 5771 | /** |
| 5772 | * Set the preferred network type. |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5773 | * |
| 5774 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5775 | * @return true on success; false on any failure. |
| 5776 | */ |
| 5777 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5778 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5779 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5780 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5781 | |
| 5782 | final long identity = Binder.clearCallingIdentity(); |
| 5783 | try { |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5784 | Boolean success = (Boolean) sendRequest( |
| 5785 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
calvinpan | 03641a7 | 2020-08-18 16:53:59 +0800 | [diff] [blame] | 5786 | |
| 5787 | if (success) { |
| 5788 | Settings.Global.putInt(mApp.getContentResolver(), |
| 5789 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 5790 | } |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5791 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 5792 | return success; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5793 | } finally { |
| 5794 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5795 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5796 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5797 | |
| 5798 | /** |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5799 | * Get the allowed network types that store in the telephony provider. |
| 5800 | * |
| 5801 | * @param subId the id of the subscription. |
| 5802 | * @return allowedNetworkTypes the allowed network types. |
| 5803 | */ |
| 5804 | @Override |
| 5805 | public long getAllowedNetworkTypes(int subId) { |
| 5806 | TelephonyPermissions |
| 5807 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5808 | mApp, subId, "getAllowedNetworkTypes"); |
| 5809 | |
| 5810 | final long identity = Binder.clearCallingIdentity(); |
| 5811 | try { |
| 5812 | return SubscriptionManager.getLongSubscriptionProperty( |
| 5813 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5814 | } finally { |
| 5815 | Binder.restoreCallingIdentity(identity); |
| 5816 | } |
| 5817 | } |
| 5818 | |
| 5819 | /** |
| 5820 | * Set the allowed network types. |
| 5821 | * |
| 5822 | * @param subId the id of the subscription. |
| 5823 | * @param allowedNetworkTypes the allowed network types. |
| 5824 | * @return true on success; false on any failure. |
| 5825 | */ |
| 5826 | @Override |
| 5827 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 5828 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5829 | mApp, subId, "setAllowedNetworkTypes"); |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5830 | |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5831 | SubscriptionManager.setSubscriptionProperty(subId, |
| 5832 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 5833 | String.valueOf(allowedNetworkTypes)); |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5834 | |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5835 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 5836 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5837 | RILConstants.PREFERRED_NETWORK_MODE); |
| 5838 | return setPreferredNetworkType(subId, preferredNetworkMode); |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5839 | } |
| 5840 | |
| 5841 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 5842 | * Get the allowed network types for certain reason. |
| 5843 | * |
| 5844 | * @param subId the id of the subscription. |
| 5845 | * @param reason the reason the allowed network type change is taking place |
| 5846 | * @return the allowed network types. |
| 5847 | */ |
| 5848 | @Override |
| 5849 | public long getAllowedNetworkTypesForReason(int subId, |
| 5850 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
| 5851 | TelephonyPermissions |
| 5852 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5853 | mApp, subId, "getAllowedNetworkTypesForReason"); |
| 5854 | final long identity = Binder.clearCallingIdentity(); |
| 5855 | try { |
| 5856 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 5857 | } finally { |
| 5858 | Binder.restoreCallingIdentity(identity); |
| 5859 | } |
| 5860 | } |
| 5861 | |
| 5862 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 5863 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 5864 | * @param subId subscription id of the sim card |
| 5865 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 5866 | * This can be passed following states |
| 5867 | * <ol> |
| 5868 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 5869 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 5870 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 5871 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 5872 | * </ol> |
| 5873 | * @return operation result. |
| 5874 | */ |
| 5875 | @Override |
| 5876 | public int setNrDualConnectivityState(int subId, |
| 5877 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 5878 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5879 | mApp, subId, "enableNRDualConnectivity"); |
| 5880 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 5881 | final long identity = Binder.clearCallingIdentity(); |
| 5882 | try { |
| 5883 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 5884 | nrDualConnectivityState, subId, |
| 5885 | workSource); |
| 5886 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 5887 | return result; |
| 5888 | } finally { |
| 5889 | Binder.restoreCallingIdentity(identity); |
| 5890 | } |
| 5891 | } |
| 5892 | |
| 5893 | /** |
| 5894 | * Is E-UTRA-NR Dual Connectivity enabled |
| 5895 | * @return true if dual connectivity is enabled else false |
| 5896 | */ |
| 5897 | @Override |
| 5898 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 5899 | TelephonyPermissions |
| 5900 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5901 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 5902 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 5903 | final long identity = Binder.clearCallingIdentity(); |
| 5904 | try { |
| 5905 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 5906 | null, subId, workSource); |
| 5907 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 5908 | return isEnabled; |
| 5909 | } finally { |
| 5910 | Binder.restoreCallingIdentity(identity); |
| 5911 | } |
| 5912 | } |
| 5913 | |
| 5914 | /** |
Sooraj Sasindran | 4deb887 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 5915 | * get carrier bandwidth per primary and secondary carrier |
| 5916 | * @param subId subscription id of the sim card |
| 5917 | * @return CarrierBandwidth with bandwidth of both primary and secondary carrier.. |
| 5918 | */ |
| 5919 | @Override |
| 5920 | public CarrierBandwidth getCarrierBandwidth(int subId) { |
| 5921 | TelephonyPermissions |
| 5922 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5923 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 5924 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 5925 | final long identity = Binder.clearCallingIdentity(); |
| 5926 | try { |
| 5927 | CarrierBandwidth carrierBandwidth = |
| 5928 | getPhoneFromSubId(subId).getCarrierBandwidth(); |
| 5929 | if (DBG) log("getCarrierBandwidth: " + carrierBandwidth); |
| 5930 | return carrierBandwidth; |
| 5931 | } finally { |
| 5932 | Binder.restoreCallingIdentity(identity); |
| 5933 | } |
| 5934 | } |
| 5935 | |
| 5936 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 5937 | * Get the effective allowed network types on the device. |
| 5938 | * This API will return an intersection of allowed network types for all reasons, |
| 5939 | * including the configuration done through setAllowedNetworkTypes |
| 5940 | * |
| 5941 | * @param subId the id of the subscription. |
| 5942 | * @return the allowed network types |
| 5943 | */ |
| 5944 | @Override |
| 5945 | public long getEffectiveAllowedNetworkTypes(int subId) { |
| 5946 | TelephonyPermissions |
| 5947 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5948 | mApp, subId, "getEffectiveAllowedNetworkTypes"); |
| 5949 | final long identity = Binder.clearCallingIdentity(); |
| 5950 | try { |
| 5951 | return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes(); |
| 5952 | } finally { |
| 5953 | Binder.restoreCallingIdentity(identity); |
| 5954 | } |
| 5955 | } |
| 5956 | |
| 5957 | /** |
| 5958 | * Set the allowed network types of the device and |
| 5959 | * provide the reason triggering the allowed network change. |
| 5960 | * |
| 5961 | * @param subId the id of the subscription. |
| 5962 | * @param reason the reason the allowed network type change is taking place |
| 5963 | * @param allowedNetworkTypes the allowed network types. |
| 5964 | * @return true on success; false on any failure. |
| 5965 | */ |
| 5966 | @Override |
| 5967 | public boolean setAllowedNetworkTypesForReason(int subId, |
| 5968 | @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) { |
| 5969 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5970 | mApp, subId, "setAllowedNetworkTypesForReason"); |
| 5971 | final long identity = Binder.clearCallingIdentity(); |
| 5972 | try { |
| 5973 | getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes); |
| 5974 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 5975 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5976 | RILConstants.PREFERRED_NETWORK_MODE); |
| 5977 | return setPreferredNetworkType(subId, preferredNetworkMode); |
| 5978 | } finally { |
| 5979 | Binder.restoreCallingIdentity(identity); |
| 5980 | } |
| 5981 | } |
| 5982 | |
| 5983 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5984 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5985 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5986 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 5987 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5988 | * @hide |
| 5989 | */ |
| 5990 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 5991 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5992 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5993 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5994 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5995 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5996 | if (phone != null) { |
| 5997 | return phone.hasMatchedTetherApnSetting(); |
| 5998 | } else { |
| 5999 | return false; |
| 6000 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6001 | } finally { |
| 6002 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6003 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6004 | } |
| 6005 | |
| 6006 | /** |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6007 | * Enable or disable always reporting signal strength changes from radio. |
| 6008 | * |
| 6009 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 6010 | */ |
| 6011 | @Override |
| 6012 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 6013 | enforceModifyPermission(); |
| 6014 | enforceSystemCaller(); |
| 6015 | |
| 6016 | final long identity = Binder.clearCallingIdentity(); |
| 6017 | final Phone phone = getPhone(subId); |
| 6018 | try { |
| 6019 | if (phone != null) { |
| 6020 | if (DBG) { |
| 6021 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6022 | + " isEnable=" + isEnable); |
| 6023 | } |
| 6024 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6025 | } else { |
| 6026 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6027 | + subId); |
| 6028 | } |
| 6029 | } finally { |
| 6030 | Binder.restoreCallingIdentity(identity); |
| 6031 | } |
| 6032 | } |
| 6033 | |
| 6034 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6035 | * Get the user enabled state of Mobile Data. |
| 6036 | * |
| 6037 | * TODO: remove and use isUserDataEnabled. |
| 6038 | * This can't be removed now because some vendor codes |
| 6039 | * calls through ITelephony directly while they should |
| 6040 | * use TelephonyManager. |
| 6041 | * |
| 6042 | * @return true on enabled |
| 6043 | */ |
| 6044 | @Override |
| 6045 | public boolean getDataEnabled(int subId) { |
| 6046 | return isUserDataEnabled(subId); |
| 6047 | } |
| 6048 | |
| 6049 | /** |
| 6050 | * Get whether mobile data is enabled per user setting. |
| 6051 | * |
| 6052 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6053 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6054 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6055 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6056 | * |
| 6057 | * @return {@code true} if data is enabled else {@code false} |
| 6058 | */ |
| 6059 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6060 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6061 | try { |
| 6062 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6063 | null); |
| 6064 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6065 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6066 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6067 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6068 | |
| 6069 | final long identity = Binder.clearCallingIdentity(); |
| 6070 | try { |
| 6071 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6072 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6073 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6074 | if (phone != null) { |
| 6075 | boolean retVal = phone.isUserDataEnabled(); |
| 6076 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6077 | return retVal; |
| 6078 | } else { |
| 6079 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6080 | return false; |
| 6081 | } |
| 6082 | } finally { |
| 6083 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6084 | } |
| 6085 | } |
| 6086 | |
| 6087 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6088 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6089 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6090 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6091 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6092 | * @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] | 6093 | */ |
| 6094 | @Override |
| 6095 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6096 | try { |
| 6097 | try { |
| 6098 | mApp.enforceCallingOrSelfPermission( |
| 6099 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6100 | null); |
| 6101 | } catch (Exception e) { |
| 6102 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6103 | "isDataEnabled"); |
| 6104 | } |
| 6105 | } catch (Exception e) { |
| 6106 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6107 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6108 | |
| 6109 | final long identity = Binder.clearCallingIdentity(); |
| 6110 | try { |
| 6111 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6112 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6113 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6114 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6115 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6116 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6117 | return retVal; |
| 6118 | } else { |
| 6119 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6120 | return false; |
| 6121 | } |
| 6122 | } finally { |
| 6123 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6124 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6125 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6126 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6127 | /** |
| 6128 | * Check if data is enabled for a specific reason |
| 6129 | * @param subId Subscription index |
| 6130 | * @param reason the reason the data enable change is taking place |
| 6131 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6132 | */ |
| 6133 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6134 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6135 | @TelephonyManager.DataEnabledReason int reason) { |
| 6136 | try { |
| 6137 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6138 | null); |
| 6139 | } catch (Exception e) { |
| 6140 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6141 | "isDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6142 | } |
| 6143 | |
| 6144 | |
| 6145 | final long identity = Binder.clearCallingIdentity(); |
| 6146 | try { |
| 6147 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6148 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6149 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6150 | + " reason=" + reason); |
| 6151 | } |
| 6152 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6153 | if (phone != null) { |
| 6154 | boolean retVal; |
| 6155 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6156 | retVal = phone.isUserDataEnabled(); |
| 6157 | } else { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6158 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6159 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6160 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6161 | return retVal; |
| 6162 | } else { |
| 6163 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6164 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6165 | + subId + " retVal=false"); |
| 6166 | } |
| 6167 | return false; |
| 6168 | } |
| 6169 | } finally { |
| 6170 | Binder.restoreCallingIdentity(identity); |
| 6171 | } |
| 6172 | } |
| 6173 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6174 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6175 | Phone phone) { |
Hall Liu | 54a2a0c | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 6176 | if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) { |
| 6177 | // Skip the check if it's one of these special uids |
| 6178 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6179 | } |
| 6180 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6181 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6182 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6183 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6184 | || subController == null) return privilegeFromSim; |
| 6185 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6186 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6187 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6188 | |
| 6189 | final long identity = Binder.clearCallingIdentity(); |
| 6190 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6191 | int subId = phone.getSubId(); |
| 6192 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6193 | // A test override is in place for the privileges for this subId, so don't try to |
| 6194 | // read the subscription privileges. |
| 6195 | return privilegeFromSim; |
| 6196 | } |
| 6197 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6198 | SubscriptionManager subManager = (SubscriptionManager) |
| 6199 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6200 | for (String pkg : packages) { |
| 6201 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6202 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6203 | } |
| 6204 | } |
| 6205 | return privilegeFromSim; |
| 6206 | } finally { |
| 6207 | Binder.restoreCallingIdentity(identity); |
| 6208 | } |
| 6209 | } |
| 6210 | |
| 6211 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6212 | String pkgName) { |
| 6213 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6214 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6215 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6216 | || subController == null) return privilegeFromSim; |
| 6217 | |
| 6218 | final long identity = Binder.clearCallingIdentity(); |
| 6219 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6220 | int subId = phone.getSubId(); |
| 6221 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6222 | // A test override is in place for the privileges for this subId, so don't try to |
| 6223 | // read the subscription privileges. |
| 6224 | return privilegeFromSim; |
| 6225 | } |
| 6226 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6227 | SubscriptionManager subManager = (SubscriptionManager) |
| 6228 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6229 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6230 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6231 | } finally { |
| 6232 | Binder.restoreCallingIdentity(identity); |
| 6233 | } |
| 6234 | } |
| 6235 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6236 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6237 | public int getCarrierPrivilegeStatus(int subId) { |
| 6238 | final Phone phone = getPhone(subId); |
| 6239 | if (phone == null) { |
| 6240 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6241 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6242 | } |
| 6243 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6244 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6245 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6246 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6247 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6248 | |
| 6249 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6250 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6251 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6252 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6253 | |
| 6254 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6255 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6256 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6257 | final Phone phone = getPhone(subId); |
| 6258 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6259 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6260 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6261 | } |
| 6262 | UiccProfile profile = |
| 6263 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6264 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6265 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6266 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6267 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6268 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6269 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6270 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6271 | } |
| 6272 | |
| 6273 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6274 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 6275 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6276 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6277 | } |
| 6278 | |
| 6279 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 6280 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6281 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6282 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6283 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6284 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6285 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6286 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6287 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6288 | } |
| 6289 | |
| 6290 | @Override |
| 6291 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6292 | if (TextUtils.isEmpty(pkgName)) |
| 6293 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6294 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6295 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6296 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 6297 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6298 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6299 | continue; |
| 6300 | } |
| 6301 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6302 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6303 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6304 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6305 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6306 | break; |
| 6307 | } |
| 6308 | } |
| 6309 | |
| 6310 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6311 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6312 | |
| 6313 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6314 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 6315 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6316 | loge("phoneId " + phoneId + " is not valid."); |
| 6317 | return null; |
| 6318 | } |
| 6319 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6320 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6321 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6322 | return null ; |
| 6323 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6324 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6325 | } |
| 6326 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6327 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6328 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6329 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6330 | List<String> privilegedPackages = new ArrayList<>(); |
| 6331 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6332 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 6333 | // has UICC in that slot. |
| 6334 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6335 | if (card.hasCarrierPrivilegeRules()) { |
| 6336 | if (packages == null) { |
| 6337 | // Only check packages in user 0 for now |
| 6338 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6339 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6340 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6341 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6342 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6343 | } |
| 6344 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6345 | PackageInfo pkgInfo = packages.get(p); |
| 6346 | if (pkgInfo != null && pkgInfo.packageName != null |
| 6347 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6348 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6349 | privilegedPackages.add(pkgInfo.packageName); |
| 6350 | } |
| 6351 | } |
| 6352 | } |
| 6353 | } |
| 6354 | return privilegedPackages; |
| 6355 | } |
| 6356 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6357 | @Override |
| 6358 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6359 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6360 | |
| 6361 | final long identity = Binder.clearCallingIdentity(); |
| 6362 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6363 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6364 | try { |
| 6365 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6366 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6367 | } |
| 6368 | } finally { |
| 6369 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6370 | } |
| 6371 | return privilegedPackages; |
| 6372 | } |
| 6373 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6374 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6375 | final Phone phone = getPhone(subId); |
| 6376 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6377 | if (card == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6378 | return null; |
| 6379 | } |
| 6380 | String iccId = card.getIccId(); |
| 6381 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6382 | return null; |
| 6383 | } |
| 6384 | return iccId; |
| 6385 | } |
| 6386 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6387 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6388 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6389 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6390 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6391 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6392 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6393 | final long identity = Binder.clearCallingIdentity(); |
| 6394 | try { |
| 6395 | final String iccId = getIccId(subId); |
| 6396 | final Phone phone = getPhone(subId); |
| 6397 | if (phone == null) { |
| 6398 | return false; |
| 6399 | } |
| 6400 | final String subscriberId = phone.getSubscriberId(); |
| 6401 | |
| 6402 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6403 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6404 | + subscriberId + " to " + number); |
| 6405 | } |
| 6406 | |
| 6407 | if (TextUtils.isEmpty(iccId)) { |
| 6408 | return false; |
| 6409 | } |
| 6410 | |
| 6411 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6412 | |
| 6413 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6414 | if (alphaTag == null) { |
| 6415 | editor.remove(alphaTagPrefKey); |
| 6416 | } else { |
| 6417 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6418 | } |
| 6419 | |
| 6420 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6421 | // track all merged IMSIs based on line number |
| 6422 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6423 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6424 | if (number == null) { |
| 6425 | editor.remove(numberPrefKey); |
| 6426 | editor.remove(subscriberPrefKey); |
| 6427 | } else { |
| 6428 | editor.putString(numberPrefKey, number); |
| 6429 | editor.putString(subscriberPrefKey, subscriberId); |
| 6430 | } |
| 6431 | |
| 6432 | editor.commit(); |
| 6433 | return true; |
| 6434 | } finally { |
| 6435 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6436 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6437 | } |
| 6438 | |
| 6439 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6440 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6441 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6442 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6443 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6444 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6445 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6446 | return null; |
| 6447 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6448 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6449 | final long identity = Binder.clearCallingIdentity(); |
| 6450 | try { |
| 6451 | String iccId = getIccId(subId); |
| 6452 | if (iccId != null) { |
| 6453 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6454 | if (DBG_MERGE) { |
| 6455 | log("getLine1NumberForDisplay returning " |
| 6456 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6457 | } |
| 6458 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6459 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6460 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6461 | return null; |
| 6462 | } finally { |
| 6463 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6464 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6465 | } |
| 6466 | |
| 6467 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6468 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6469 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6470 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6471 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6472 | return null; |
| 6473 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6474 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6475 | final long identity = Binder.clearCallingIdentity(); |
| 6476 | try { |
| 6477 | String iccId = getIccId(subId); |
| 6478 | if (iccId != null) { |
| 6479 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6480 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6481 | } |
| 6482 | return null; |
| 6483 | } finally { |
| 6484 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6485 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6486 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6487 | |
| 6488 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6489 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6490 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6491 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6492 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6493 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6494 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6495 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6496 | return null; |
| 6497 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6498 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6499 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6500 | // the process, where TelephonyManager was instantiated. |
| 6501 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6502 | final long identity = Binder.clearCallingIdentity(); |
| 6503 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6504 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6505 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6506 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6507 | |
| 6508 | // Figure out what subscribers are currently active |
| 6509 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6510 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6511 | // Only consider subs which match the current subId |
| 6512 | // This logic can be simplified. See b/131189269 for progress. |
| 6513 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6514 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6515 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6516 | |
| 6517 | // First pass, find a number override for an active subscriber |
| 6518 | String mergeNumber = null; |
| 6519 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6520 | for (String key : prefs.keySet()) { |
| 6521 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6522 | final String subscriberId = (String) prefs.get(key); |
| 6523 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6524 | final String iccId = key.substring( |
| 6525 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6526 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6527 | mergeNumber = (String) prefs.get(numberKey); |
| 6528 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6529 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6530 | + " for active subscriber " + subscriberId); |
| 6531 | } |
| 6532 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6533 | break; |
| 6534 | } |
| 6535 | } |
| 6536 | } |
| 6537 | } |
| 6538 | |
| 6539 | // Shortcut when no active merged subscribers |
| 6540 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6541 | return null; |
| 6542 | } |
| 6543 | |
| 6544 | // Second pass, find all subscribers under that line override |
| 6545 | final ArraySet<String> result = new ArraySet<>(); |
| 6546 | for (String key : prefs.keySet()) { |
| 6547 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6548 | final String number = (String) prefs.get(key); |
| 6549 | if (mergeNumber.equals(number)) { |
| 6550 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6551 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6552 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6553 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6554 | result.add(subscriberId); |
| 6555 | } |
| 6556 | } |
| 6557 | } |
| 6558 | } |
| 6559 | |
| 6560 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6561 | Arrays.sort(resultArray); |
| 6562 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6563 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6564 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6565 | } |
| 6566 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6567 | } finally { |
| 6568 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6569 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6570 | } |
| 6571 | |
| 6572 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6573 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6574 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6575 | |
| 6576 | final long identity = Binder.clearCallingIdentity(); |
| 6577 | try { |
| 6578 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6579 | TelephonyManager.class); |
| 6580 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6581 | if (subscriberId == null) { |
| 6582 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6583 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6584 | + subId); |
| 6585 | } |
| 6586 | return null; |
| 6587 | } |
| 6588 | |
| 6589 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6590 | .getSubscriptionInfo(subId); |
| 6591 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6592 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6593 | if (groupUuid == null) { |
| 6594 | return new String[]{subscriberId}; |
| 6595 | } |
| 6596 | |
| 6597 | // Get all subscriberIds from the group. |
| 6598 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6599 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6600 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6601 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6602 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6603 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6604 | if (subscriberId != null) { |
| 6605 | mergedSubscriberIds.add(subscriberId); |
| 6606 | } |
| 6607 | } |
| 6608 | |
| 6609 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6610 | } finally { |
| 6611 | Binder.restoreCallingIdentity(identity); |
| 6612 | |
| 6613 | } |
| 6614 | } |
| 6615 | |
| 6616 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6617 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6618 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6619 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6620 | |
| 6621 | final long identity = Binder.clearCallingIdentity(); |
| 6622 | try { |
| 6623 | final Phone phone = getPhone(subId); |
| 6624 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6625 | } finally { |
| 6626 | Binder.restoreCallingIdentity(identity); |
| 6627 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6628 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6629 | |
| 6630 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6631 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6632 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6633 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6634 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6635 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6636 | |
| 6637 | final long identity = Binder.clearCallingIdentity(); |
| 6638 | try { |
| 6639 | final Phone phone = getPhone(subId); |
| 6640 | if (phone == null) { |
| 6641 | return false; |
| 6642 | } |
| 6643 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6644 | cdmaNonRoamingList); |
| 6645 | } finally { |
| 6646 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6647 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6648 | } |
| 6649 | |
| 6650 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6651 | @Deprecated |
| 6652 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6653 | enforceModifyPermission(); |
| 6654 | |
| 6655 | int returnValue = 0; |
| 6656 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6657 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6658 | if(result.exception == null) { |
| 6659 | if (result.result != null) { |
| 6660 | byte[] responseData = (byte[])(result.result); |
| 6661 | if(responseData.length > oemResp.length) { |
| 6662 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6663 | responseData.length + "bytes. Buffer Size is " + |
| 6664 | oemResp.length + "bytes."); |
| 6665 | } |
| 6666 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6667 | returnValue = responseData.length; |
| 6668 | } |
| 6669 | } else { |
| 6670 | CommandException ex = (CommandException) result.exception; |
| 6671 | returnValue = ex.getCommandError().ordinal(); |
| 6672 | if(returnValue > 0) returnValue *= -1; |
| 6673 | } |
| 6674 | } catch (RuntimeException e) { |
| 6675 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6676 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6677 | if(returnValue > 0) returnValue *= -1; |
| 6678 | } |
| 6679 | |
| 6680 | return returnValue; |
| 6681 | } |
| 6682 | |
| 6683 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6684 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6685 | try { |
| 6686 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6687 | } catch (RuntimeException e) { |
| 6688 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6689 | } |
| 6690 | } |
| 6691 | |
| 6692 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6693 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6694 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 6695 | try { |
| 6696 | TelephonyPermissions |
| 6697 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6698 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6699 | } catch (SecurityException e) { |
| 6700 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 6701 | throw e; |
| 6702 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6703 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6704 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6705 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6706 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6707 | final long identity = Binder.clearCallingIdentity(); |
| 6708 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6709 | TelephonyPermissions |
| 6710 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6711 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6712 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6713 | } finally { |
| 6714 | Binder.restoreCallingIdentity(identity); |
| 6715 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6716 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6717 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6718 | |
| 6719 | @Override |
| 6720 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6721 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6722 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6723 | |
| 6724 | final long identity = Binder.clearCallingIdentity(); |
| 6725 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6726 | ImsManager.getInstance(defaultPhone.getContext(), |
| 6727 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6728 | } finally { |
| 6729 | Binder.restoreCallingIdentity(identity); |
| 6730 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6731 | } |
| 6732 | |
| 6733 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6734 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6735 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6736 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 6737 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6738 | return false; |
| 6739 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6740 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6741 | final long identity = Binder.clearCallingIdentity(); |
| 6742 | try { |
| 6743 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 6744 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 6745 | // In the long run, we may instead need to check if there exists a connection service |
| 6746 | // which can support video calling. |
| 6747 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6748 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6749 | return imsManager.isVtEnabledByPlatform() |
| 6750 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 6751 | && imsManager.isVtEnabledByUser(); |
| 6752 | } finally { |
| 6753 | Binder.restoreCallingIdentity(identity); |
| 6754 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6755 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 6756 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6757 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6758 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 6759 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6760 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6761 | mApp, subId, callingPackage, callingFeatureId, |
| 6762 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6763 | return false; |
| 6764 | } |
| 6765 | |
| 6766 | final long identity = Binder.clearCallingIdentity(); |
| 6767 | try { |
| 6768 | CarrierConfigManager configManager = |
| 6769 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6770 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6771 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 6772 | } finally { |
| 6773 | Binder.restoreCallingIdentity(identity); |
| 6774 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6775 | } |
| 6776 | |
| 6777 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6778 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6779 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6780 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6781 | return false; |
| 6782 | } |
| 6783 | |
| 6784 | final long identity = Binder.clearCallingIdentity(); |
| 6785 | try { |
| 6786 | CarrierConfigManager configManager = |
| 6787 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6788 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6789 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 6790 | } finally { |
| 6791 | Binder.restoreCallingIdentity(identity); |
| 6792 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6793 | } |
| 6794 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6795 | @Override |
| 6796 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6797 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 6798 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6799 | } |
| 6800 | |
| 6801 | @Override |
| 6802 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6803 | final long identity = Binder.clearCallingIdentity(); |
| 6804 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6805 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6806 | } finally { |
| 6807 | Binder.restoreCallingIdentity(identity); |
| 6808 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6809 | } |
| 6810 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6811 | /** |
| 6812 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 6813 | * support for the feature and device firmware support. |
| 6814 | * |
| 6815 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 6816 | */ |
| 6817 | @Override |
| 6818 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6819 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6820 | final Phone phone = getPhone(subscriptionId); |
| 6821 | if (phone == null) { |
| 6822 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 6823 | return false; |
| 6824 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6825 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6826 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6827 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 6828 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6829 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6830 | return isCarrierSupported && isDeviceSupported; |
| 6831 | } finally { |
| 6832 | Binder.restoreCallingIdentity(identity); |
| 6833 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 6834 | } |
| 6835 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6836 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 6837 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 6838 | * RTT setting, will return true if the device and carrier both support RTT. |
| 6839 | * 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] | 6840 | */ |
| 6841 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6842 | final long identity = Binder.clearCallingIdentity(); |
| 6843 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 6844 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 6845 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 6846 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 6847 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 6848 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 6849 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6850 | } finally { |
| 6851 | Binder.restoreCallingIdentity(identity); |
| 6852 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 6853 | } |
| 6854 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6855 | @Deprecated |
| 6856 | @Override |
| 6857 | public String getDeviceId(String callingPackage) { |
| 6858 | return getDeviceIdWithFeature(callingPackage, null); |
| 6859 | } |
| 6860 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6861 | /** |
| 6862 | * Returns the unique device ID of phone, for example, the IMEI for |
| 6863 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 6864 | * |
| 6865 | * <p>Requires Permission: |
| 6866 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 6867 | */ |
| 6868 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6869 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6870 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6871 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6872 | return null; |
| 6873 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6874 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 6875 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6876 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6877 | return null; |
| 6878 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6879 | |
| 6880 | final long identity = Binder.clearCallingIdentity(); |
| 6881 | try { |
| 6882 | return phone.getDeviceId(); |
| 6883 | } finally { |
| 6884 | Binder.restoreCallingIdentity(identity); |
| 6885 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6886 | } |
| 6887 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6888 | /** |
| 6889 | * {@hide} |
| 6890 | * Returns the IMS Registration Status on a particular subid |
| 6891 | * |
| 6892 | * @param subId |
| 6893 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6894 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6895 | Phone phone = getPhone(subId); |
| 6896 | if (phone != null) { |
| 6897 | return phone.isImsRegistered(); |
| 6898 | } else { |
| 6899 | return false; |
| 6900 | } |
| 6901 | } |
| 6902 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6903 | @Override |
| 6904 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6905 | final long identity = Binder.clearCallingIdentity(); |
| 6906 | try { |
| 6907 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 6908 | } finally { |
| 6909 | Binder.restoreCallingIdentity(identity); |
| 6910 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6911 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 6912 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6913 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6914 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6915 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6916 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6917 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6918 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6919 | } |
| 6920 | final long identity = Binder.clearCallingIdentity(); |
| 6921 | try { |
| 6922 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 6923 | } finally { |
| 6924 | Binder.restoreCallingIdentity(identity); |
| 6925 | } |
| 6926 | } |
| 6927 | |
| 6928 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6929 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
duki.hong | fd96bde | 2020-07-22 17:32:19 +0900 | [diff] [blame] | 6930 | enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, " |
| 6931 | + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6932 | final long identity = Binder.clearCallingIdentity(); |
| 6933 | try { |
| 6934 | Phone phone = getPhone(subscriptionId); |
| 6935 | if (phone == null) { |
| 6936 | return null; |
| 6937 | } |
| 6938 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 6939 | } finally { |
| 6940 | Binder.restoreCallingIdentity(identity); |
| 6941 | } |
| 6942 | } |
| 6943 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6944 | /** |
| 6945 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6946 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6947 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6948 | final long identity = Binder.clearCallingIdentity(); |
| 6949 | try { |
| 6950 | Phone phone = getPhone(subId); |
| 6951 | if (phone != null) { |
| 6952 | return phone.isWifiCallingEnabled(); |
| 6953 | } else { |
| 6954 | return false; |
| 6955 | } |
| 6956 | } finally { |
| 6957 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6958 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6959 | } |
| 6960 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6961 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6962 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6963 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6964 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6965 | final long identity = Binder.clearCallingIdentity(); |
| 6966 | try { |
| 6967 | Phone phone = getPhone(subId); |
| 6968 | if (phone != null) { |
| 6969 | return phone.isVideoEnabled(); |
| 6970 | } else { |
| 6971 | return false; |
| 6972 | } |
| 6973 | } finally { |
| 6974 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6975 | } |
| 6976 | } |
| 6977 | |
| 6978 | /** |
| 6979 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 6980 | * defined in {@link ImsRegistrationImplBase}. |
| 6981 | */ |
| 6982 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6983 | final long identity = Binder.clearCallingIdentity(); |
| 6984 | try { |
| 6985 | Phone phone = getPhone(subId); |
| 6986 | if (phone != null) { |
| 6987 | return phone.getImsRegistrationTech(); |
| 6988 | } else { |
| 6989 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 6990 | } |
| 6991 | } finally { |
| 6992 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6993 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6994 | } |
| 6995 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6996 | @Override |
| 6997 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 6998 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6999 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7000 | return; |
| 7001 | } |
| 7002 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7003 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7004 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7005 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7006 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7007 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7008 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7009 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7010 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7011 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7012 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 7013 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7014 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7015 | // There has been issues when Sms raw table somehow stores orphan |
| 7016 | // fragments. They lead to garbled message when new fragments come |
| 7017 | // in and combined with those stale ones. In case this happens again, |
| 7018 | // user can reset all network settings which will clean up this table. |
| 7019 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7020 | // Clean up IMS settings as well here. |
| 7021 | int slotId = getSlotIndex(subId); |
| 7022 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7023 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7024 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7025 | |
| 7026 | // Erase modem config if erase modem on network setting is enabled. |
| 7027 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7028 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7029 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 7030 | sendEraseModemConfig(getDefaultPhone()); |
| 7031 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7032 | } finally { |
| 7033 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7034 | } |
| 7035 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7036 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7037 | private void cleanUpSmsRawTable(Context context) { |
| 7038 | ContentResolver resolver = context.getContentResolver(); |
| 7039 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7040 | resolver.delete(uri, null, null); |
| 7041 | } |
| 7042 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7043 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7044 | public String getSimLocaleForSubscriber(int subId) { |
| 7045 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7046 | final Phone phone = getPhone(subId); |
| 7047 | if (phone == null) { |
| 7048 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7049 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7050 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7051 | final long identity = Binder.clearCallingIdentity(); |
| 7052 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7053 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7054 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7055 | if (info == null) { |
| 7056 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7057 | return null; |
| 7058 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7059 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7060 | // preferences (EF-PL and EF-LI)... |
| 7061 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7062 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7063 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7064 | if (localeFromDefaultSim != null) { |
| 7065 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7066 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7067 | + localeFromDefaultSim); |
| 7068 | return localeFromDefaultSim.toLanguageTag(); |
| 7069 | } else { |
| 7070 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7071 | } |
| 7072 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7073 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7074 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7075 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7076 | // the SIM and carrier preferences does not include a country we add the country |
| 7077 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7078 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7079 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7080 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7081 | return mccLocale.toLanguageTag(); |
| 7082 | } |
| 7083 | |
| 7084 | if (DBG) log("No locale found - returning null"); |
| 7085 | return null; |
| 7086 | } finally { |
| 7087 | Binder.restoreCallingIdentity(identity); |
| 7088 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7089 | } |
| 7090 | |
| 7091 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7092 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7093 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7094 | } |
| 7095 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7096 | /** |
| 7097 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7098 | */ |
| 7099 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7100 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7101 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7102 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7103 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7104 | private final ModemActivityInfo mLastModemActivityInfo = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7105 | new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7106 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7107 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7108 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7109 | * representing the state of the modem. |
| 7110 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7111 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7112 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7113 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7114 | */ |
| 7115 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7116 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7117 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7118 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7119 | |
| 7120 | final long identity = Binder.clearCallingIdentity(); |
| 7121 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7122 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7123 | } finally { |
| 7124 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7125 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7126 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7127 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7128 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7129 | // less than total activity duration. |
| 7130 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7131 | if (info == null) { |
| 7132 | return false; |
| 7133 | } |
| 7134 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7135 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7136 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7137 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7138 | return (info.isValid() |
| 7139 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7140 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7141 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7142 | && (totalTxTimeMs <= activityDurationMs)); |
| 7143 | } |
| 7144 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7145 | /** |
| 7146 | * {@hide} |
| 7147 | * Returns the service state information on specified subscription. |
| 7148 | */ |
| 7149 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7150 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7151 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7152 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7153 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7154 | return null; |
| 7155 | } |
| 7156 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7157 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7158 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7159 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7160 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7161 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7162 | .setCallingPid(Binder.getCallingPid()) |
| 7163 | .setCallingUid(Binder.getCallingUid()) |
| 7164 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7165 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7166 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7167 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7168 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7169 | .build()); |
| 7170 | |
| 7171 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7172 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7173 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7174 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7175 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7176 | .setCallingPid(Binder.getCallingPid()) |
| 7177 | .setCallingUid(Binder.getCallingUid()) |
| 7178 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7179 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7180 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7181 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7182 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7183 | .build()); |
| 7184 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7185 | boolean hasFinePermission = |
| 7186 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7187 | boolean hasCoarsePermission = |
| 7188 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7189 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7190 | final Phone phone = getPhone(subId); |
| 7191 | if (phone == null) { |
| 7192 | return null; |
| 7193 | } |
| 7194 | |
| 7195 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 7196 | .contains(callingPackage); |
| 7197 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7198 | final long identity = Binder.clearCallingIdentity(); |
| 7199 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7200 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7201 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7202 | Rlog.d(LOG_TAG, |
| 7203 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7204 | return null; |
| 7205 | } |
| 7206 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7207 | ServiceState ss = phone.getServiceState(); |
| 7208 | |
| 7209 | // Scrub out the location info in ServiceState depending on what level of access |
| 7210 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7211 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7212 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7213 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7214 | } finally { |
| 7215 | Binder.restoreCallingIdentity(identity); |
| 7216 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7217 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7218 | |
| 7219 | /** |
| 7220 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7221 | * |
| 7222 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7223 | * voicemail ringtone. |
| 7224 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7225 | * PhoneAccount. |
| 7226 | */ |
| 7227 | @Override |
| 7228 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7229 | final long identity = Binder.clearCallingIdentity(); |
| 7230 | try { |
| 7231 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7232 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7233 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7234 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7235 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7236 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7237 | } finally { |
| 7238 | Binder.restoreCallingIdentity(identity); |
| 7239 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7240 | } |
| 7241 | |
| 7242 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7243 | * Sets the per-account voicemail ringtone. |
| 7244 | * |
| 7245 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7246 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7247 | * |
| 7248 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7249 | * voicemail ringtone. |
| 7250 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7251 | * PhoneAccount. |
| 7252 | */ |
| 7253 | @Override |
| 7254 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7255 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7256 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7257 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7258 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7259 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7260 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7261 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7262 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7263 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7264 | |
| 7265 | final long identity = Binder.clearCallingIdentity(); |
| 7266 | try { |
| 7267 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7268 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7269 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7270 | } |
| 7271 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7272 | } finally { |
| 7273 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7274 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7275 | } |
| 7276 | |
| 7277 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7278 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7279 | * |
| 7280 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7281 | * voicemail vibration setting. |
| 7282 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7283 | */ |
| 7284 | @Override |
| 7285 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7286 | final long identity = Binder.clearCallingIdentity(); |
| 7287 | try { |
| 7288 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7289 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7290 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7291 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7292 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7293 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7294 | } finally { |
| 7295 | Binder.restoreCallingIdentity(identity); |
| 7296 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7297 | } |
| 7298 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7299 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7300 | * Sets the per-account voicemail vibration. |
| 7301 | * |
| 7302 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7303 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7304 | * |
| 7305 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7306 | * voicemail vibration setting. |
| 7307 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7308 | * specific PhoneAccount. |
| 7309 | */ |
| 7310 | @Override |
| 7311 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7312 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7313 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7314 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7315 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7316 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7317 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7318 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7319 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7320 | } |
| 7321 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7322 | final long identity = Binder.clearCallingIdentity(); |
| 7323 | try { |
| 7324 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7325 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7326 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7327 | } |
| 7328 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7329 | } finally { |
| 7330 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7331 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7332 | } |
| 7333 | |
| 7334 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7335 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 7336 | * |
| 7337 | * @throws SecurityException if the caller does not have the required permission |
| 7338 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7339 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7340 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7341 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7342 | } |
| 7343 | |
| 7344 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7345 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 7346 | * permission. |
| 7347 | * |
| 7348 | * @throws SecurityException if the caller does not have the required permission |
| 7349 | */ |
| 7350 | private void enforceSendSmsPermission() { |
| 7351 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 7352 | } |
| 7353 | |
| 7354 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7355 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7356 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7357 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7358 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7359 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7360 | final long identity = Binder.clearCallingIdentity(); |
| 7361 | try { |
| 7362 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7363 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7364 | if (componentName == null) { |
| 7365 | throw new SecurityException( |
| 7366 | "Caller not current active visual voicemail package[null]"); |
| 7367 | } |
| 7368 | String vvmPackage = componentName.getPackageName(); |
| 7369 | if (!callingPackage.equals(vvmPackage)) { |
| 7370 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 7371 | + vvmPackage + "]"); |
| 7372 | } |
| 7373 | } finally { |
| 7374 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7375 | } |
| 7376 | } |
| 7377 | |
| 7378 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7379 | * Return the application ID for the app type. |
| 7380 | * |
| 7381 | * @param subId the subscription ID that this request applies to. |
| 7382 | * @param appType the uicc app type. |
| 7383 | * @return Application ID for specificied app type, or null if no uicc. |
| 7384 | */ |
| 7385 | @Override |
| 7386 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7387 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7388 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7389 | |
| 7390 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7391 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7392 | if (phone == null) { |
| 7393 | return null; |
| 7394 | } |
| 7395 | String aid = null; |
| 7396 | try { |
| 7397 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 7398 | .getApplicationByType(appType).getAid(); |
| 7399 | } catch (Exception e) { |
| 7400 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 7401 | } |
| 7402 | return aid; |
| 7403 | } finally { |
| 7404 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7405 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7406 | } |
| 7407 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7408 | /** |
| 7409 | * Return the Electronic Serial Number. |
| 7410 | * |
| 7411 | * @param subId the subscription ID that this request applies to. |
| 7412 | * @return ESN or null if error. |
| 7413 | */ |
| 7414 | @Override |
| 7415 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7416 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7417 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7418 | |
| 7419 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7420 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7421 | if (phone == null) { |
| 7422 | return null; |
| 7423 | } |
| 7424 | String esn = null; |
| 7425 | try { |
| 7426 | esn = phone.getEsn(); |
| 7427 | } catch (Exception e) { |
| 7428 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 7429 | } |
| 7430 | return esn; |
| 7431 | } finally { |
| 7432 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7433 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7434 | } |
| 7435 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7436 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7437 | * Return the Preferred Roaming List Version. |
| 7438 | * |
| 7439 | * @param subId the subscription ID that this request applies to. |
| 7440 | * @return PRLVersion or null if error. |
| 7441 | */ |
| 7442 | @Override |
| 7443 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7444 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7445 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7446 | |
| 7447 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7448 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7449 | if (phone == null) { |
| 7450 | return null; |
| 7451 | } |
| 7452 | String cdmaPrlVersion = null; |
| 7453 | try { |
| 7454 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7455 | } catch (Exception e) { |
| 7456 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7457 | } |
| 7458 | return cdmaPrlVersion; |
| 7459 | } finally { |
| 7460 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7461 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7462 | } |
| 7463 | |
| 7464 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7465 | * Get snapshot of Telephony histograms |
| 7466 | * @return List of Telephony histograms |
| 7467 | * @hide |
| 7468 | */ |
| 7469 | @Override |
| 7470 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7471 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7472 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7473 | |
| 7474 | final long identity = Binder.clearCallingIdentity(); |
| 7475 | try { |
| 7476 | return RIL.getTelephonyRILTimingHistograms(); |
| 7477 | } finally { |
| 7478 | Binder.restoreCallingIdentity(identity); |
| 7479 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7480 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7481 | |
| 7482 | /** |
| 7483 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7484 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7485 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7486 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7487 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7488 | * @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] | 7489 | */ |
| 7490 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7491 | @TelephonyManager.SetCarrierRestrictionResult |
| 7492 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7493 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7494 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7495 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7496 | if (carrierRestrictionRules == null) { |
| 7497 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7498 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7499 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7500 | final long identity = Binder.clearCallingIdentity(); |
| 7501 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7502 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7503 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7504 | } finally { |
| 7505 | Binder.restoreCallingIdentity(identity); |
| 7506 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7507 | } |
| 7508 | |
| 7509 | /** |
| 7510 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7511 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7512 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7513 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7514 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7515 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7516 | */ |
| 7517 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7518 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7519 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7520 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7521 | |
| 7522 | final long identity = Binder.clearCallingIdentity(); |
| 7523 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7524 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7525 | if (response instanceof CarrierRestrictionRules) { |
| 7526 | return (CarrierRestrictionRules) response; |
| 7527 | } |
| 7528 | // Response is an Exception of some kind, |
| 7529 | // which is signalled to the user as a NULL retval |
| 7530 | return null; |
| 7531 | } catch (Exception e) { |
| 7532 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7533 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7534 | } finally { |
| 7535 | Binder.restoreCallingIdentity(identity); |
| 7536 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7537 | } |
| 7538 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7539 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7540 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7541 | * @param subId the subscription ID that this action applies to. |
| 7542 | * @param enabled control enable or disable radio. |
| 7543 | * {@hide} |
| 7544 | */ |
| 7545 | @Override |
| 7546 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7547 | enforceModifyPermission(); |
| 7548 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7549 | |
| 7550 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7551 | if (phone == null) { |
| 7552 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7553 | return; |
| 7554 | } |
| 7555 | try { |
| 7556 | phone.carrierActionSetRadioEnabled(enabled); |
| 7557 | } catch (Exception e) { |
| 7558 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7559 | } finally { |
| 7560 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7561 | } |
| 7562 | } |
| 7563 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7564 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7565 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7566 | * network status based on which carrier apps could apply actions accordingly, |
| 7567 | * enable/disable default url handler for example. |
| 7568 | * |
| 7569 | * @param subId the subscription ID that this action applies to. |
| 7570 | * @param report control start/stop reporting the default network status. |
| 7571 | * {@hide} |
| 7572 | */ |
| 7573 | @Override |
| 7574 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7575 | enforceModifyPermission(); |
| 7576 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7577 | |
| 7578 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7579 | if (phone == null) { |
| 7580 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7581 | return; |
| 7582 | } |
| 7583 | try { |
| 7584 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7585 | } catch (Exception e) { |
| 7586 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7587 | } finally { |
| 7588 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7589 | } |
| 7590 | } |
| 7591 | |
| 7592 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7593 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7594 | * @param subId the subscription ID that this action applies to. |
| 7595 | * {@hide} |
| 7596 | */ |
| 7597 | @Override |
| 7598 | public void carrierActionResetAll(int subId) { |
| 7599 | enforceModifyPermission(); |
| 7600 | final Phone phone = getPhone(subId); |
| 7601 | if (phone == null) { |
| 7602 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7603 | return; |
| 7604 | } |
| 7605 | try { |
| 7606 | phone.carrierActionResetAll(); |
| 7607 | } catch (Exception e) { |
| 7608 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7609 | } |
| 7610 | } |
| 7611 | |
| 7612 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7613 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7614 | * bug report is being generated. |
| 7615 | */ |
| 7616 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7617 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7618 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7619 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7620 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7621 | + Binder.getCallingPid() |
| 7622 | + ", uid=" + Binder.getCallingUid() |
| 7623 | + "without permission " |
| 7624 | + android.Manifest.permission.DUMP); |
| 7625 | return; |
| 7626 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7627 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7628 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7629 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7630 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 7631 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 7632 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 7633 | @NonNull String[] args) { |
| 7634 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 7635 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 7636 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7637 | } |
| 7638 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7639 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7640 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 7641 | * @param subId Subscription index |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7642 | * @param reason the reason the data enable change is taking place |
| 7643 | * @param enabled True if enabling the data, otherwise disabling. |
| 7644 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7645 | */ |
| 7646 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7647 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7648 | boolean enabled) { |
| 7649 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 7650 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7651 | try { |
| 7652 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7653 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7654 | } catch (SecurityException se) { |
| 7655 | enforceModifyPermission(); |
| 7656 | } |
| 7657 | } else { |
| 7658 | enforceModifyPermission(); |
| 7659 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7660 | |
| 7661 | final long identity = Binder.clearCallingIdentity(); |
| 7662 | try { |
| 7663 | Phone phone = getPhone(subId); |
| 7664 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7665 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7666 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7667 | } else { |
| 7668 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 7669 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7670 | } |
| 7671 | } finally { |
| 7672 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7673 | } |
| 7674 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7675 | |
| 7676 | /** |
| 7677 | * Get Client request stats |
| 7678 | * @return List of Client Request Stats |
| 7679 | * @hide |
| 7680 | */ |
| 7681 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7682 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7683 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7684 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7685 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7686 | return null; |
| 7687 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7688 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7689 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7690 | final long identity = Binder.clearCallingIdentity(); |
| 7691 | try { |
| 7692 | if (phone != null) { |
| 7693 | return phone.getClientRequestStats(); |
| 7694 | } |
| 7695 | |
| 7696 | return null; |
| 7697 | } finally { |
| 7698 | Binder.restoreCallingIdentity(identity); |
| 7699 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7700 | } |
| 7701 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7702 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7703 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7704 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7705 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7706 | |
| 7707 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7708 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7709 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7710 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7711 | * @param state State of SIM (power down, power up, pass through) |
| 7712 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7713 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7714 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7715 | * |
| 7716 | **/ |
| 7717 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7718 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7719 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7720 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7721 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7722 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7723 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7724 | final long identity = Binder.clearCallingIdentity(); |
| 7725 | try { |
| 7726 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7727 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7728 | } |
| 7729 | } finally { |
| 7730 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7731 | } |
| 7732 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7733 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7734 | private boolean isUssdApiAllowed(int subId) { |
| 7735 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7736 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7737 | if (configManager == null) { |
| 7738 | return false; |
| 7739 | } |
| 7740 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 7741 | if (pb == null) { |
| 7742 | return false; |
| 7743 | } |
| 7744 | return pb.getBoolean( |
| 7745 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 7746 | } |
| 7747 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7748 | /** |
| 7749 | * Check if phone is in emergency callback mode |
| 7750 | * @return true if phone is in emergency callback mode |
| 7751 | * @param subId sub id |
| 7752 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 7753 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7754 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7755 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7756 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7757 | |
| 7758 | final long identity = Binder.clearCallingIdentity(); |
| 7759 | try { |
| 7760 | if (phone != null) { |
| 7761 | return phone.isInEcm(); |
| 7762 | } else { |
| 7763 | return false; |
| 7764 | } |
| 7765 | } finally { |
| 7766 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7767 | } |
| 7768 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7769 | |
| 7770 | /** |
| 7771 | * Get the current signal strength information for the given subscription. |
| 7772 | * Because this information is not updated when the device is in a low power state |
| 7773 | * it should not be relied-upon to be current. |
| 7774 | * @param subId Subscription index |
| 7775 | * @return the most recent cached signal strength info from the modem |
| 7776 | */ |
| 7777 | @Override |
| 7778 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7779 | final long identity = Binder.clearCallingIdentity(); |
| 7780 | try { |
| 7781 | Phone p = getPhone(subId); |
| 7782 | if (p == null) { |
| 7783 | return null; |
| 7784 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7785 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7786 | return p.getSignalStrength(); |
| 7787 | } finally { |
| 7788 | Binder.restoreCallingIdentity(identity); |
| 7789 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7790 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7791 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7792 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7793 | * Get the current modem radio state for the given slot. |
| 7794 | * @param slotIndex slot index. |
| 7795 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7796 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7797 | * @return the current radio power state from the modem |
| 7798 | */ |
| 7799 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7800 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7801 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7802 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7803 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 7804 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7805 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7806 | } |
| 7807 | |
| 7808 | final long identity = Binder.clearCallingIdentity(); |
| 7809 | try { |
| 7810 | return phone.getRadioPowerState(); |
| 7811 | } finally { |
| 7812 | Binder.restoreCallingIdentity(identity); |
| 7813 | } |
| 7814 | } |
| 7815 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7816 | } |
| 7817 | |
| 7818 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7819 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 7820 | * |
| 7821 | * <p>Requires one of the following permissions: |
| 7822 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 7823 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 7824 | * privileges. |
| 7825 | * |
| 7826 | * @param subId subscription id |
| 7827 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 7828 | * {@code false}. |
| 7829 | */ |
| 7830 | @Override |
| 7831 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 7832 | try { |
| 7833 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7834 | null); |
| 7835 | } catch (Exception e) { |
| 7836 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 7837 | mApp, subId, "isDataRoamingEnabled"); |
| 7838 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7839 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7840 | boolean isEnabled = false; |
| 7841 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7842 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7843 | Phone phone = getPhone(subId); |
| 7844 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7845 | } finally { |
| 7846 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7847 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7848 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7849 | } |
| 7850 | |
| 7851 | |
| 7852 | /** |
| 7853 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 7854 | * |
| 7855 | * <p> Requires permission: |
| 7856 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 7857 | * privileges. |
| 7858 | * |
| 7859 | * @param subId subscription id |
| 7860 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 7861 | */ |
| 7862 | @Override |
| 7863 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7864 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7865 | mApp, subId, "setDataRoamingEnabled"); |
| 7866 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7867 | final long identity = Binder.clearCallingIdentity(); |
| 7868 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7869 | Phone phone = getPhone(subId); |
| 7870 | if (phone != null) { |
| 7871 | phone.setDataRoamingEnabled(isEnabled); |
| 7872 | } |
| 7873 | } finally { |
| 7874 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7875 | } |
| 7876 | } |
| 7877 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7878 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7879 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 7880 | TelephonyPermissions |
| 7881 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7882 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 7883 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7884 | boolean isAllowed = true; |
| 7885 | final long identity = Binder.clearCallingIdentity(); |
| 7886 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7887 | Phone phone = getPhone(subId); |
| 7888 | if (phone != null) { |
| 7889 | isAllowed = phone.isCspPlmnEnabled(); |
| 7890 | } |
| 7891 | } finally { |
| 7892 | Binder.restoreCallingIdentity(identity); |
| 7893 | } |
| 7894 | return isAllowed; |
| 7895 | } |
| 7896 | |
| 7897 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7898 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 7899 | // Verify that tha callingPackage belongs to the calling UID |
| 7900 | mApp.getSystemService(AppOpsManager.class) |
| 7901 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 7902 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7903 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7904 | try { |
| 7905 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7906 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7907 | } catch (SecurityException e) { |
| 7908 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 7909 | // has carrier privileges on an active UICC |
| 7910 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 7911 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7912 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7913 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7914 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7915 | |
| 7916 | final long identity = Binder.clearCallingIdentity(); |
| 7917 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7918 | UiccController uiccController = UiccController.getInstance(); |
| 7919 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7920 | if (hasReadPermission) { |
| 7921 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7922 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7923 | |
| 7924 | // Remove private info if the caller doesn't have access |
| 7925 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 7926 | for (UiccCardInfo cardInfo : cardInfos) { |
| 7927 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 7928 | // is available |
| 7929 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 7930 | if (card == null || card.getUiccProfile() == null) { |
| 7931 | // assume no access if the card or profile is unavailable |
| 7932 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7933 | continue; |
| 7934 | } |
| 7935 | UiccProfile profile = card.getUiccProfile(); |
| 7936 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 7937 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7938 | filteredInfos.add(cardInfo); |
| 7939 | } else { |
| 7940 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7941 | } |
| 7942 | } |
| 7943 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7944 | } finally { |
| 7945 | Binder.restoreCallingIdentity(identity); |
| 7946 | } |
| 7947 | } |
| 7948 | |
| 7949 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7950 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7951 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7952 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7953 | final long identity = Binder.clearCallingIdentity(); |
| 7954 | try { |
| 7955 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 7956 | if (slots == null) { |
| 7957 | Rlog.i(LOG_TAG, "slots is null."); |
| 7958 | return null; |
| 7959 | } |
| 7960 | |
| 7961 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 7962 | for (int i = 0; i < slots.length; i++) { |
| 7963 | UiccSlot slot = slots[i]; |
| 7964 | if (slot == null) { |
| 7965 | continue; |
| 7966 | } |
| 7967 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7968 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7969 | UiccCard card = slot.getUiccCard(); |
| 7970 | if (card != null) { |
| 7971 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7972 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 7973 | cardId = slot.getEid(); |
| 7974 | if (TextUtils.isEmpty(cardId)) { |
| 7975 | cardId = slot.getIccId(); |
| 7976 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7977 | } |
| 7978 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 7979 | if (cardId != null) { |
| 7980 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 7981 | // if cardId is an EID, it's all digits so this is fine |
| 7982 | cardId = IccUtils.stripTrailingFs(cardId); |
| 7983 | } |
| 7984 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7985 | int cardState = 0; |
| 7986 | switch (slot.getCardState()) { |
| 7987 | case CARDSTATE_ABSENT: |
| 7988 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 7989 | break; |
| 7990 | case CARDSTATE_PRESENT: |
| 7991 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 7992 | break; |
| 7993 | case CARDSTATE_ERROR: |
| 7994 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 7995 | break; |
| 7996 | case CARDSTATE_RESTRICTED: |
| 7997 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 7998 | break; |
| 7999 | default: |
| 8000 | break; |
| 8001 | |
| 8002 | } |
| 8003 | |
| 8004 | infos[i] = new UiccSlotInfo( |
| 8005 | slot.isActive(), |
| 8006 | slot.isEuicc(), |
| 8007 | cardId, |
| 8008 | cardState, |
| 8009 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8010 | slot.isExtendedApduSupported(), |
| 8011 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8012 | } |
| 8013 | return infos; |
| 8014 | } finally { |
| 8015 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8016 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8017 | } |
| 8018 | |
| 8019 | @Override |
| 8020 | public boolean switchSlots(int[] physicalSlots) { |
| 8021 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8022 | |
| 8023 | final long identity = Binder.clearCallingIdentity(); |
| 8024 | try { |
| 8025 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8026 | } finally { |
| 8027 | Binder.restoreCallingIdentity(identity); |
| 8028 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8029 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8030 | |
| 8031 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8032 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8033 | final long identity = Binder.clearCallingIdentity(); |
| 8034 | try { |
| 8035 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8036 | } finally { |
| 8037 | Binder.restoreCallingIdentity(identity); |
| 8038 | } |
| 8039 | } |
| 8040 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8041 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8042 | * A test API to reload the UICC profile. |
| 8043 | * |
| 8044 | * <p>Requires that the calling app has permission |
| 8045 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8046 | * @hide |
| 8047 | */ |
| 8048 | @Override |
| 8049 | public void refreshUiccProfile(int subId) { |
| 8050 | enforceModifyPermission(); |
| 8051 | |
| 8052 | final long identity = Binder.clearCallingIdentity(); |
| 8053 | try { |
| 8054 | Phone phone = getPhone(subId); |
| 8055 | if (phone == null) { |
| 8056 | return; |
| 8057 | } |
| 8058 | UiccCard uiccCard = phone.getUiccCard(); |
| 8059 | if (uiccCard == null) { |
| 8060 | return; |
| 8061 | } |
| 8062 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8063 | if (uiccProfile == null) { |
| 8064 | return; |
| 8065 | } |
| 8066 | uiccProfile.refresh(); |
| 8067 | } finally { |
| 8068 | Binder.restoreCallingIdentity(identity); |
| 8069 | } |
| 8070 | } |
| 8071 | |
| 8072 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8073 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8074 | */ |
| 8075 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8076 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8077 | } |
| 8078 | |
| 8079 | /** |
| 8080 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8081 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8082 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8083 | */ |
| 8084 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8085 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8086 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8087 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8088 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8089 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8090 | return isDataRoamingEnabled; |
| 8091 | } |
| 8092 | |
| 8093 | /** |
| 8094 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8095 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8096 | */ |
| 8097 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8098 | List<Integer> list = TelephonyProperties.default_network(); |
| 8099 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8100 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8101 | return list.get(phoneId); |
| 8102 | } |
| 8103 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8104 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8105 | |
| 8106 | @Override |
| 8107 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8108 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8109 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8110 | |
| 8111 | final long identity = Binder.clearCallingIdentity(); |
| 8112 | try { |
| 8113 | final Phone phone = getPhone(subId); |
| 8114 | if (phone == null) { |
| 8115 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8116 | return; |
| 8117 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8118 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8119 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8120 | if (carrierPrivilegeRules == null) { |
| 8121 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8122 | } else { |
| 8123 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8124 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8125 | } finally { |
| 8126 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8127 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8128 | } |
| 8129 | |
| 8130 | @Override |
| 8131 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8132 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8133 | |
| 8134 | final long identity = Binder.clearCallingIdentity(); |
| 8135 | try { |
| 8136 | final Phone phone = getPhone(subId); |
| 8137 | if (phone == null) { |
| 8138 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 8139 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 8140 | } |
| 8141 | return phone.getCarrierIdListVersion(); |
| 8142 | } finally { |
| 8143 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8144 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8145 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8146 | |
| 8147 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8148 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 8149 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8150 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8151 | mApp, subId, callingPackage, callingFeatureId, |
| 8152 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8153 | return -1; |
| 8154 | } |
| 8155 | |
| 8156 | final long identity = Binder.clearCallingIdentity(); |
| 8157 | try { |
| 8158 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 8159 | } finally { |
| 8160 | Binder.restoreCallingIdentity(identity); |
| 8161 | } |
| 8162 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8163 | |
| 8164 | @Override |
| 8165 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 8166 | TelephonyPermissions |
| 8167 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8168 | mApp, subId, "getCdmaRoamingMode"); |
| 8169 | |
| 8170 | final long identity = Binder.clearCallingIdentity(); |
| 8171 | try { |
| 8172 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 8173 | } finally { |
| 8174 | Binder.restoreCallingIdentity(identity); |
| 8175 | } |
| 8176 | } |
| 8177 | |
| 8178 | @Override |
| 8179 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 8180 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8181 | mApp, subId, "setCdmaRoamingMode"); |
| 8182 | |
| 8183 | final long identity = Binder.clearCallingIdentity(); |
| 8184 | try { |
| 8185 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 8186 | } finally { |
| 8187 | Binder.restoreCallingIdentity(identity); |
| 8188 | } |
| 8189 | } |
| 8190 | |
| 8191 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8192 | public int getCdmaSubscriptionMode(int subId) { |
| 8193 | TelephonyPermissions |
| 8194 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8195 | mApp, subId, "getCdmaSubscriptionMode"); |
| 8196 | |
| 8197 | final long identity = Binder.clearCallingIdentity(); |
| 8198 | try { |
| 8199 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 8200 | } finally { |
| 8201 | Binder.restoreCallingIdentity(identity); |
| 8202 | } |
| 8203 | } |
| 8204 | |
| 8205 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8206 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 8207 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8208 | mApp, subId, "setCdmaSubscriptionMode"); |
| 8209 | |
| 8210 | final long identity = Binder.clearCallingIdentity(); |
| 8211 | try { |
| 8212 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 8213 | } finally { |
| 8214 | Binder.restoreCallingIdentity(identity); |
| 8215 | } |
| 8216 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8217 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8218 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8219 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8220 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8221 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8222 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 8223 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8224 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8225 | } |
| 8226 | final long identity = Binder.clearCallingIdentity(); |
| 8227 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8228 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 8229 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8230 | if (phone.getEmergencyNumberTracker() != null |
| 8231 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 8232 | emergencyNumberListInternal.put( |
| 8233 | phone.getSubId(), |
| 8234 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 8235 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8236 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8237 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8238 | } finally { |
| 8239 | Binder.restoreCallingIdentity(identity); |
| 8240 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8241 | } |
| 8242 | |
| 8243 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8244 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8245 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8246 | if (!exactMatch) { |
| 8247 | TelephonyPermissions |
| 8248 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8249 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8250 | } |
| 8251 | final long identity = Binder.clearCallingIdentity(); |
| 8252 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8253 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8254 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8255 | && phone.getEmergencyNumberTracker() |
| 8256 | .isEmergencyNumber(number, exactMatch)) { |
| 8257 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8258 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8259 | } |
| 8260 | return false; |
| 8261 | } finally { |
| 8262 | Binder.restoreCallingIdentity(identity); |
| 8263 | } |
| 8264 | } |
| 8265 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8266 | /** |
| 8267 | * Update emergency number list for test mode. |
| 8268 | */ |
| 8269 | @Override |
| 8270 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 8271 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8272 | "updateEmergencyNumberListTestMode"); |
| 8273 | |
| 8274 | final long identity = Binder.clearCallingIdentity(); |
| 8275 | try { |
| 8276 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8277 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8278 | if (tracker != null) { |
| 8279 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 8280 | } |
| 8281 | } |
| 8282 | } finally { |
| 8283 | Binder.restoreCallingIdentity(identity); |
| 8284 | } |
| 8285 | } |
| 8286 | |
| 8287 | /** |
| 8288 | * Get the full emergency number list for test mode. |
| 8289 | */ |
| 8290 | @Override |
| 8291 | public List<String> getEmergencyNumberListTestMode() { |
| 8292 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8293 | "getEmergencyNumberListTestMode"); |
| 8294 | |
| 8295 | final long identity = Binder.clearCallingIdentity(); |
| 8296 | try { |
| 8297 | Set<String> emergencyNumbers = new HashSet<>(); |
| 8298 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8299 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8300 | if (tracker != null) { |
| 8301 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 8302 | emergencyNumbers.add(num.getNumber()); |
| 8303 | } |
| 8304 | } |
| 8305 | } |
| 8306 | return new ArrayList<>(emergencyNumbers); |
| 8307 | } finally { |
| 8308 | Binder.restoreCallingIdentity(identity); |
| 8309 | } |
| 8310 | } |
| 8311 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8312 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8313 | public int getEmergencyNumberDbVersion(int subId) { |
| 8314 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 8315 | |
| 8316 | final long identity = Binder.clearCallingIdentity(); |
| 8317 | try { |
| 8318 | final Phone phone = getPhone(subId); |
| 8319 | if (phone == null) { |
| 8320 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 8321 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 8322 | } |
| 8323 | return phone.getEmergencyNumberDbVersion(); |
| 8324 | } finally { |
| 8325 | Binder.restoreCallingIdentity(identity); |
| 8326 | } |
| 8327 | } |
| 8328 | |
| 8329 | @Override |
| 8330 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 8331 | enforceModifyPermission(); |
| 8332 | |
| 8333 | final long identity = Binder.clearCallingIdentity(); |
| 8334 | try { |
| 8335 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8336 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8337 | if (tracker != null) { |
| 8338 | tracker.updateOtaEmergencyNumberDatabase(); |
| 8339 | } |
| 8340 | } |
| 8341 | } finally { |
| 8342 | Binder.restoreCallingIdentity(identity); |
| 8343 | } |
| 8344 | } |
| 8345 | |
| 8346 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8347 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8348 | enforceActiveEmergencySessionPermission(); |
| 8349 | |
| 8350 | final long identity = Binder.clearCallingIdentity(); |
| 8351 | try { |
| 8352 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8353 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8354 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8355 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 8356 | } |
| 8357 | } |
| 8358 | } finally { |
| 8359 | Binder.restoreCallingIdentity(identity); |
| 8360 | } |
| 8361 | } |
| 8362 | |
| 8363 | @Override |
| 8364 | public void resetOtaEmergencyNumberDbFilePath() { |
| 8365 | enforceActiveEmergencySessionPermission(); |
| 8366 | |
| 8367 | final long identity = Binder.clearCallingIdentity(); |
| 8368 | try { |
| 8369 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8370 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8371 | if (tracker != null) { |
| 8372 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8373 | } |
| 8374 | } |
| 8375 | } finally { |
| 8376 | Binder.restoreCallingIdentity(identity); |
| 8377 | } |
| 8378 | } |
| 8379 | |
| 8380 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8381 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 8382 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 8383 | Phone phone = getPhone(subId); |
| 8384 | if (phone == null) { |
| 8385 | return null; |
| 8386 | } |
| 8387 | final long identity = Binder.clearCallingIdentity(); |
| 8388 | try { |
| 8389 | UiccProfile profile = UiccController.getInstance() |
| 8390 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 8391 | if (profile != null) { |
| 8392 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 8393 | } |
| 8394 | } finally { |
| 8395 | Binder.restoreCallingIdentity(identity); |
| 8396 | } |
| 8397 | return null; |
| 8398 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 8399 | |
| 8400 | /** |
| 8401 | * Enable or disable a modem stack. |
| 8402 | */ |
| 8403 | @Override |
| 8404 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 8405 | enforceModifyPermission(); |
| 8406 | |
| 8407 | final long identity = Binder.clearCallingIdentity(); |
| 8408 | try { |
| 8409 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8410 | if (phone == null) { |
| 8411 | return false; |
| 8412 | } else { |
| 8413 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 8414 | } |
| 8415 | } finally { |
| 8416 | Binder.restoreCallingIdentity(identity); |
| 8417 | } |
| 8418 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8419 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8420 | /** |
| 8421 | * Whether a modem stack is enabled or not. |
| 8422 | */ |
| 8423 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8424 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 8425 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8426 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8427 | if (phone == null) return false; |
| 8428 | |
| 8429 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8430 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 8431 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8432 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8433 | } |
| 8434 | |
| 8435 | final long identity = Binder.clearCallingIdentity(); |
| 8436 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8437 | try { |
| 8438 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 8439 | } catch (NoSuchElementException ex) { |
| 8440 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 8441 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8442 | } finally { |
| 8443 | Binder.restoreCallingIdentity(identity); |
| 8444 | } |
| 8445 | } |
| 8446 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8447 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8448 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8449 | enforceModifyPermission(); |
| 8450 | |
| 8451 | final long identity = Binder.clearCallingIdentity(); |
| 8452 | try { |
| 8453 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8454 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8455 | .commit(); |
| 8456 | } finally { |
| 8457 | Binder.restoreCallingIdentity(identity); |
| 8458 | } |
| 8459 | } |
| 8460 | |
| 8461 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8462 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8463 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8464 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8465 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8466 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8467 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8468 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8469 | |
| 8470 | final long identity = Binder.clearCallingIdentity(); |
| 8471 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8472 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8473 | } finally { |
| 8474 | Binder.restoreCallingIdentity(identity); |
| 8475 | } |
| 8476 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8477 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8478 | @TelephonyManager.IsMultiSimSupportedResult |
| 8479 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8480 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8481 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8482 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8483 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8484 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8485 | } |
| 8486 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8487 | // supported by the modem, indicate that it is restricted. |
| 8488 | PhoneCapability staticCapability = |
| 8489 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8490 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8491 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8492 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8493 | } |
Sarah Chin | 7caee49 | 2020-02-18 20:49:02 +0000 | [diff] [blame] | 8494 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8495 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8496 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8497 | } |
| 8498 | // Check if support of multiple SIMs is restricted by carrier |
| 8499 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8500 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8501 | } |
| 8502 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8503 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8504 | } |
| 8505 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8506 | /** |
| 8507 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8508 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8509 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8510 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8511 | * @param numOfSims number of active sims we want to switch to |
| 8512 | */ |
| 8513 | @Override |
| 8514 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8515 | if (numOfSims == 1) { |
| 8516 | enforceModifyPermission(); |
| 8517 | } else { |
| 8518 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8519 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8520 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8521 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8522 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8523 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8524 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8525 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8526 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8527 | return; |
| 8528 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8529 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8530 | } finally { |
| 8531 | Binder.restoreCallingIdentity(identity); |
| 8532 | } |
| 8533 | } |
| 8534 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8535 | @Override |
| 8536 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8537 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8538 | Phone phone = getPhone(subId); |
| 8539 | if (phone == null) { |
| 8540 | return false; |
| 8541 | } |
| 8542 | final long identity = Binder.clearCallingIdentity(); |
| 8543 | try { |
| 8544 | UiccCard uiccCard = phone.getUiccCard(); |
| 8545 | if (uiccCard == null) { |
| 8546 | return false; |
| 8547 | } |
| 8548 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8549 | if (uiccProfile == null) { |
| 8550 | return false; |
| 8551 | } |
| 8552 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8553 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8554 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8555 | } |
| 8556 | return false; |
| 8557 | } finally { |
| 8558 | Binder.restoreCallingIdentity(identity); |
| 8559 | } |
| 8560 | } |
| 8561 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8562 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8563 | * Get whether making changes to modem configurations will trigger reboot. |
| 8564 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8565 | */ |
| 8566 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8567 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8568 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8569 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8570 | mApp, subId, callingPackage, callingFeatureId, |
| 8571 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8572 | return false; |
| 8573 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8574 | final long identity = Binder.clearCallingIdentity(); |
| 8575 | try { |
| 8576 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8577 | } finally { |
| 8578 | Binder.restoreCallingIdentity(identity); |
| 8579 | } |
| 8580 | } |
| 8581 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8582 | private void updateModemStateMetrics() { |
| 8583 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8584 | // TODO: check the state for each modem if the api is ready. |
| 8585 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8586 | } |
| 8587 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8588 | @Override |
| 8589 | public int[] getSlotsMapping() { |
| 8590 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8591 | |
| 8592 | final long identity = Binder.clearCallingIdentity(); |
| 8593 | try { |
| 8594 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8595 | // All logical slots should have a mapping to a physical slot. |
| 8596 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8597 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8598 | for (int i = 0; i < slotInfos.length; i++) { |
| 8599 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8600 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8601 | } |
| 8602 | } |
| 8603 | return logicalSlotsMapping; |
| 8604 | } finally { |
| 8605 | Binder.restoreCallingIdentity(identity); |
| 8606 | } |
| 8607 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8608 | |
| 8609 | /** |
| 8610 | * Get the IRadio HAL Version |
| 8611 | */ |
| 8612 | @Override |
| 8613 | public int getRadioHalVersion() { |
| 8614 | Phone phone = getDefaultPhone(); |
| 8615 | if (phone == null) return -1; |
| 8616 | HalVersion hv = phone.getHalVersion(); |
| 8617 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8618 | return hv.major * 100 + hv.minor; |
| 8619 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8620 | |
| 8621 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8622 | * Get the current calling package name. |
| 8623 | * @return the current calling package name |
| 8624 | */ |
| 8625 | @Override |
| 8626 | public String getCurrentPackageName() { |
| 8627 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8628 | } |
| 8629 | |
| 8630 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8631 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8632 | * corresponding network requests on a subId. |
| 8633 | * |
| 8634 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8635 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8636 | * 2) APN is un-metered for this subscription, or |
| 8637 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 8638 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8639 | * |
| 8640 | * @return whether data is allowed for a apn type. |
| 8641 | * |
| 8642 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8643 | */ |
| 8644 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8645 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8646 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8647 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8648 | |
| 8649 | // Now that all security checks passes, perform the operation as ourselves. |
| 8650 | final long identity = Binder.clearCallingIdentity(); |
| 8651 | try { |
| 8652 | Phone phone = getPhone(subId); |
| 8653 | if (phone == null) return false; |
| 8654 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8655 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8656 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8657 | } finally { |
| 8658 | Binder.restoreCallingIdentity(identity); |
| 8659 | } |
| 8660 | } |
| 8661 | |
| 8662 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8663 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8664 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8665 | |
| 8666 | // Now that all security checks passes, perform the operation as ourselves. |
| 8667 | final long identity = Binder.clearCallingIdentity(); |
| 8668 | try { |
| 8669 | Phone phone = getPhone(subId); |
| 8670 | if (phone == null) return true; // By default return true. |
| 8671 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8672 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8673 | } finally { |
| 8674 | Binder.restoreCallingIdentity(identity); |
| 8675 | } |
| 8676 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8677 | |
| 8678 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 8679 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 8680 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 8681 | enforceModifyPermission(); |
| 8682 | long token = Binder.clearCallingIdentity(); |
| 8683 | try { |
| 8684 | Phone phone = getPhone(subscriptionId); |
| 8685 | if (phone == null) { |
| 8686 | try { |
| 8687 | if (resultCallback != null) { |
| 8688 | resultCallback.accept(false); |
| 8689 | } |
| 8690 | } catch (RemoteException e) { |
| 8691 | // ignore |
| 8692 | } |
| 8693 | return; |
| 8694 | } |
| 8695 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 8696 | Pair.create(specifiers, (x) -> { |
| 8697 | try { |
| 8698 | if (resultCallback != null) { |
| 8699 | resultCallback.accept(x); |
| 8700 | } |
| 8701 | } catch (RemoteException e) { |
| 8702 | // ignore |
| 8703 | } |
| 8704 | }); |
| 8705 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 8706 | } finally { |
| 8707 | Binder.restoreCallingIdentity(token); |
| 8708 | } |
| 8709 | } |
| 8710 | |
| 8711 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8712 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 8713 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8714 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 8715 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 8716 | if (iccRecords == null) { |
| 8717 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 8718 | return false; |
| 8719 | } |
| 8720 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 8721 | } |
| 8722 | |
| 8723 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8724 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 8725 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8726 | if (callingPackage == null) { |
| 8727 | callingPackage = getCurrentPackageName(); |
| 8728 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8729 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 8730 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8731 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 8732 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8733 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 8734 | } |
| 8735 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 8736 | Intent intent = new Intent(); |
| 8737 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 8738 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 8739 | // Bring up choose default SMS subscription dialog right now |
| 8740 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 8741 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 8742 | mApp.startActivity(intent); |
| 8743 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8744 | |
| 8745 | @Override |
| 8746 | public String getMmsUAProfUrl(int subId) { |
| 8747 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8748 | final long identity = Binder.clearCallingIdentity(); |
| 8749 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 8750 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 8751 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 8752 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 8753 | return carrierUAProfUrl; |
| 8754 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 8755 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8756 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8757 | } finally { |
| 8758 | Binder.restoreCallingIdentity(identity); |
| 8759 | } |
| 8760 | } |
| 8761 | |
| 8762 | @Override |
| 8763 | public String getMmsUserAgent(int subId) { |
| 8764 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8765 | final long identity = Binder.clearCallingIdentity(); |
| 8766 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 8767 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 8768 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 8769 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 8770 | return carrierUserAgent; |
| 8771 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 8772 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8773 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8774 | } finally { |
| 8775 | Binder.restoreCallingIdentity(identity); |
| 8776 | } |
| 8777 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8778 | |
| 8779 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 8780 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 8781 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8782 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8783 | final long identity = Binder.clearCallingIdentity(); |
| 8784 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 8785 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8786 | if (phone == null) return false; |
| 8787 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 8788 | switch (policy) { |
| 8789 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 8790 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 8791 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 8792 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 8793 | default: |
| 8794 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 8795 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8796 | } finally { |
| 8797 | Binder.restoreCallingIdentity(identity); |
| 8798 | } |
| 8799 | } |
| 8800 | |
| 8801 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 8802 | public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy, |
| 8803 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8804 | enforceModifyPermission(); |
| 8805 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8806 | final long identity = Binder.clearCallingIdentity(); |
| 8807 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 8808 | Phone phone = getPhone(subscriptionId); |
| 8809 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8810 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 8811 | switch (policy) { |
| 8812 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 8813 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 8814 | break; |
| 8815 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 8816 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 8817 | break; |
| 8818 | default: |
| 8819 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 8820 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8821 | } finally { |
| 8822 | Binder.restoreCallingIdentity(identity); |
| 8823 | } |
| 8824 | } |
| 8825 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8826 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 8827 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8828 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 8829 | * otherwise. |
| 8830 | */ |
| 8831 | @Override |
| 8832 | public void setCepEnabled(boolean isCepEnabled) { |
| 8833 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 8834 | |
| 8835 | final long identity = Binder.clearCallingIdentity(); |
| 8836 | try { |
| 8837 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 8838 | for (Phone phone : PhoneFactory.getPhones()) { |
| 8839 | Phone defaultPhone = phone.getImsPhone(); |
| 8840 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 8841 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 8842 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 8843 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 8844 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 8845 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 8846 | + imsPhone.getMsisdn()); |
| 8847 | } |
| 8848 | } |
| 8849 | } finally { |
| 8850 | Binder.restoreCallingIdentity(identity); |
| 8851 | } |
| 8852 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 8853 | |
| 8854 | /** |
| 8855 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 8856 | * |
| 8857 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 8858 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 8859 | * before being read. |
| 8860 | */ |
| 8861 | @Override |
| 8862 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 8863 | isCompressed) { |
| 8864 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8865 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
| 8866 | try { |
| 8867 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 8868 | if (configBinder == null) { |
| 8869 | Rlog.e(LOG_TAG, "null result for getImsConfig"); |
| 8870 | } else { |
| 8871 | configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed); |
| 8872 | } |
| 8873 | } catch (RemoteException e) { |
| 8874 | Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage()); |
| 8875 | } |
| 8876 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8877 | |
| 8878 | @Override |
| 8879 | public boolean isIccLockEnabled(int subId) { |
| 8880 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 8881 | |
| 8882 | // Now that all security checks passes, perform the operation as ourselves. |
| 8883 | final long identity = Binder.clearCallingIdentity(); |
| 8884 | try { |
| 8885 | Phone phone = getPhone(subId); |
| 8886 | if (phone != null && phone.getIccCard() != null) { |
| 8887 | return phone.getIccCard().getIccLockEnabled(); |
| 8888 | } else { |
| 8889 | return false; |
| 8890 | } |
| 8891 | } finally { |
| 8892 | Binder.restoreCallingIdentity(identity); |
| 8893 | } |
| 8894 | } |
| 8895 | |
| 8896 | /** |
| 8897 | * Set the ICC pin lock enabled or disabled. |
| 8898 | * |
| 8899 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 8900 | * three cases: |
| 8901 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 8902 | * successfully. |
| 8903 | * - Positive number and zero for remaining password attempts. |
| 8904 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 8905 | * |
| 8906 | */ |
| 8907 | @Override |
| 8908 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 8909 | enforceModifyPermission(); |
| 8910 | |
| 8911 | Phone phone = getPhone(subId); |
| 8912 | if (phone == null) { |
| 8913 | return 0; |
| 8914 | } |
| 8915 | // Now that all security checks passes, perform the operation as ourselves. |
| 8916 | final long identity = Binder.clearCallingIdentity(); |
| 8917 | try { |
| 8918 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 8919 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 8920 | return attemptsRemaining; |
| 8921 | |
| 8922 | } catch (Exception e) { |
| 8923 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 8924 | } finally { |
| 8925 | Binder.restoreCallingIdentity(identity); |
| 8926 | } |
| 8927 | return 0; |
| 8928 | } |
| 8929 | |
| 8930 | /** |
| 8931 | * Change the ICC password used in ICC pin lock. |
| 8932 | * |
| 8933 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 8934 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 8935 | * - Positive number and zero for remaining password attempts. |
| 8936 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 8937 | * |
| 8938 | */ |
| 8939 | @Override |
| 8940 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 8941 | enforceModifyPermission(); |
| 8942 | |
| 8943 | Phone phone = getPhone(subId); |
| 8944 | if (phone == null) { |
| 8945 | return 0; |
| 8946 | } |
| 8947 | // Now that all security checks passes, perform the operation as ourselves. |
| 8948 | final long identity = Binder.clearCallingIdentity(); |
| 8949 | try { |
| 8950 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 8951 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 8952 | return attemptsRemaining; |
| 8953 | |
| 8954 | } catch (Exception e) { |
| 8955 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 8956 | } finally { |
| 8957 | Binder.restoreCallingIdentity(identity); |
| 8958 | } |
| 8959 | return 0; |
| 8960 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 8961 | |
| 8962 | /** |
| 8963 | * Request for receiving user activity notification |
| 8964 | */ |
| 8965 | @Override |
| 8966 | public void requestUserActivityNotification() { |
| 8967 | if (!mNotifyUserActivity.get() |
| 8968 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 8969 | mNotifyUserActivity.set(true); |
| 8970 | } |
| 8971 | } |
| 8972 | |
| 8973 | /** |
| 8974 | * Called when userActivity is signalled in the power manager. |
| 8975 | * This is safe to call from any thread, with any window manager locks held or not. |
| 8976 | */ |
| 8977 | @Override |
| 8978 | public void userActivity() { |
| 8979 | // *************************************** |
| 8980 | // * Inherited from PhoneWindowManager * |
| 8981 | // *************************************** |
| 8982 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 8983 | // WITH ITS LOCKS HELD. |
| 8984 | // |
| 8985 | // This code must be VERY careful about the locks |
| 8986 | // it acquires. |
| 8987 | // In fact, the current code acquires way too many, |
| 8988 | // and probably has lurking deadlocks. |
| 8989 | |
| 8990 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 8991 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 8992 | } |
| 8993 | |
| 8994 | if (mNotifyUserActivity.getAndSet(false)) { |
| 8995 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 8996 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 8997 | } |
| 8998 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 8999 | |
| 9000 | @Override |
| 9001 | public boolean canConnectTo5GInDsdsMode() { |
| 9002 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9003 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9004 | |
| 9005 | @Override |
| 9006 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 9007 | String callingFeatureId) { |
| 9008 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 9009 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 9010 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9011 | } |
| 9012 | |
| 9013 | Phone phone = getPhone(subId); |
| 9014 | if (phone == null) { |
| 9015 | throw new RuntimeException("phone is not available"); |
| 9016 | } |
| 9017 | // Now that all security checks passes, perform the operation as ourselves. |
| 9018 | final long identity = Binder.clearCallingIdentity(); |
| 9019 | try { |
| 9020 | return phone.getEquivalentHomePlmns(); |
| 9021 | } finally { |
| 9022 | Binder.restoreCallingIdentity(identity); |
| 9023 | } |
| 9024 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame^] | 9025 | |
| 9026 | @Override |
| 9027 | public boolean isRadioInterfaceCapabilitySupported( |
| 9028 | @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 9029 | RadioInterfaceCapabilities radioInterfaceCapabilities = |
| 9030 | mPhoneConfigurationManager.getRadioInterfaceCapabilities(); |
| 9031 | if (radioInterfaceCapabilities == null) { |
| 9032 | throw new RuntimeException("radio interface capabilities are not available"); |
| 9033 | } else { |
| 9034 | return radioInterfaceCapabilities.isSupported(capability); |
| 9035 | } |
| 9036 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 9037 | } |