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; |
changbetty | 363e8ac | 2019-12-06 18:16:37 +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; |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 48 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 49 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 50 | import android.os.PersistableBundle; |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 51 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 52 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 53 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 54 | import android.os.ServiceSpecificException; |
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 | 8ff344d | 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 | 8d298d4 | 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 | c7b18ec | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 66 | import android.telephony.Annotation.ApnType; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 67 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 68 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 69 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 70 | import android.telephony.CellIdentity; |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 71 | import android.telephony.CellIdentityCdma; |
| 72 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 73 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 74 | import android.telephony.CellInfoGsm; |
| 75 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 76 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 77 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 78 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 79 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 80 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 81 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 82 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 83 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 84 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 85 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 86 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 87 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 88 | import android.telephony.SignalStrength; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 89 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 90 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 91 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 92 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 93 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 94 | import android.telephony.TelephonyScanManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 95 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 96 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 97 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 98 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 99 | import android.telephony.data.ApnSetting; |
| 100 | import android.telephony.emergency.EmergencyNumber; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 101 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 102 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 103 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 104 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 105 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 106 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 107 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 108 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 109 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 110 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 111 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 112 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 113 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 114 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 115 | import android.util.ArraySet; |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 116 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 117 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 118 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 119 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 120 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 121 | import com.android.ims.internal.IImsServiceFeatureCallback; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 122 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 123 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 124 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 126 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 127 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.CommandException; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 129 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 130 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 131 | import com.android.internal.telephony.HalVersion; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 132 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 134 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 135 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 137 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 143 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 152 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 153 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 156 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 158 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 160 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 161 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 162 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 164 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 168 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 170 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 171 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 172 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 173 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 174 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 175 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 176 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 177 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 178 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 179 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 180 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 181 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 182 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 183 | import java.io.FileDescriptor; |
| 184 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 185 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 186 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 187 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 188 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 189 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 190 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 191 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 192 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 193 | import java.util.Set; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 194 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 195 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 196 | |
| 197 | /** |
| 198 | * Implementation of the ITelephony interface. |
| 199 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 200 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 201 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 202 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 203 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 204 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 205 | |
| 206 | // Message codes used with mMainThreadHandler |
| 207 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 208 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 209 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 210 | private static final int CMD_OPEN_CHANNEL = 9; |
| 211 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 212 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 213 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 214 | private static final int CMD_NV_READ_ITEM = 13; |
| 215 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 216 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 217 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 218 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 219 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 220 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 221 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 222 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 223 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 224 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 225 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 226 | private static final int CMD_SEND_ENVELOPE = 25; |
| 227 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 228 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 229 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 230 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 231 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 232 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 233 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 234 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 235 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 236 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 237 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 238 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 239 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 240 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 241 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 242 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 243 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 244 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 245 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 246 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 247 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 248 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 249 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 250 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 251 | private static final int CMD_SWITCH_SLOTS = 50; |
| 252 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 253 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 254 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 255 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 256 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 257 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 258 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 259 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 260 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 261 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 262 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 263 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 264 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 265 | private static final int CMD_MODEM_REBOOT = 64; |
| 266 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 267 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 268 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 269 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 270 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 271 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 272 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 273 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 274 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 275 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 276 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 277 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 278 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 279 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 280 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 281 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 282 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 283 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 284 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 285 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 286 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 287 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 288 | private static final int CMD_GET_CALL_WAITING = 87; |
| 289 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 290 | private static final int CMD_SET_CALL_WAITING = 89; |
| 291 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 292 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 293 | // Parameters of select command. |
| 294 | private static final int SELECT_COMMAND = 0xA4; |
| 295 | private static final int SELECT_P1 = 0x04; |
| 296 | private static final int SELECT_P2 = 0; |
| 297 | private static final int SELECT_P3 = 0x10; |
| 298 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 299 | /** The singleton instance. */ |
| 300 | private static PhoneInterfaceManager sInstance; |
| 301 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 302 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 303 | private CallManager mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 304 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 305 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 306 | private AppOpsManager mAppOps; |
| 307 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 308 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 309 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 310 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 311 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 312 | /** User Activity */ |
| 313 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 314 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 315 | |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 316 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 317 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 318 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 319 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 320 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 321 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 322 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 323 | // String to store multi SIM allowed |
| 324 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 325 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 326 | // The AID of ISD-R. |
| 327 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 328 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 329 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 330 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 331 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 332 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 333 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 334 | /** |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 335 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 336 | */ |
| 337 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 338 | "reset_network_erase_modem_config_enabled"; |
| 339 | |
| 340 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 341 | * A request object to use for transmitting data to an ICC. |
| 342 | */ |
| 343 | private static final class IccAPDUArgument { |
| 344 | public int channel, cla, command, p1, p2, p3; |
| 345 | public String data; |
| 346 | |
| 347 | public IccAPDUArgument(int channel, int cla, int command, |
| 348 | int p1, int p2, int p3, String data) { |
| 349 | this.channel = channel; |
| 350 | this.cla = cla; |
| 351 | this.command = command; |
| 352 | this.p1 = p1; |
| 353 | this.p2 = p2; |
| 354 | this.p3 = p3; |
| 355 | this.data = data; |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 360 | * A request object to use for transmitting data to an ICC. |
| 361 | */ |
| 362 | private static final class ManualNetworkSelectionArgument { |
| 363 | public OperatorInfo operatorInfo; |
| 364 | public boolean persistSelection; |
| 365 | |
| 366 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 367 | this.operatorInfo = operatorInfo; |
| 368 | this.persistSelection = persistSelection; |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 373 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 374 | * request after sending. The main thread will notify the request when it is complete. |
| 375 | */ |
| 376 | private static final class MainThreadRequest { |
| 377 | /** The argument to use for the request */ |
| 378 | public Object argument; |
| 379 | /** The result of the request that is run on the main thread */ |
| 380 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 381 | // The subscriber id that this request applies to. Defaults to |
| 382 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 383 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 384 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 385 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 386 | public Phone phone; |
| 387 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 388 | public WorkSource workSource; |
| 389 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 390 | public MainThreadRequest(Object argument) { |
| 391 | this.argument = argument; |
| 392 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 393 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 394 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 395 | this.argument = argument; |
| 396 | if (phone != null) { |
| 397 | this.phone = phone; |
| 398 | } |
| 399 | this.workSource = workSource; |
| 400 | } |
| 401 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 402 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 403 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 404 | if (subId != null) { |
| 405 | this.subId = subId; |
| 406 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 407 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 408 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 409 | } |
| 410 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 411 | private static final class IncomingThirdPartyCallArgs { |
| 412 | public final ComponentName component; |
| 413 | public final String callId; |
| 414 | public final String callerDisplayName; |
| 415 | |
| 416 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 417 | String callerDisplayName) { |
| 418 | this.component = component; |
| 419 | this.callId = callId; |
| 420 | this.callerDisplayName = callerDisplayName; |
| 421 | } |
| 422 | } |
| 423 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 424 | /** |
| 425 | * A handler that processes messages on the main thread in the phone process. Since many |
| 426 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 427 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 428 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 429 | * on, which will be notified when the operation completes and will contain the result of the |
| 430 | * request. |
| 431 | * |
| 432 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 433 | * note that request.result must be set to something non-null for the calling thread to |
| 434 | * unblock. |
| 435 | */ |
| 436 | private final class MainThreadHandler extends Handler { |
| 437 | @Override |
| 438 | public void handleMessage(Message msg) { |
| 439 | MainThreadRequest request; |
| 440 | Message onCompleted; |
| 441 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 442 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 443 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 444 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 445 | |
| 446 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 447 | case CMD_HANDLE_USSD_REQUEST: { |
| 448 | request = (MainThreadRequest) msg.obj; |
| 449 | final Phone phone = getPhoneFromRequest(request); |
| 450 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 451 | String ussdRequest = ussdObject.first; |
| 452 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 453 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 454 | if (!isUssdApiAllowed(request.subId)) { |
| 455 | // Carrier does not support use of this API, return failure. |
| 456 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 457 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 458 | Bundle returnData = new Bundle(); |
| 459 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 460 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
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 | request.result = true; |
| 463 | notifyRequester(request); |
| 464 | return; |
| 465 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 466 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 467 | try { |
| 468 | request.result = phone != null |
| 469 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 470 | } catch (CallStateException cse) { |
| 471 | request.result = false; |
| 472 | } |
| 473 | // Wake up the requesting thread |
| 474 | notifyRequester(request); |
| 475 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 476 | } |
| 477 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 478 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 479 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 480 | final Phone phone = getPhoneFromRequest(request); |
| 481 | request.result = phone != null ? |
| 482 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 483 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 484 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 485 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 486 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 487 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 488 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 489 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 490 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 491 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 492 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 493 | if (uiccCard == null) { |
| 494 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 495 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 496 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 497 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 498 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 499 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 500 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 501 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 502 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 503 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 504 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 505 | break; |
| 506 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 507 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 508 | ar = (AsyncResult) msg.obj; |
| 509 | request = (MainThreadRequest) ar.userObj; |
| 510 | if (ar.exception == null && ar.result != null) { |
| 511 | request.result = ar.result; |
| 512 | } else { |
| 513 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 514 | if (ar.result == null) { |
| 515 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 516 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 517 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 518 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 519 | } else { |
| 520 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 521 | } |
| 522 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 523 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 524 | break; |
| 525 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 526 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 527 | request = (MainThreadRequest) msg.obj; |
| 528 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 529 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 530 | if (uiccCard == null) { |
| 531 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 532 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 533 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 534 | } else { |
| 535 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 536 | request); |
| 537 | uiccCard.iccTransmitApduBasicChannel( |
| 538 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 539 | iccArgument.p3, iccArgument.data, onCompleted); |
| 540 | } |
| 541 | break; |
| 542 | |
| 543 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 544 | ar = (AsyncResult) msg.obj; |
| 545 | request = (MainThreadRequest) ar.userObj; |
| 546 | if (ar.exception == null && ar.result != null) { |
| 547 | request.result = ar.result; |
| 548 | } else { |
| 549 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 550 | if (ar.result == null) { |
| 551 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 552 | } else if (ar.exception instanceof CommandException) { |
| 553 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 554 | ar.exception); |
| 555 | } else { |
| 556 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 557 | } |
| 558 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 559 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 560 | break; |
| 561 | |
| 562 | case CMD_EXCHANGE_SIM_IO: |
| 563 | request = (MainThreadRequest) msg.obj; |
| 564 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 565 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 566 | if (uiccCard == null) { |
| 567 | loge("iccExchangeSimIO: No UICC"); |
| 568 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 569 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 570 | } else { |
| 571 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 572 | request); |
| 573 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 574 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 575 | iccArgument.data, onCompleted); |
| 576 | } |
| 577 | break; |
| 578 | |
| 579 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 580 | ar = (AsyncResult) msg.obj; |
| 581 | request = (MainThreadRequest) ar.userObj; |
| 582 | if (ar.exception == null && ar.result != null) { |
| 583 | request.result = ar.result; |
| 584 | } else { |
| 585 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 586 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 587 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 588 | break; |
| 589 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 590 | case CMD_SEND_ENVELOPE: |
| 591 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 592 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 593 | if (uiccCard == null) { |
| 594 | loge("sendEnvelopeWithStatus: No UICC"); |
| 595 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 596 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 597 | } else { |
| 598 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 599 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 600 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 601 | break; |
| 602 | |
| 603 | case EVENT_SEND_ENVELOPE_DONE: |
| 604 | ar = (AsyncResult) msg.obj; |
| 605 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 606 | if (ar.exception == null && ar.result != null) { |
| 607 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 608 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 609 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 610 | if (ar.result == null) { |
| 611 | loge("sendEnvelopeWithStatus: Empty response"); |
| 612 | } else if (ar.exception instanceof CommandException) { |
| 613 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 614 | ar.exception); |
| 615 | } else { |
| 616 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 617 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 618 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 619 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 620 | break; |
| 621 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 622 | case CMD_OPEN_CHANNEL: |
| 623 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 624 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 625 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 626 | if (uiccCard == null) { |
| 627 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 628 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 629 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 630 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 631 | } else { |
| 632 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 633 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 634 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 635 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 636 | break; |
| 637 | |
| 638 | case EVENT_OPEN_CHANNEL_DONE: |
| 639 | ar = (AsyncResult) msg.obj; |
| 640 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 641 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 642 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 643 | int[] result = (int[]) ar.result; |
| 644 | int channelId = result[0]; |
| 645 | byte[] selectResponse = null; |
| 646 | if (result.length > 1) { |
| 647 | selectResponse = new byte[result.length - 1]; |
| 648 | for (int i = 1; i < result.length; ++i) { |
| 649 | selectResponse[i - 1] = (byte) result[i]; |
| 650 | } |
| 651 | } |
| 652 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 653 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 654 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 655 | if (ar.result == null) { |
| 656 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 657 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 658 | if (ar.exception != null) { |
| 659 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 660 | } |
| 661 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 662 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 663 | if (ar.exception instanceof CommandException) { |
| 664 | CommandException.Error error = |
| 665 | ((CommandException) (ar.exception)).getCommandError(); |
| 666 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 667 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 668 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 669 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 670 | } |
| 671 | } |
| 672 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 673 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 674 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 675 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 676 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 677 | break; |
| 678 | |
| 679 | case CMD_CLOSE_CHANNEL: |
| 680 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 681 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 682 | if (uiccCard == null) { |
| 683 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 684 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 685 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 686 | } else { |
| 687 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 688 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 689 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 690 | break; |
| 691 | |
| 692 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 693 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 694 | break; |
| 695 | |
| 696 | case CMD_NV_READ_ITEM: |
| 697 | request = (MainThreadRequest) msg.obj; |
| 698 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 699 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 700 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 701 | break; |
| 702 | |
| 703 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 704 | ar = (AsyncResult) msg.obj; |
| 705 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 706 | if (ar.exception == null && ar.result != null) { |
| 707 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 708 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 709 | request.result = ""; |
| 710 | if (ar.result == null) { |
| 711 | loge("nvReadItem: Empty response"); |
| 712 | } else if (ar.exception instanceof CommandException) { |
| 713 | loge("nvReadItem: CommandException: " + |
| 714 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 715 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 716 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 717 | } |
| 718 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 719 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 720 | break; |
| 721 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 722 | case CMD_NV_WRITE_ITEM: |
| 723 | request = (MainThreadRequest) msg.obj; |
| 724 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 725 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 726 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 727 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 728 | break; |
| 729 | |
| 730 | case EVENT_NV_WRITE_ITEM_DONE: |
| 731 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 732 | break; |
| 733 | |
| 734 | case CMD_NV_WRITE_CDMA_PRL: |
| 735 | request = (MainThreadRequest) msg.obj; |
| 736 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 737 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 738 | break; |
| 739 | |
| 740 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 741 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 742 | break; |
| 743 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 744 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 745 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 746 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 747 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 748 | break; |
| 749 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 750 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 751 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 752 | break; |
| 753 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 754 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 755 | request = (MainThreadRequest) msg.obj; |
| 756 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 757 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 758 | break; |
| 759 | |
| 760 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 761 | ar = (AsyncResult) msg.obj; |
| 762 | request = (MainThreadRequest) ar.userObj; |
| 763 | if (ar.exception == null && ar.result != null) { |
| 764 | request.result = ar.result; // Integer |
| 765 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 766 | // request.result must be set to something non-null |
| 767 | // for the calling thread to unblock |
| 768 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 769 | if (ar.result == null) { |
| 770 | loge("getPreferredNetworkType: Empty response"); |
| 771 | } else if (ar.exception instanceof CommandException) { |
| 772 | loge("getPreferredNetworkType: CommandException: " + |
| 773 | ar.exception); |
| 774 | } else { |
| 775 | loge("getPreferredNetworkType: Unknown exception"); |
| 776 | } |
| 777 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 778 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 779 | break; |
| 780 | |
| 781 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 782 | request = (MainThreadRequest) msg.obj; |
| 783 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 784 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 785 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 786 | break; |
| 787 | |
| 788 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 789 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 790 | break; |
| 791 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 792 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 793 | request = (MainThreadRequest)msg.obj; |
| 794 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 795 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 796 | break; |
| 797 | |
| 798 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 799 | ar = (AsyncResult)msg.obj; |
| 800 | request = (MainThreadRequest)ar.userObj; |
| 801 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 802 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 803 | break; |
| 804 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 805 | case CMD_SET_VOICEMAIL_NUMBER: |
| 806 | request = (MainThreadRequest) msg.obj; |
| 807 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 808 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 809 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 810 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 811 | break; |
| 812 | |
| 813 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 814 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 815 | break; |
| 816 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 817 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 818 | request = (MainThreadRequest) msg.obj; |
| 819 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 820 | request); |
| 821 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 822 | break; |
| 823 | |
| 824 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 825 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 826 | break; |
| 827 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 828 | case CMD_PERFORM_NETWORK_SCAN: |
| 829 | request = (MainThreadRequest) msg.obj; |
| 830 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 831 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 832 | break; |
| 833 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 834 | case CMD_GET_CALL_FORWARDING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 835 | request = (MainThreadRequest) msg.obj; |
| 836 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 837 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 838 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 839 | request.argument; |
| 840 | int callForwardingReason = args.first; |
| 841 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 842 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 843 | } |
| 844 | case EVENT_GET_CALL_FORWARDING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 845 | ar = (AsyncResult) msg.obj; |
| 846 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 847 | TelephonyManager.CallForwardingInfoCallback callback = |
| 848 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 849 | request.argument).second; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 850 | if (ar.exception == null && ar.result != null) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 851 | CallForwardingInfo callForwardingInfo = null; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 852 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 853 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 854 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 855 | // any service for voice call. |
| 856 | if ((callForwardInfo.serviceClass |
| 857 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 858 | callForwardingInfo = new CallForwardingInfo(true, |
| 859 | callForwardInfo.reason, |
| 860 | callForwardInfo.number, |
| 861 | callForwardInfo.timeSeconds); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 862 | break; |
| 863 | } |
| 864 | } |
| 865 | // Didn't find a call forward info for voice call. |
| 866 | if (callForwardingInfo == null) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 867 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 868 | 0 /* reason */, null /* number */, 0 /* timeout */); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 869 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 870 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 871 | } else { |
| 872 | if (ar.result == null) { |
| 873 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 874 | } |
| 875 | if (ar.exception != null) { |
| 876 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 877 | } |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 878 | int errorCode = TelephonyManager |
| 879 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 880 | if (ar.exception instanceof CommandException) { |
| 881 | CommandException.Error error = |
| 882 | ((CommandException) (ar.exception)).getCommandError(); |
| 883 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 884 | errorCode = TelephonyManager |
| 885 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 886 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 887 | errorCode = TelephonyManager |
| 888 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 889 | } |
| 890 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 891 | callback.onError(errorCode); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 892 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 893 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 894 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 895 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 896 | case CMD_SET_CALL_FORWARDING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 897 | request = (MainThreadRequest) msg.obj; |
| 898 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 899 | request = (MainThreadRequest) msg.obj; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 900 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 901 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 902 | request.argument).first; |
| 903 | request.phone.setCallForwardingOption( |
| 904 | callForwardingInfoToSet.isEnabled() |
| 905 | ? CommandsInterface.CF_ACTION_ENABLE |
| 906 | : CommandsInterface.CF_ACTION_DISABLE, |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 907 | callForwardingInfoToSet.getReason(), |
| 908 | callForwardingInfoToSet.getNumber(), |
| 909 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 910 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 911 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 912 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 913 | case EVENT_SET_CALL_FORWARDING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 914 | ar = (AsyncResult) msg.obj; |
| 915 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 916 | Consumer<Integer> callback = |
| 917 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 918 | request.argument).second; |
| 919 | if (ar.exception != null) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 920 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 921 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 922 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 923 | if (ar.exception instanceof CommandException) { |
| 924 | CommandException.Error error = |
| 925 | ((CommandException) (ar.exception)).getCommandError(); |
| 926 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 927 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 928 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 929 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 930 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 931 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 932 | } |
| 933 | } |
| 934 | callback.accept(errorCode); |
| 935 | } else { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 936 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 937 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 938 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 939 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 940 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 941 | case CMD_GET_CALL_WAITING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 942 | request = (MainThreadRequest) msg.obj; |
| 943 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 944 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 945 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 946 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 947 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 948 | case EVENT_GET_CALL_WAITING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 949 | ar = (AsyncResult) msg.obj; |
| 950 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 951 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 952 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 953 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 954 | int[] callForwardResults = (int[]) ar.result; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 955 | // Service Class is a bit mask per 3gpp 27.007. |
| 956 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 957 | if (callForwardResults.length > 1 |
| 958 | && ((callForwardResults[1] |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 959 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 960 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 961 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 962 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 963 | } else { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 964 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 965 | } |
| 966 | } else { |
| 967 | if (ar.result == null) { |
| 968 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 969 | } |
| 970 | if (ar.exception != null) { |
| 971 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 972 | } |
| 973 | if (ar.exception instanceof CommandException) { |
| 974 | CommandException.Error error = |
| 975 | ((CommandException) (ar.exception)).getCommandError(); |
| 976 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 977 | callForwardingStatus = |
| 978 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 979 | } |
| 980 | } |
| 981 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 982 | callback.accept(callForwardingStatus); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 983 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 984 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 985 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 986 | case CMD_SET_CALL_WAITING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 987 | request = (MainThreadRequest) msg.obj; |
| 988 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 989 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 990 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 991 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 992 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 993 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 994 | case EVENT_SET_CALL_WAITING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 995 | ar = (AsyncResult) msg.obj; |
| 996 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 997 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 998 | Consumer<Integer> callback = |
| 999 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1000 | if (ar.exception != null) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1001 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1002 | if (ar.exception instanceof CommandException) { |
| 1003 | CommandException.Error error = |
| 1004 | ((CommandException) (ar.exception)).getCommandError(); |
| 1005 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1006 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1007 | } else { |
| 1008 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1009 | } |
| 1010 | } else { |
| 1011 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1012 | } |
| 1013 | } else { |
| 1014 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1015 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1016 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1017 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1018 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1019 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1020 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1021 | ar = (AsyncResult) msg.obj; |
| 1022 | request = (MainThreadRequest) ar.userObj; |
| 1023 | CellNetworkScanResult cellScanResult; |
| 1024 | if (ar.exception == null && ar.result != null) { |
| 1025 | cellScanResult = new CellNetworkScanResult( |
| 1026 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1027 | (List<OperatorInfo>) ar.result); |
| 1028 | } else { |
| 1029 | if (ar.result == null) { |
| 1030 | loge("getCellNetworkScanResults: Empty response"); |
| 1031 | } |
| 1032 | if (ar.exception != null) { |
| 1033 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1034 | } |
| 1035 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1036 | if (ar.exception instanceof CommandException) { |
| 1037 | CommandException.Error error = |
| 1038 | ((CommandException) (ar.exception)).getCommandError(); |
| 1039 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1040 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1041 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1042 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1043 | } |
| 1044 | } |
| 1045 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1046 | } |
| 1047 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1048 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1049 | break; |
| 1050 | |
| 1051 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1052 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1053 | ManualNetworkSelectionArgument selArg = |
| 1054 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1055 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1056 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1057 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1058 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1059 | break; |
| 1060 | |
| 1061 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1062 | ar = (AsyncResult) msg.obj; |
| 1063 | request = (MainThreadRequest) ar.userObj; |
| 1064 | if (ar.exception == null) { |
| 1065 | request.result = true; |
| 1066 | } else { |
| 1067 | request.result = false; |
| 1068 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1069 | } |
| 1070 | notifyRequester(request); |
| 1071 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1072 | break; |
| 1073 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1074 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1075 | request = (MainThreadRequest) msg.obj; |
| 1076 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1077 | if (defaultPhone != null) { |
| 1078 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1079 | } else { |
| 1080 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1081 | Bundle bundle = new Bundle(); |
| 1082 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
| 1083 | new ModemActivityInfo(0, 0, 0, new int[0], 0)); |
| 1084 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1085 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1086 | break; |
| 1087 | |
| 1088 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 1089 | ar = (AsyncResult) msg.obj; |
| 1090 | request = (MainThreadRequest) ar.userObj; |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1091 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1092 | |
| 1093 | ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1094 | if (ar.exception == null && ar.result != null) { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1095 | // Update the last modem activity info and the result of the request. |
| 1096 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1097 | if (isModemActivityInfoValid(info)) { |
| 1098 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 1099 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1100 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1101 | .getTransmitTimeMillis(); |
| 1102 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1103 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1104 | } |
| 1105 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 1106 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1107 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1108 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1109 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1110 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1111 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1112 | info.getReceiveTimeMillis() |
| 1113 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1114 | } |
| 1115 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 1116 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1117 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1118 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1119 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1120 | } else { |
| 1121 | if (ar.result == null) { |
| 1122 | loge("queryModemActivityInfo: Empty response"); |
| 1123 | } else if (ar.exception instanceof CommandException) { |
| 1124 | loge("queryModemActivityInfo: CommandException: " + |
| 1125 | ar.exception); |
| 1126 | } else { |
| 1127 | loge("queryModemActivityInfo: Unknown exception"); |
| 1128 | } |
| 1129 | } |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1130 | Bundle bundle = new Bundle(); |
| 1131 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1132 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1133 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1134 | break; |
| 1135 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1136 | case CMD_SET_ALLOWED_CARRIERS: |
| 1137 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1138 | CarrierRestrictionRules argument = |
| 1139 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1140 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1141 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1142 | break; |
| 1143 | |
| 1144 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1145 | ar = (AsyncResult) msg.obj; |
| 1146 | request = (MainThreadRequest) ar.userObj; |
| 1147 | if (ar.exception == null && ar.result != null) { |
| 1148 | request.result = ar.result; |
| 1149 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1150 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1151 | if (ar.exception instanceof CommandException) { |
| 1152 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1153 | CommandException.Error error = |
| 1154 | ((CommandException) (ar.exception)).getCommandError(); |
| 1155 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1156 | request.result = |
| 1157 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1158 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1159 | } else { |
| 1160 | loge("setAllowedCarriers: Unknown exception"); |
| 1161 | } |
| 1162 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1163 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1164 | break; |
| 1165 | |
| 1166 | case CMD_GET_ALLOWED_CARRIERS: |
| 1167 | request = (MainThreadRequest) msg.obj; |
| 1168 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1169 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1170 | break; |
| 1171 | |
| 1172 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1173 | ar = (AsyncResult) msg.obj; |
| 1174 | request = (MainThreadRequest) ar.userObj; |
| 1175 | if (ar.exception == null && ar.result != null) { |
| 1176 | request.result = ar.result; |
| 1177 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1178 | request.result = new IllegalStateException( |
| 1179 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1180 | if (ar.result == null) { |
| 1181 | loge("getAllowedCarriers: Empty response"); |
| 1182 | } else if (ar.exception instanceof CommandException) { |
| 1183 | loge("getAllowedCarriers: CommandException: " + |
| 1184 | ar.exception); |
| 1185 | } else { |
| 1186 | loge("getAllowedCarriers: Unknown exception"); |
| 1187 | } |
| 1188 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1189 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1190 | break; |
| 1191 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1192 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1193 | ar = (AsyncResult) msg.obj; |
| 1194 | request = (MainThreadRequest) ar.userObj; |
| 1195 | if (ar.exception == null && ar.result != null) { |
| 1196 | request.result = ar.result; |
| 1197 | } else { |
| 1198 | request.result = new IllegalArgumentException( |
| 1199 | "Failed to retrieve Forbidden Plmns"); |
| 1200 | if (ar.result == null) { |
| 1201 | loge("getForbiddenPlmns: Empty response"); |
| 1202 | } else { |
| 1203 | loge("getForbiddenPlmns: Unknown exception"); |
| 1204 | } |
| 1205 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1206 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1207 | break; |
| 1208 | |
| 1209 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1210 | request = (MainThreadRequest) msg.obj; |
| 1211 | uiccCard = getUiccCardFromRequest(request); |
| 1212 | if (uiccCard == null) { |
| 1213 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1214 | request.result = new IllegalArgumentException( |
| 1215 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1216 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1217 | break; |
| 1218 | } |
| 1219 | Integer appType = (Integer) request.argument; |
| 1220 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1221 | if (uiccApp == null) { |
| 1222 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1223 | + appType); |
| 1224 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1225 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1226 | break; |
| 1227 | } else { |
| 1228 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1229 | + " specified type -- " + appType); |
| 1230 | } |
| 1231 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1232 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1233 | onCompleted); |
| 1234 | break; |
| 1235 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1236 | case CMD_SWITCH_SLOTS: |
| 1237 | request = (MainThreadRequest) msg.obj; |
| 1238 | int[] physicalSlots = (int[]) request.argument; |
| 1239 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1240 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1241 | break; |
| 1242 | |
| 1243 | case EVENT_SWITCH_SLOTS_DONE: |
| 1244 | ar = (AsyncResult) msg.obj; |
| 1245 | request = (MainThreadRequest) ar.userObj; |
| 1246 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1247 | notifyRequester(request); |
| 1248 | break; |
| 1249 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1250 | request = (MainThreadRequest) msg.obj; |
| 1251 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1252 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1253 | break; |
| 1254 | |
| 1255 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1256 | ar = (AsyncResult) msg.obj; |
| 1257 | request = (MainThreadRequest) ar.userObj; |
| 1258 | if (ar.exception != null) { |
| 1259 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1260 | } else { |
| 1261 | int mode = ((int[]) ar.result)[0]; |
| 1262 | if (mode == 0) { |
| 1263 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1264 | } else { |
| 1265 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1266 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1267 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1268 | notifyRequester(request); |
| 1269 | break; |
| 1270 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1271 | request = (MainThreadRequest) msg.obj; |
| 1272 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1273 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1274 | break; |
| 1275 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1276 | ar = (AsyncResult) msg.obj; |
| 1277 | request = (MainThreadRequest) ar.userObj; |
| 1278 | if (ar.exception != null) { |
| 1279 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1280 | } else { |
| 1281 | request.result = ((int[]) ar.result)[0]; |
| 1282 | } |
| 1283 | notifyRequester(request); |
| 1284 | break; |
| 1285 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1286 | request = (MainThreadRequest) msg.obj; |
| 1287 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1288 | int mode = (int) request.argument; |
| 1289 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1290 | break; |
| 1291 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1292 | ar = (AsyncResult) msg.obj; |
| 1293 | request = (MainThreadRequest) ar.userObj; |
| 1294 | request.result = ar.exception == null; |
| 1295 | notifyRequester(request); |
| 1296 | break; |
| 1297 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1298 | request = (MainThreadRequest) msg.obj; |
| 1299 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1300 | int subscriptionMode = (int) request.argument; |
| 1301 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1302 | break; |
| 1303 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1304 | ar = (AsyncResult) msg.obj; |
| 1305 | request = (MainThreadRequest) ar.userObj; |
| 1306 | request.result = ar.exception == null; |
| 1307 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1308 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1309 | case CMD_GET_ALL_CELL_INFO: |
| 1310 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1311 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1312 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1313 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1314 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1315 | ar = (AsyncResult) msg.obj; |
| 1316 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1317 | // If a timeout occurs, the response will be null |
| 1318 | request.result = (ar.exception == null && ar.result != null) |
| 1319 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1320 | synchronized (request) { |
| 1321 | request.notifyAll(); |
| 1322 | } |
| 1323 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1324 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1325 | request = (MainThreadRequest) msg.obj; |
| 1326 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1327 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1328 | break; |
| 1329 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1330 | ar = (AsyncResult) msg.obj; |
| 1331 | request = (MainThreadRequest) ar.userObj; |
| 1332 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1333 | try { |
| 1334 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1335 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1336 | cb.onError( |
| 1337 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1338 | ar.exception.getClass().getName(), |
| 1339 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1340 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1341 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1342 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1343 | } else { |
| 1344 | // use the result as returned |
| 1345 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1346 | } |
| 1347 | } catch (RemoteException re) { |
| 1348 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1349 | } |
| 1350 | break; |
| 1351 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1352 | request = (MainThreadRequest) msg.obj; |
| 1353 | WorkSource ws = (WorkSource) request.argument; |
| 1354 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1355 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1356 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1357 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1358 | ar = (AsyncResult) msg.obj; |
| 1359 | request = (MainThreadRequest) ar.userObj; |
| 1360 | if (ar.exception == null) { |
| 1361 | request.result = ar.result; |
| 1362 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1363 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1364 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1365 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1366 | } |
| 1367 | |
| 1368 | synchronized (request) { |
| 1369 | request.notifyAll(); |
| 1370 | } |
| 1371 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1372 | case CMD_MODEM_REBOOT: |
| 1373 | request = (MainThreadRequest) msg.obj; |
| 1374 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1375 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1376 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1377 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1378 | handleNullReturnEvent(msg, "rebootModem"); |
| 1379 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1380 | case CMD_REQUEST_ENABLE_MODEM: |
| 1381 | request = (MainThreadRequest) msg.obj; |
| 1382 | boolean enable = (boolean) request.argument; |
| 1383 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1384 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1385 | PhoneConfigurationManager.getInstance() |
| 1386 | .enablePhone(request.phone, enable, onCompleted); |
| 1387 | break; |
| 1388 | case EVENT_ENABLE_MODEM_DONE: |
| 1389 | ar = (AsyncResult) msg.obj; |
| 1390 | request = (MainThreadRequest) ar.userObj; |
| 1391 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1392 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1393 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1394 | if ((boolean) request.result) { |
| 1395 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1396 | updateModemStateMetrics(); |
| 1397 | } else { |
| 1398 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1399 | + ar.exception); |
| 1400 | } |
| 1401 | notifyRequester(request); |
| 1402 | break; |
| 1403 | case CMD_GET_MODEM_STATUS: |
| 1404 | request = (MainThreadRequest) msg.obj; |
| 1405 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1406 | PhoneConfigurationManager.getInstance() |
| 1407 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1408 | break; |
| 1409 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1410 | ar = (AsyncResult) msg.obj; |
| 1411 | request = (MainThreadRequest) ar.userObj; |
| 1412 | int id = request.phone.getPhoneId(); |
| 1413 | if (ar.exception == null && ar.result != null) { |
| 1414 | request.result = ar.result; |
| 1415 | //update the cache as modem status has changed |
| 1416 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1417 | (boolean) request.result); |
| 1418 | } else { |
| 1419 | // Return true if modem status cannot be retrieved. For most cases, |
| 1420 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1421 | // and disable modem are not supported. Modem is always on. |
| 1422 | // TODO: this should be fixed in R to support a third |
| 1423 | // status UNKNOWN b/131631629 |
| 1424 | request.result = true; |
| 1425 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1426 | + ar.exception); |
| 1427 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1428 | notifyRequester(request); |
| 1429 | break; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1430 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1431 | request = (MainThreadRequest) msg.obj; |
| 1432 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1433 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1434 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1435 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1436 | break; |
| 1437 | } |
| 1438 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1439 | ar = (AsyncResult) msg.obj; |
| 1440 | request = (MainThreadRequest) ar.userObj; |
| 1441 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1442 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1443 | args.second.accept(ar.exception == null); |
| 1444 | notifyRequester(request); |
| 1445 | break; |
| 1446 | } |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1447 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1448 | ar = (AsyncResult) msg.obj; |
| 1449 | request = (MainThreadRequest) ar.userObj; |
| 1450 | if (ar.exception == null && ar.result != null) { |
| 1451 | request.result = ar.result; |
| 1452 | } else { |
| 1453 | request.result = -1; |
| 1454 | loge("Failed to set Forbidden Plmns"); |
| 1455 | if (ar.result == null) { |
| 1456 | loge("setForbidenPlmns: Empty response"); |
| 1457 | } else if (ar.exception != null) { |
| 1458 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1459 | request.result = -1; |
| 1460 | } else { |
| 1461 | loge("setForbiddenPlmns: Unknown exception"); |
| 1462 | } |
| 1463 | } |
| 1464 | notifyRequester(request); |
| 1465 | break; |
| 1466 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1467 | request = (MainThreadRequest) msg.obj; |
| 1468 | uiccCard = getUiccCardFromRequest(request); |
| 1469 | if (uiccCard == null) { |
| 1470 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1471 | request.result = -1; |
| 1472 | notifyRequester(request); |
| 1473 | break; |
| 1474 | } |
| 1475 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1476 | (Pair<Integer, List<String>>) request.argument; |
| 1477 | appType = setFplmnsArgs.first; |
| 1478 | List<String> fplmns = setFplmnsArgs.second; |
| 1479 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1480 | if (uiccApp == null) { |
| 1481 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1482 | request.result = -1; |
| 1483 | loge("Failed to get UICC App"); |
| 1484 | notifyRequester(request); |
| 1485 | } else { |
| 1486 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1487 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1488 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1489 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1490 | break; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1491 | case CMD_ERASE_MODEM_CONFIG: |
| 1492 | request = (MainThreadRequest) msg.obj; |
| 1493 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1494 | defaultPhone.eraseModemConfig(onCompleted); |
| 1495 | break; |
| 1496 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1497 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1498 | break; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1499 | |
| 1500 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1501 | request = (MainThreadRequest) msg.obj; |
| 1502 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1503 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1504 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1505 | changed.first, changed.second, onCompleted); |
| 1506 | break; |
| 1507 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1508 | ar = (AsyncResult) msg.obj; |
| 1509 | request = (MainThreadRequest) ar.userObj; |
| 1510 | if (ar.exception == null) { |
| 1511 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1512 | } else { |
| 1513 | request.result = msg.arg1; |
| 1514 | } |
| 1515 | notifyRequester(request); |
| 1516 | break; |
| 1517 | |
| 1518 | case CMD_SET_ICC_LOCK_ENABLED: |
| 1519 | request = (MainThreadRequest) msg.obj; |
| 1520 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1521 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1522 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1523 | enabled.first, enabled.second, onCompleted); |
| 1524 | break; |
| 1525 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1526 | ar = (AsyncResult) msg.obj; |
| 1527 | request = (MainThreadRequest) ar.userObj; |
| 1528 | if (ar.exception == null) { |
| 1529 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1530 | } else { |
| 1531 | request.result = msg.arg1; |
| 1532 | } |
| 1533 | notifyRequester(request); |
| 1534 | break; |
| 1535 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1536 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1537 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1538 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1539 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1540 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1541 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1542 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1543 | default: |
| 1544 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1545 | break; |
| 1546 | } |
| 1547 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1548 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1549 | private void notifyRequester(MainThreadRequest request) { |
| 1550 | synchronized (request) { |
| 1551 | request.notifyAll(); |
| 1552 | } |
| 1553 | } |
| 1554 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1555 | private void handleNullReturnEvent(Message msg, String command) { |
| 1556 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1557 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1558 | if (ar.exception == null) { |
| 1559 | request.result = true; |
| 1560 | } else { |
| 1561 | request.result = false; |
| 1562 | if (ar.exception instanceof CommandException) { |
| 1563 | loge(command + ": CommandException: " + ar.exception); |
| 1564 | } else { |
| 1565 | loge(command + ": Unknown exception"); |
| 1566 | } |
| 1567 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1568 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1569 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1570 | } |
| 1571 | |
| 1572 | /** |
| 1573 | * Posts the specified command to be executed on the main thread, |
| 1574 | * waits for the request to complete, and returns the result. |
| 1575 | * @see #sendRequestAsync |
| 1576 | */ |
| 1577 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1578 | return sendRequest( |
| 1579 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1580 | } |
| 1581 | |
| 1582 | /** |
| 1583 | * Posts the specified command to be executed on the main thread, |
| 1584 | * waits for the request to complete, and returns the result. |
| 1585 | * @see #sendRequestAsync |
| 1586 | */ |
| 1587 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1588 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1589 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1590 | } |
| 1591 | |
| 1592 | /** |
| 1593 | * Posts the specified command to be executed on the main thread, |
| 1594 | * waits for the request to complete, and returns the result. |
| 1595 | * @see #sendRequestAsync |
| 1596 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1597 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1598 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1599 | } |
| 1600 | |
| 1601 | /** |
| 1602 | * Posts the specified command to be executed on the main thread, |
| 1603 | * waits for the request to complete, and returns the result. |
| 1604 | * @see #sendRequestAsync |
| 1605 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1606 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1607 | return sendRequest(command, argument, subId, null, workSource); |
| 1608 | } |
| 1609 | |
| 1610 | /** |
| 1611 | * Posts the specified command to be executed on the main thread, |
| 1612 | * waits for the request to complete, and returns the result. |
| 1613 | * @see #sendRequestAsync |
| 1614 | */ |
| 1615 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1616 | return sendRequest( |
| 1617 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1618 | } |
| 1619 | |
| 1620 | /** |
| 1621 | * Posts the specified command to be executed on the main thread, |
| 1622 | * waits for the request to complete, and returns the result. |
| 1623 | * @see #sendRequestAsync |
| 1624 | */ |
| 1625 | private Object sendRequest( |
| 1626 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1627 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1628 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1629 | } |
| 1630 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1631 | MainThreadRequest request = null; |
| 1632 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1633 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1634 | } else if (phone != null) { |
| 1635 | request = new MainThreadRequest(argument, phone, workSource); |
| 1636 | } else { |
| 1637 | request = new MainThreadRequest(argument, subId, workSource); |
| 1638 | } |
| 1639 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1640 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1641 | msg.sendToTarget(); |
| 1642 | |
| 1643 | // Wait for the request to complete |
| 1644 | synchronized (request) { |
| 1645 | while (request.result == null) { |
| 1646 | try { |
| 1647 | request.wait(); |
| 1648 | } catch (InterruptedException e) { |
| 1649 | // Do nothing, go back and wait until the request is complete |
| 1650 | } |
| 1651 | } |
| 1652 | } |
| 1653 | return request.result; |
| 1654 | } |
| 1655 | |
| 1656 | /** |
| 1657 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1658 | * Posts the specified command to be executed on the main thread, and |
| 1659 | * returns immediately. |
| 1660 | * @see #sendRequest |
| 1661 | */ |
| 1662 | private void sendRequestAsync(int command) { |
| 1663 | mMainThreadHandler.sendEmptyMessage(command); |
| 1664 | } |
| 1665 | |
| 1666 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1667 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1668 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1669 | */ |
| 1670 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1671 | sendRequestAsync(command, argument, null, null); |
| 1672 | } |
| 1673 | |
| 1674 | /** |
| 1675 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1676 | * @see {@link #sendRequest(int,Object)} |
| 1677 | */ |
| 1678 | private void sendRequestAsync( |
| 1679 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1680 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1681 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1682 | msg.sendToTarget(); |
| 1683 | } |
| 1684 | |
| 1685 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1686 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1687 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1688 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1689 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1690 | synchronized (PhoneInterfaceManager.class) { |
| 1691 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1692 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1693 | } else { |
| 1694 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1695 | } |
| 1696 | return sInstance; |
| 1697 | } |
| 1698 | } |
| 1699 | |
| 1700 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 1701 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1702 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1703 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1704 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1705 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1706 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1707 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1708 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1709 | mTelephonySharedPreferences = |
| 1710 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1711 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1712 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 1713 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1714 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1715 | publish(); |
| 1716 | } |
| 1717 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1718 | private Phone getDefaultPhone() { |
| 1719 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1720 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1721 | } |
| 1722 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1723 | private void publish() { |
| 1724 | if (DBG) log("publish: " + this); |
| 1725 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 1726 | TelephonyFrameworkInitializer |
| 1727 | .getTelephonyServiceManager() |
| 1728 | .getTelephonyServiceRegisterer() |
| 1729 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1730 | } |
| 1731 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1732 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1733 | if (request.phone != null) { |
| 1734 | return request.phone; |
| 1735 | } else { |
| 1736 | return getPhoneFromSubId(request.subId); |
| 1737 | } |
| 1738 | } |
| 1739 | |
| 1740 | private Phone getPhoneFromSubId(int subId) { |
| 1741 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1742 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1743 | } |
| 1744 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1745 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1746 | Phone phone = getPhoneFromRequest(request); |
| 1747 | return phone == null ? null : |
| 1748 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1749 | } |
| 1750 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1751 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1752 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1753 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1754 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1755 | |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1756 | private void sendEraseModemConfig(Phone phone) { |
| 1757 | if (phone != null) { |
| 1758 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 1759 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 1760 | final long identity = Binder.clearCallingIdentity(); |
| 1761 | try { |
| 1762 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 1763 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 1764 | } finally { |
| 1765 | Binder.restoreCallingIdentity(identity); |
| 1766 | } |
| 1767 | } |
| 1768 | } |
| 1769 | |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 1770 | private boolean isImsAvailableOnDevice() { |
| 1771 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 1772 | if (pm == null) { |
| 1773 | // For some reason package manger is not available.. This will fail internally anyway, |
| 1774 | // so do not throw error and allow. |
| 1775 | return true; |
| 1776 | } |
| 1777 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 1778 | } |
| 1779 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1780 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1781 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1782 | } |
| 1783 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1784 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1785 | if (DBG) log("dial: " + number); |
| 1786 | // No permission check needed here: This is just a wrapper around the |
| 1787 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1788 | // the UI before it does anything. |
| 1789 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1790 | final long identity = Binder.clearCallingIdentity(); |
| 1791 | try { |
| 1792 | String url = createTelUrl(number); |
| 1793 | if (url == null) { |
| 1794 | return; |
| 1795 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1796 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1797 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1798 | PhoneConstants.State state = mCM.getState(subId); |
| 1799 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1800 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1801 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1802 | mApp.startActivity(intent); |
| 1803 | } |
| 1804 | } finally { |
| 1805 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1806 | } |
| 1807 | } |
| 1808 | |
| 1809 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1810 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1811 | } |
| 1812 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1813 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1814 | if (DBG) log("call: " + number); |
| 1815 | |
| 1816 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1817 | // need to do a permission check since we're calling startActivity() |
| 1818 | // from the context of the phone app. |
| 1819 | enforceCallPermission(); |
| 1820 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 1821 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1822 | != AppOpsManager.MODE_ALLOWED) { |
| 1823 | return; |
| 1824 | } |
| 1825 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1826 | final long identity = Binder.clearCallingIdentity(); |
| 1827 | try { |
| 1828 | String url = createTelUrl(number); |
| 1829 | if (url == null) { |
| 1830 | return; |
| 1831 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1832 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1833 | boolean isValid = false; |
| 1834 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1835 | if (slist != null) { |
| 1836 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1837 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1838 | isValid = true; |
| 1839 | break; |
| 1840 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1841 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1842 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1843 | if (!isValid) { |
| 1844 | return; |
| 1845 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1846 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1847 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1848 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1849 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1850 | mApp.startActivity(intent); |
| 1851 | } finally { |
| 1852 | Binder.restoreCallingIdentity(identity); |
| 1853 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1854 | } |
| 1855 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1856 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1857 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1858 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1859 | } |
| 1860 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1861 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1862 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1863 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1864 | } |
| 1865 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1866 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1867 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1868 | |
| 1869 | final long identity = Binder.clearCallingIdentity(); |
| 1870 | try { |
| 1871 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1872 | checkSimPin.start(); |
| 1873 | return checkSimPin.unlockSim(null, pin); |
| 1874 | } finally { |
| 1875 | Binder.restoreCallingIdentity(identity); |
| 1876 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1877 | } |
| 1878 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1879 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1880 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1881 | |
| 1882 | final long identity = Binder.clearCallingIdentity(); |
| 1883 | try { |
| 1884 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1885 | checkSimPuk.start(); |
| 1886 | return checkSimPuk.unlockSim(puk, pin); |
| 1887 | } finally { |
| 1888 | Binder.restoreCallingIdentity(identity); |
| 1889 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1890 | } |
| 1891 | |
| 1892 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1893 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1894 | * a synchronous one. |
| 1895 | */ |
| 1896 | private static class UnlockSim extends Thread { |
| 1897 | |
| 1898 | private final IccCard mSimCard; |
| 1899 | |
| 1900 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1901 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1902 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1903 | |
| 1904 | // For replies from SimCard interface |
| 1905 | private Handler mHandler; |
| 1906 | |
| 1907 | // For async handler to identify request type |
| 1908 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1909 | |
| 1910 | public UnlockSim(IccCard simCard) { |
| 1911 | mSimCard = simCard; |
| 1912 | } |
| 1913 | |
| 1914 | @Override |
| 1915 | public void run() { |
| 1916 | Looper.prepare(); |
| 1917 | synchronized (UnlockSim.this) { |
| 1918 | mHandler = new Handler() { |
| 1919 | @Override |
| 1920 | public void handleMessage(Message msg) { |
| 1921 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1922 | switch (msg.what) { |
| 1923 | case SUPPLY_PIN_COMPLETE: |
| 1924 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1925 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1926 | mRetryCount = msg.arg1; |
| 1927 | if (ar.exception != null) { |
| 1928 | if (ar.exception instanceof CommandException && |
| 1929 | ((CommandException)(ar.exception)).getCommandError() |
| 1930 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1931 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 1932 | } //When UiccCardApp dispose,handle message and return exception |
| 1933 | else if (ar.exception instanceof CommandException && |
| 1934 | ((CommandException) (ar.exception)).getCommandError() |
| 1935 | == CommandException.Error.ABORTED) { |
| 1936 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1937 | } else { |
| 1938 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1939 | } |
| 1940 | } else { |
| 1941 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1942 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1943 | mDone = true; |
| 1944 | UnlockSim.this.notifyAll(); |
| 1945 | } |
| 1946 | break; |
| 1947 | } |
| 1948 | } |
| 1949 | }; |
| 1950 | UnlockSim.this.notifyAll(); |
| 1951 | } |
| 1952 | Looper.loop(); |
| 1953 | } |
| 1954 | |
| 1955 | /* |
| 1956 | * Use PIN or PUK to unlock SIM card |
| 1957 | * |
| 1958 | * If PUK is null, unlock SIM card with PIN |
| 1959 | * |
| 1960 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1961 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1962 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1963 | |
| 1964 | while (mHandler == null) { |
| 1965 | try { |
| 1966 | wait(); |
| 1967 | } catch (InterruptedException e) { |
| 1968 | Thread.currentThread().interrupt(); |
| 1969 | } |
| 1970 | } |
| 1971 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1972 | |
| 1973 | if (puk == null) { |
| 1974 | mSimCard.supplyPin(pin, callback); |
| 1975 | } else { |
| 1976 | mSimCard.supplyPuk(puk, pin, callback); |
| 1977 | } |
| 1978 | |
| 1979 | while (!mDone) { |
| 1980 | try { |
| 1981 | Log.d(LOG_TAG, "wait for done"); |
| 1982 | wait(); |
| 1983 | } catch (InterruptedException e) { |
| 1984 | // Restore the interrupted status |
| 1985 | Thread.currentThread().interrupt(); |
| 1986 | } |
| 1987 | } |
| 1988 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1989 | int[] resultArray = new int[2]; |
| 1990 | resultArray[0] = mResult; |
| 1991 | resultArray[1] = mRetryCount; |
| 1992 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1993 | } |
| 1994 | } |
| 1995 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 1996 | /** |
| 1997 | * This method has been removed due to privacy and stability concerns. |
| 1998 | */ |
| 1999 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2000 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2001 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2002 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2003 | } |
| 2004 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2005 | @Override |
| 2006 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2007 | mApp.getSystemService(AppOpsManager.class) |
| 2008 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2009 | |
| 2010 | final int targetSdk = getTargetSdk(callingPackage); |
| 2011 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2012 | // Callers targeting S have no business invoking this method. |
| 2013 | return; |
| 2014 | } |
| 2015 | |
| 2016 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2017 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2018 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2019 | .setCallingPackage(callingPackage) |
| 2020 | .setCallingFeatureId(null) |
| 2021 | .setCallingPid(Binder.getCallingPid()) |
| 2022 | .setCallingUid(Binder.getCallingUid()) |
| 2023 | .setMethod("updateServiceLocation") |
| 2024 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2025 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2026 | .build()); |
| 2027 | // Apps that lack location permission have no business calling this method; |
| 2028 | // however, because no permission was declared in the public API, denials must |
| 2029 | // all be "soft". |
| 2030 | switch (locationResult) { |
| 2031 | case DENIED_HARD: /* fall through */ |
| 2032 | case DENIED_SOFT: |
| 2033 | return; |
| 2034 | } |
| 2035 | |
| 2036 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2037 | final long identity = Binder.clearCallingIdentity(); |
| 2038 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2039 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2040 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2041 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2042 | } |
| 2043 | } finally { |
| 2044 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2045 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2046 | } |
| 2047 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2048 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2049 | @Override |
| 2050 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2051 | return isRadioOnWithFeature(callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2052 | } |
| 2053 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2054 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2055 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2056 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2057 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2058 | callingFeatureId); |
| 2059 | } |
| 2060 | |
| 2061 | @Deprecated |
| 2062 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2063 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2064 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
| 2065 | } |
| 2066 | |
| 2067 | @Override |
| 2068 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2069 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2070 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2071 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2072 | return false; |
| 2073 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2074 | |
| 2075 | final long identity = Binder.clearCallingIdentity(); |
| 2076 | try { |
| 2077 | return isRadioOnForSubscriber(subId); |
| 2078 | } finally { |
| 2079 | Binder.restoreCallingIdentity(identity); |
| 2080 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2081 | } |
| 2082 | |
| 2083 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2084 | final long identity = Binder.clearCallingIdentity(); |
| 2085 | try { |
| 2086 | final Phone phone = getPhone(subId); |
| 2087 | if (phone != null) { |
| 2088 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2089 | } else { |
| 2090 | return false; |
| 2091 | } |
| 2092 | } finally { |
| 2093 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2094 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2095 | } |
| 2096 | |
| 2097 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2098 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2099 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2100 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2101 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2102 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2103 | |
| 2104 | final long identity = Binder.clearCallingIdentity(); |
| 2105 | try { |
| 2106 | final Phone phone = getPhone(subId); |
| 2107 | if (phone != null) { |
| 2108 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2109 | } |
| 2110 | } finally { |
| 2111 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2112 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2113 | } |
| 2114 | |
| 2115 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2116 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2117 | } |
| 2118 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2119 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2120 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2121 | |
| 2122 | final long identity = Binder.clearCallingIdentity(); |
| 2123 | try { |
| 2124 | final Phone phone = getPhone(subId); |
| 2125 | if (phone == null) { |
| 2126 | return false; |
| 2127 | } |
| 2128 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2129 | toggleRadioOnOffForSubscriber(subId); |
| 2130 | } |
| 2131 | return true; |
| 2132 | } finally { |
| 2133 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2134 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2135 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2136 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2137 | public boolean needMobileRadioShutdown() { |
Shuo Qian | afeaf7d | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2138 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2139 | /* |
| 2140 | * If any of the Radios are available, it will need to be |
| 2141 | * shutdown. So return true if any Radio is available. |
| 2142 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2143 | final long identity = Binder.clearCallingIdentity(); |
| 2144 | try { |
| 2145 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2146 | Phone phone = PhoneFactory.getPhone(i); |
| 2147 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2148 | } |
| 2149 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2150 | return false; |
| 2151 | } finally { |
| 2152 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2153 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2154 | } |
| 2155 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2156 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2157 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2158 | enforceModifyPermission(); |
| 2159 | |
| 2160 | final long identity = Binder.clearCallingIdentity(); |
| 2161 | try { |
| 2162 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2163 | logv("Shutting down Phone " + i); |
| 2164 | shutdownRadioUsingPhoneId(i); |
| 2165 | } |
| 2166 | } finally { |
| 2167 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2168 | } |
| 2169 | } |
| 2170 | |
| 2171 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2172 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2173 | if (phone != null && phone.isRadioAvailable()) { |
| 2174 | phone.shutdownRadio(); |
| 2175 | } |
| 2176 | } |
| 2177 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2178 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2179 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2180 | |
| 2181 | final long identity = Binder.clearCallingIdentity(); |
| 2182 | try { |
| 2183 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2184 | if (defaultPhone != null) { |
| 2185 | defaultPhone.setRadioPower(turnOn); |
| 2186 | return true; |
| 2187 | } else { |
| 2188 | loge("There's no default phone."); |
| 2189 | return false; |
| 2190 | } |
| 2191 | } finally { |
| 2192 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2193 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2194 | } |
| 2195 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2196 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2197 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2198 | |
| 2199 | final long identity = Binder.clearCallingIdentity(); |
| 2200 | try { |
| 2201 | final Phone phone = getPhone(subId); |
| 2202 | if (phone != null) { |
| 2203 | phone.setRadioPower(turnOn); |
| 2204 | return true; |
| 2205 | } else { |
| 2206 | return false; |
| 2207 | } |
| 2208 | } finally { |
| 2209 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2210 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2211 | } |
| 2212 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2213 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2214 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2215 | public boolean enableDataConnectivity() { |
| 2216 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2217 | |
| 2218 | final long identity = Binder.clearCallingIdentity(); |
| 2219 | try { |
| 2220 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2221 | final Phone phone = getPhone(subId); |
| 2222 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 2223 | phone.getDataEnabledSettings().setDataEnabled( |
| 2224 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2225 | return true; |
| 2226 | } else { |
| 2227 | return false; |
| 2228 | } |
| 2229 | } finally { |
| 2230 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2231 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2232 | } |
| 2233 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2234 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2235 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2236 | public boolean disableDataConnectivity() { |
| 2237 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2238 | |
| 2239 | final long identity = Binder.clearCallingIdentity(); |
| 2240 | try { |
| 2241 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2242 | final Phone phone = getPhone(subId); |
| 2243 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 2244 | phone.getDataEnabledSettings().setDataEnabled( |
| 2245 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2246 | return true; |
| 2247 | } else { |
| 2248 | return false; |
| 2249 | } |
| 2250 | } finally { |
| 2251 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2252 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2253 | } |
| 2254 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2255 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2256 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2257 | final long identity = Binder.clearCallingIdentity(); |
| 2258 | try { |
| 2259 | final Phone phone = getPhone(subId); |
| 2260 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2261 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2262 | } else { |
| 2263 | return false; |
| 2264 | } |
| 2265 | } finally { |
| 2266 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2267 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2268 | } |
| 2269 | |
| 2270 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2271 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2272 | } |
| 2273 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2274 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2275 | enforceCallPermission(); |
| 2276 | |
| 2277 | final long identity = Binder.clearCallingIdentity(); |
| 2278 | try { |
| 2279 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2280 | return; |
| 2281 | } |
| 2282 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2283 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2284 | } finally { |
| 2285 | Binder.restoreCallingIdentity(identity); |
| 2286 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2287 | }; |
| 2288 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2289 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2290 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2291 | |
| 2292 | final long identity = Binder.clearCallingIdentity(); |
| 2293 | try { |
| 2294 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2295 | return false; |
| 2296 | } |
| 2297 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2298 | } finally { |
| 2299 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2300 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2301 | } |
| 2302 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2303 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2304 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2305 | } |
| 2306 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2307 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2308 | final long identity = Binder.clearCallingIdentity(); |
| 2309 | try { |
| 2310 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2311 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2312 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2313 | } finally { |
| 2314 | Binder.restoreCallingIdentity(identity); |
| 2315 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2316 | } |
| 2317 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2318 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2319 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2320 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2321 | } |
| 2322 | |
| 2323 | @Override |
| 2324 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2325 | final long identity = Binder.clearCallingIdentity(); |
| 2326 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2327 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2328 | if (phone != null) { |
| 2329 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2330 | } else { |
| 2331 | return PhoneConstantConversions.convertDataState( |
| 2332 | PhoneConstants.DataState.DISCONNECTED); |
| 2333 | } |
| 2334 | } finally { |
| 2335 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2336 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2337 | } |
| 2338 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2339 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2340 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2341 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2342 | } |
| 2343 | |
| 2344 | @Override |
| 2345 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2346 | final long identity = Binder.clearCallingIdentity(); |
| 2347 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2348 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2349 | if (phone != null) { |
| 2350 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2351 | } else { |
| 2352 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2353 | } |
| 2354 | } finally { |
| 2355 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2356 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2357 | } |
| 2358 | |
| 2359 | @Override |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2360 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2361 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2362 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2363 | |
| 2364 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2365 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2366 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2367 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2368 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2369 | .setCallingPid(Binder.getCallingPid()) |
| 2370 | .setCallingUid(Binder.getCallingUid()) |
| 2371 | .setMethod("getCellLocation") |
Hall Liu | c3f8eb6 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2372 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2373 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2374 | .build()); |
| 2375 | switch (locationResult) { |
| 2376 | case DENIED_HARD: |
| 2377 | throw new SecurityException("Not allowed to access cell location"); |
| 2378 | case DENIED_SOFT: |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2379 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2380 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2381 | } |
| 2382 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2383 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2384 | final long identity = Binder.clearCallingIdentity(); |
| 2385 | try { |
| 2386 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2387 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2388 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2389 | } finally { |
| 2390 | Binder.restoreCallingIdentity(identity); |
| 2391 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2392 | } |
| 2393 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2394 | @Override |
Jack Yu | 0142503 | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2395 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2396 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2397 | // registered cell info, so return a NULL country instead. |
| 2398 | final long identity = Binder.clearCallingIdentity(); |
| 2399 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2400 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2401 | // Get default phone in this case. |
| 2402 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2403 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2404 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2405 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | cf38ed9 | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2406 | if (phone == null) return ""; |
| 2407 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2408 | if (sst == null) return ""; |
| 2409 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2410 | if (lt == null) return ""; |
| 2411 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry(); |
| 2412 | EmergencyNumberTracker ent = phone.getEmergencyNumberTracker(); |
| 2413 | return (ent == null) ? "" : ent.getEmergencyCountryIso(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2414 | } finally { |
| 2415 | Binder.restoreCallingIdentity(identity); |
| 2416 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2417 | } |
| 2418 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2419 | /** |
| 2420 | * This method was removed due to potential issues caused by performing partial |
| 2421 | * updates of service state, and lack of a credible use case. |
| 2422 | * |
| 2423 | * This has the ability to break the telephony implementation by disabling notification of |
| 2424 | * changes in device connectivity. DO NOT USE THIS! |
| 2425 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2426 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2427 | public void enableLocationUpdates() { |
| 2428 | mApp.enforceCallingOrSelfPermission( |
| 2429 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2430 | } |
| 2431 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2432 | /** |
| 2433 | * This method was removed due to potential issues caused by performing partial |
| 2434 | * updates of service state, and lack of a credible use case. |
| 2435 | * |
| 2436 | * This has the ability to break the telephony implementation by disabling notification of |
| 2437 | * changes in device connectivity. DO NOT USE THIS! |
| 2438 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2439 | @Override |
| 2440 | public void disableLocationUpdates() { |
| 2441 | mApp.enforceCallingOrSelfPermission( |
| 2442 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2443 | } |
| 2444 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2445 | /** |
| 2446 | * Returns the target SDK version number for a given package name. |
| 2447 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2448 | * This call MUST be invoked before clearing the calling UID. |
| 2449 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2450 | * @return target SDK if the package is found or INT_MAX. |
| 2451 | */ |
| 2452 | private int getTargetSdk(String packageName) { |
| 2453 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2454 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 54d2030 | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2455 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2456 | if (ai != null) return ai.targetSdkVersion; |
| 2457 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2458 | loge("Failed to get package info for pkg=" |
| 2459 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2460 | } |
| 2461 | return Integer.MAX_VALUE; |
| 2462 | } |
| 2463 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2464 | @Override |
| 2465 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2466 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2467 | String callingFeatureId) { |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2468 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2469 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2470 | throw new SecurityException( |
| 2471 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2472 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2473 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2474 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2475 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2476 | return null; |
| 2477 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2478 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2479 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2480 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2481 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2482 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2483 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2484 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2485 | for (CellInfo ci : info) { |
| 2486 | if (ci instanceof CellInfoGsm) { |
| 2487 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2488 | } else if (ci instanceof CellInfoWcdma) { |
| 2489 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2490 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2491 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2492 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2493 | } |
| 2494 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2495 | private List<CellInfo> getCachedCellInfo() { |
| 2496 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2497 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2498 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2499 | if (info != null) cellInfos.addAll(info); |
| 2500 | } |
| 2501 | return cellInfos; |
| 2502 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2503 | |
| 2504 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2505 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2506 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2507 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2508 | |
| 2509 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2510 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2511 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2512 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2513 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2514 | .setCallingPid(Binder.getCallingPid()) |
| 2515 | .setCallingUid(Binder.getCallingUid()) |
| 2516 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2517 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2518 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2519 | .build()); |
| 2520 | switch (locationResult) { |
| 2521 | case DENIED_HARD: |
| 2522 | throw new SecurityException("Not allowed to access cell info"); |
| 2523 | case DENIED_SOFT: |
| 2524 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2525 | } |
| 2526 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2527 | final int targetSdk = getTargetSdk(callingPackage); |
| 2528 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2529 | return getCachedCellInfo(); |
| 2530 | } |
| 2531 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2532 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2533 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2534 | final long identity = Binder.clearCallingIdentity(); |
| 2535 | try { |
| 2536 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2537 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2538 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2539 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2540 | if (info != null) cellInfos.addAll(info); |
| 2541 | } |
| 2542 | return cellInfos; |
| 2543 | } finally { |
| 2544 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2545 | } |
| 2546 | } |
| 2547 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2548 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2549 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2550 | String callingFeatureId) { |
| 2551 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2552 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2553 | } |
| 2554 | |
| 2555 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2556 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2557 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2558 | enforceModifyPermission(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2559 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2560 | } |
| 2561 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2562 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2563 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2564 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2565 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2566 | |
| 2567 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2568 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2569 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2570 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2571 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2572 | .setCallingPid(Binder.getCallingPid()) |
| 2573 | .setCallingUid(Binder.getCallingUid()) |
| 2574 | .setMethod("requestCellInfoUpdate") |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2575 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2576 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2577 | .build()); |
| 2578 | switch (locationResult) { |
| 2579 | case DENIED_HARD: |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2580 | if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) { |
| 2581 | // Safetynet logging for b/154934934 |
| 2582 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2583 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2584 | throw new SecurityException("Not allowed to access cell info"); |
| 2585 | case DENIED_SOFT: |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2586 | if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) { |
| 2587 | // Safetynet logging for b/154934934 |
| 2588 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2589 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2590 | try { |
| 2591 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2592 | } catch (RemoteException re) { |
| 2593 | // Drop without consequences |
| 2594 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2595 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2596 | } |
| 2597 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2598 | |
| 2599 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2600 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2601 | |
| 2602 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2603 | } |
| 2604 | |
| 2605 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2606 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2607 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2608 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2609 | |
| 2610 | final long identity = Binder.clearCallingIdentity(); |
| 2611 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2612 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2613 | } finally { |
| 2614 | Binder.restoreCallingIdentity(identity); |
| 2615 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2616 | } |
| 2617 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2618 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2619 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2620 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2621 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2622 | return null; |
| 2623 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2624 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2625 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2626 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2627 | return null; |
| 2628 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2629 | |
| 2630 | final long identity = Binder.clearCallingIdentity(); |
| 2631 | try { |
| 2632 | return phone.getImei(); |
| 2633 | } finally { |
| 2634 | Binder.restoreCallingIdentity(identity); |
| 2635 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2636 | } |
| 2637 | |
| 2638 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2639 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2640 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2641 | String tac = null; |
| 2642 | if (phone != null) { |
| 2643 | String imei = phone.getImei(); |
| 2644 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2645 | } |
| 2646 | return tac; |
| 2647 | } |
| 2648 | |
| 2649 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2650 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2651 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2652 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2653 | return null; |
| 2654 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2655 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2656 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2657 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2658 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2659 | return null; |
| 2660 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2661 | |
| 2662 | final long identity = Binder.clearCallingIdentity(); |
| 2663 | try { |
| 2664 | return phone.getMeid(); |
| 2665 | } finally { |
| 2666 | Binder.restoreCallingIdentity(identity); |
| 2667 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2668 | } |
| 2669 | |
| 2670 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2671 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2672 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2673 | String manufacturerCode = null; |
| 2674 | if (phone != null) { |
| 2675 | String meid = phone.getMeid(); |
| 2676 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2677 | } |
| 2678 | return manufacturerCode; |
| 2679 | } |
| 2680 | |
| 2681 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2682 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2683 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2684 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2685 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2686 | return null; |
| 2687 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2688 | int subId = phone.getSubId(); |
| 2689 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2690 | mApp, subId, callingPackage, callingFeatureId, |
| 2691 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2692 | return null; |
| 2693 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2694 | |
| 2695 | final long identity = Binder.clearCallingIdentity(); |
| 2696 | try { |
| 2697 | return phone.getDeviceSvn(); |
| 2698 | } finally { |
| 2699 | Binder.restoreCallingIdentity(identity); |
| 2700 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2701 | } |
| 2702 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2703 | @Override |
| 2704 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2705 | final long identity = Binder.clearCallingIdentity(); |
| 2706 | try { |
| 2707 | final Phone phone = getPhone(subId); |
| 2708 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2709 | } finally { |
| 2710 | Binder.restoreCallingIdentity(identity); |
| 2711 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2712 | } |
| 2713 | |
| 2714 | @Override |
| 2715 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2716 | final long identity = Binder.clearCallingIdentity(); |
| 2717 | try { |
| 2718 | final Phone phone = getPhone(subId); |
| 2719 | return phone == null ? null : phone.getCarrierName(); |
| 2720 | } finally { |
| 2721 | Binder.restoreCallingIdentity(identity); |
| 2722 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2723 | } |
| 2724 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2725 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2726 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2727 | final long identity = Binder.clearCallingIdentity(); |
| 2728 | try { |
| 2729 | final Phone phone = getPhone(subId); |
| 2730 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2731 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2732 | } finally { |
| 2733 | Binder.restoreCallingIdentity(identity); |
| 2734 | } |
| 2735 | } |
| 2736 | |
| 2737 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2738 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2739 | final long identity = Binder.clearCallingIdentity(); |
| 2740 | try { |
| 2741 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2742 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2743 | } finally { |
| 2744 | Binder.restoreCallingIdentity(identity); |
| 2745 | } |
| 2746 | } |
| 2747 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2748 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2749 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2750 | if (!isSubscriptionMccMnc) { |
| 2751 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2752 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2753 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2754 | if (phone == null) { |
| 2755 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2756 | } |
| 2757 | final long identity = Binder.clearCallingIdentity(); |
| 2758 | try { |
| 2759 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2760 | } finally { |
| 2761 | Binder.restoreCallingIdentity(identity); |
| 2762 | } |
| 2763 | } |
| 2764 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2765 | // |
| 2766 | // Internal helper methods. |
| 2767 | // |
| 2768 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2769 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2770 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2771 | * |
| 2772 | * @throws SecurityException if the caller does not have the required permission |
| 2773 | */ |
| 2774 | private void enforceModifyPermission() { |
| 2775 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2776 | } |
| 2777 | |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 2778 | /** |
| 2779 | * Make sure the caller is system. |
| 2780 | * |
| 2781 | * @throws SecurityException if the caller is not system. |
| 2782 | */ |
| 2783 | private void enforceSystemCaller() { |
| 2784 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 2785 | throw new SecurityException("Caller must be system"); |
| 2786 | } |
| 2787 | } |
| 2788 | |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 2789 | private void enforceActiveEmergencySessionPermission() { |
| 2790 | mApp.enforceCallingOrSelfPermission( |
| 2791 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 2792 | } |
| 2793 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2794 | /** |
| 2795 | * Make sure the caller has the CALL_PHONE permission. |
| 2796 | * |
| 2797 | * @throws SecurityException if the caller does not have the required permission |
| 2798 | */ |
| 2799 | private void enforceCallPermission() { |
| 2800 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2801 | } |
| 2802 | |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 2803 | private void enforceSettingsPermission() { |
| 2804 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2805 | } |
| 2806 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2807 | private String createTelUrl(String number) { |
| 2808 | if (TextUtils.isEmpty(number)) { |
| 2809 | return null; |
| 2810 | } |
| 2811 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2812 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2813 | } |
| 2814 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2815 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2816 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2817 | } |
| 2818 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2819 | private static void logv(String msg) { |
| 2820 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2821 | } |
| 2822 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2823 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2824 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2825 | } |
| 2826 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2827 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2828 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2829 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2830 | } |
| 2831 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2832 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2833 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2834 | final long identity = Binder.clearCallingIdentity(); |
| 2835 | try { |
| 2836 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2837 | if (phone == null) { |
| 2838 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2839 | } else { |
| 2840 | return phone.getPhoneType(); |
| 2841 | } |
| 2842 | } finally { |
| 2843 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2844 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2845 | } |
| 2846 | |
| 2847 | /** |
| 2848 | * Returns the CDMA ERI icon index to display |
| 2849 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2850 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2851 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 2852 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 2853 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2854 | } |
| 2855 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2856 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2857 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 2858 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2859 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2860 | mApp, subId, callingPackage, callingFeatureId, |
| 2861 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2862 | return -1; |
| 2863 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2864 | |
| 2865 | final long identity = Binder.clearCallingIdentity(); |
| 2866 | try { |
| 2867 | final Phone phone = getPhone(subId); |
| 2868 | if (phone != null) { |
| 2869 | return phone.getCdmaEriIconIndex(); |
| 2870 | } else { |
| 2871 | return -1; |
| 2872 | } |
| 2873 | } finally { |
| 2874 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2875 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2876 | } |
| 2877 | |
| 2878 | /** |
| 2879 | * Returns the CDMA ERI icon mode, |
| 2880 | * 0 - ON |
| 2881 | * 1 - FLASHING |
| 2882 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2883 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2884 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 2885 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 2886 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2887 | } |
| 2888 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2889 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2890 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 2891 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2892 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2893 | mApp, subId, callingPackage, callingFeatureId, |
| 2894 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2895 | return -1; |
| 2896 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2897 | |
| 2898 | final long identity = Binder.clearCallingIdentity(); |
| 2899 | try { |
| 2900 | final Phone phone = getPhone(subId); |
| 2901 | if (phone != null) { |
| 2902 | return phone.getCdmaEriIconMode(); |
| 2903 | } else { |
| 2904 | return -1; |
| 2905 | } |
| 2906 | } finally { |
| 2907 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2908 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2909 | } |
| 2910 | |
| 2911 | /** |
| 2912 | * Returns the CDMA ERI text, |
| 2913 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2914 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2915 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 2916 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 2917 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2918 | } |
| 2919 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2920 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2921 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 2922 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2923 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2924 | mApp, subId, callingPackage, callingFeatureId, |
| 2925 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2926 | return null; |
| 2927 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2928 | |
| 2929 | final long identity = Binder.clearCallingIdentity(); |
| 2930 | try { |
| 2931 | final Phone phone = getPhone(subId); |
| 2932 | if (phone != null) { |
| 2933 | return phone.getCdmaEriText(); |
| 2934 | } else { |
| 2935 | return null; |
| 2936 | } |
| 2937 | } finally { |
| 2938 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2939 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2940 | } |
| 2941 | |
| 2942 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2943 | * Returns the CDMA MDN. |
| 2944 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2945 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2946 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2947 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2948 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2949 | |
| 2950 | final long identity = Binder.clearCallingIdentity(); |
| 2951 | try { |
| 2952 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2953 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2954 | return phone.getLine1Number(); |
| 2955 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2956 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2957 | return null; |
| 2958 | } |
| 2959 | } finally { |
| 2960 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2961 | } |
| 2962 | } |
| 2963 | |
| 2964 | /** |
| 2965 | * Returns the CDMA MIN. |
| 2966 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2967 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2968 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2969 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2970 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2971 | |
| 2972 | final long identity = Binder.clearCallingIdentity(); |
| 2973 | try { |
| 2974 | final Phone phone = getPhone(subId); |
| 2975 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2976 | return phone.getCdmaMin(); |
| 2977 | } else { |
| 2978 | return null; |
| 2979 | } |
| 2980 | } finally { |
| 2981 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2982 | } |
| 2983 | } |
| 2984 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2985 | @Override |
| 2986 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2987 | INumberVerificationCallback callback, String callingPackage) { |
| 2988 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2989 | != PERMISSION_GRANTED) { |
| 2990 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2991 | } |
| 2992 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2993 | |
| 2994 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2995 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2996 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2997 | } |
| 2998 | |
| 2999 | if (range == null) { |
| 3000 | throw new NullPointerException("Range must be non-null"); |
| 3001 | } |
| 3002 | |
| 3003 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3004 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3005 | |
| 3006 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3007 | } |
| 3008 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3009 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3010 | * Returns true if CDMA provisioning needs to run. |
| 3011 | */ |
| 3012 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3013 | final long identity = Binder.clearCallingIdentity(); |
| 3014 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3015 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3016 | } finally { |
| 3017 | Binder.restoreCallingIdentity(identity); |
| 3018 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3019 | } |
| 3020 | |
| 3021 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3022 | * Sets the voice mail number of a given subId. |
| 3023 | */ |
| 3024 | @Override |
| 3025 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3026 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3027 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3028 | |
| 3029 | final long identity = Binder.clearCallingIdentity(); |
| 3030 | try { |
| 3031 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3032 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3033 | return success; |
| 3034 | } finally { |
| 3035 | Binder.restoreCallingIdentity(identity); |
| 3036 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3037 | } |
| 3038 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3039 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3040 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3041 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3042 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3043 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3044 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3045 | throw new SecurityException("caller must be system dialer"); |
| 3046 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3047 | |
| 3048 | final long identity = Binder.clearCallingIdentity(); |
| 3049 | try { |
| 3050 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3051 | if (phoneAccountHandle == null) { |
| 3052 | return null; |
| 3053 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3054 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3055 | } finally { |
| 3056 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3057 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3058 | } |
| 3059 | |
| 3060 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3061 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3062 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3063 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3064 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3065 | mApp, subId, callingPackage, callingFeatureId, |
| 3066 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3067 | return null; |
| 3068 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3069 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3070 | final long identity = Binder.clearCallingIdentity(); |
| 3071 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3072 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3073 | } finally { |
| 3074 | Binder.restoreCallingIdentity(identity); |
| 3075 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3076 | } |
| 3077 | |
| 3078 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3079 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3080 | VisualVoicemailSmsFilterSettings settings) { |
| 3081 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3082 | |
| 3083 | final long identity = Binder.clearCallingIdentity(); |
| 3084 | try { |
| 3085 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3086 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3087 | } finally { |
| 3088 | Binder.restoreCallingIdentity(identity); |
| 3089 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3090 | } |
| 3091 | |
| 3092 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3093 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3094 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3095 | |
| 3096 | final long identity = Binder.clearCallingIdentity(); |
| 3097 | try { |
| 3098 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3099 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3100 | } finally { |
| 3101 | Binder.restoreCallingIdentity(identity); |
| 3102 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3103 | } |
| 3104 | |
| 3105 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3106 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3107 | String callingPackage, int subId) { |
| 3108 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3109 | |
| 3110 | final long identity = Binder.clearCallingIdentity(); |
| 3111 | try { |
| 3112 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3113 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3114 | } finally { |
| 3115 | Binder.restoreCallingIdentity(identity); |
| 3116 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3117 | } |
| 3118 | |
| 3119 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3120 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3121 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3122 | |
| 3123 | final long identity = Binder.clearCallingIdentity(); |
| 3124 | try { |
| 3125 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3126 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3127 | } finally { |
| 3128 | Binder.restoreCallingIdentity(identity); |
| 3129 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3130 | } |
| 3131 | |
| 3132 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3133 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3134 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3135 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3136 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3137 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3138 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3139 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3140 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3141 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3142 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3143 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3144 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3145 | * Sets the voice activation state of a given subId. |
| 3146 | */ |
| 3147 | @Override |
| 3148 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3149 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3150 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3151 | |
| 3152 | final long identity = Binder.clearCallingIdentity(); |
| 3153 | try { |
| 3154 | final Phone phone = getPhone(subId); |
| 3155 | if (phone != null) { |
| 3156 | phone.setVoiceActivationState(activationState); |
| 3157 | } else { |
| 3158 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3159 | } |
| 3160 | } finally { |
| 3161 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3162 | } |
| 3163 | } |
| 3164 | |
| 3165 | /** |
| 3166 | * Sets the data activation state of a given subId. |
| 3167 | */ |
| 3168 | @Override |
| 3169 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3170 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3171 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3172 | |
| 3173 | final long identity = Binder.clearCallingIdentity(); |
| 3174 | try { |
| 3175 | final Phone phone = getPhone(subId); |
| 3176 | if (phone != null) { |
| 3177 | phone.setDataActivationState(activationState); |
| 3178 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3179 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3180 | } |
| 3181 | } finally { |
| 3182 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3183 | } |
| 3184 | } |
| 3185 | |
| 3186 | /** |
| 3187 | * Returns the voice activation state of a given subId. |
| 3188 | */ |
| 3189 | @Override |
| 3190 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3191 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3192 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3193 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3194 | final long identity = Binder.clearCallingIdentity(); |
| 3195 | try { |
| 3196 | if (phone != null) { |
| 3197 | return phone.getVoiceActivationState(); |
| 3198 | } else { |
| 3199 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3200 | } |
| 3201 | } finally { |
| 3202 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3203 | } |
| 3204 | } |
| 3205 | |
| 3206 | /** |
| 3207 | * Returns the data activation state of a given subId. |
| 3208 | */ |
| 3209 | @Override |
| 3210 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3211 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3212 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3213 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3214 | final long identity = Binder.clearCallingIdentity(); |
| 3215 | try { |
| 3216 | if (phone != null) { |
| 3217 | return phone.getDataActivationState(); |
| 3218 | } else { |
| 3219 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3220 | } |
| 3221 | } finally { |
| 3222 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3223 | } |
| 3224 | } |
| 3225 | |
| 3226 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3227 | * Returns the unread count of voicemails for a subId |
| 3228 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3229 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3230 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3231 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3232 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3233 | mApp, subId, callingPackage, callingFeatureId, |
| 3234 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3235 | return 0; |
| 3236 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3237 | final long identity = Binder.clearCallingIdentity(); |
| 3238 | try { |
| 3239 | final Phone phone = getPhone(subId); |
| 3240 | if (phone != null) { |
| 3241 | return phone.getVoiceMessageCount(); |
| 3242 | } else { |
| 3243 | return 0; |
| 3244 | } |
| 3245 | } finally { |
| 3246 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3247 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3248 | } |
| 3249 | |
| 3250 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3251 | * returns true, if the device is in a state where both voice and data |
| 3252 | * are supported simultaneously. This can change based on location or network condition. |
| 3253 | */ |
| 3254 | @Override |
| 3255 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3256 | final long identity = Binder.clearCallingIdentity(); |
| 3257 | try { |
| 3258 | final Phone phone = getPhone(subId); |
| 3259 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3260 | } finally { |
| 3261 | Binder.restoreCallingIdentity(identity); |
| 3262 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3263 | } |
| 3264 | |
| 3265 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3266 | * Send the dialer code if called from the current default dialer or the caller has |
| 3267 | * carrier privilege. |
| 3268 | * @param inputCode The dialer code to send |
| 3269 | */ |
| 3270 | @Override |
| 3271 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3272 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3273 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3274 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3275 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3276 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3277 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3278 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3279 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3280 | |
| 3281 | final long identity = Binder.clearCallingIdentity(); |
| 3282 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3283 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3284 | } finally { |
| 3285 | Binder.restoreCallingIdentity(identity); |
| 3286 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3287 | } |
| 3288 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3289 | @Override |
| 3290 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3291 | TelephonyPermissions |
| 3292 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3293 | mApp, subId, "getNetworkSelectionMode"); |
| 3294 | final long identity = Binder.clearCallingIdentity(); |
| 3295 | try { |
| 3296 | if (!isActiveSubscription(subId)) { |
| 3297 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3298 | } |
| 3299 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3300 | } finally { |
| 3301 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3302 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3303 | } |
| 3304 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3305 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3306 | public boolean isInEmergencySmsMode() { |
| 3307 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3308 | final long identity = Binder.clearCallingIdentity(); |
| 3309 | try { |
| 3310 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3311 | if (phone.isInEmergencySmsMode()) { |
| 3312 | return true; |
| 3313 | } |
| 3314 | } |
| 3315 | } finally { |
| 3316 | Binder.restoreCallingIdentity(identity); |
| 3317 | } |
| 3318 | return false; |
| 3319 | } |
| 3320 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3321 | /** |
| 3322 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3323 | * @param subId The subscription to use to check the configuration. |
| 3324 | * @param c The callback that will be used to send the result. |
| 3325 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3326 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3327 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3328 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3329 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3330 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3331 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3332 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3333 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3334 | "IMS not available on device."); |
| 3335 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3336 | final long token = Binder.clearCallingIdentity(); |
| 3337 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3338 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3339 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3340 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3341 | } catch (ImsException e) { |
| 3342 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3343 | } finally { |
| 3344 | Binder.restoreCallingIdentity(token); |
| 3345 | } |
| 3346 | } |
| 3347 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3348 | /** |
| 3349 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3350 | * @param subId The subscription to use to check the configuration. |
| 3351 | * @param c The callback that will be used to send the result. |
| 3352 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3353 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3354 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3355 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3356 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3357 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3358 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3359 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3360 | final long token = Binder.clearCallingIdentity(); |
| 3361 | try { |
| 3362 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3363 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3364 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3365 | } catch (ImsException e) { |
| 3366 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3367 | + "is inactive, ignoring unregister."); |
| 3368 | // If the subscription is no longer active, just return, since the callback |
| 3369 | // will already have been removed internally. |
| 3370 | } finally { |
| 3371 | Binder.restoreCallingIdentity(token); |
| 3372 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3373 | } |
| 3374 | |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3375 | /** |
| 3376 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3377 | */ |
| 3378 | @Override |
| 3379 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3380 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3381 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3382 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3383 | "IMS not available on device."); |
| 3384 | } |
| 3385 | final long token = Binder.clearCallingIdentity(); |
| 3386 | try { |
| 3387 | Phone phone = getPhone(subId); |
| 3388 | if (phone == null) { |
| 3389 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3390 | + subId + "'"); |
| 3391 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3392 | } |
| 3393 | phone.getImsRegistrationState(regState -> { |
| 3394 | try { |
| 3395 | consumer.accept((regState == null) |
| 3396 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3397 | } catch (RemoteException e) { |
| 3398 | // Ignore if the remote process is no longer available to call back. |
| 3399 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3400 | } |
| 3401 | }); |
| 3402 | } finally { |
| 3403 | Binder.restoreCallingIdentity(token); |
| 3404 | } |
| 3405 | } |
| 3406 | |
| 3407 | /** |
| 3408 | * Get the transport type for the IMS service registration state. |
| 3409 | */ |
| 3410 | @Override |
| 3411 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3412 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3413 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3414 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3415 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3416 | "IMS not available on device."); |
| 3417 | } |
| 3418 | final long token = Binder.clearCallingIdentity(); |
| 3419 | try { |
| 3420 | Phone phone = getPhone(subId); |
| 3421 | if (phone == null) { |
| 3422 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3423 | + subId + "'"); |
| 3424 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3425 | } |
| 3426 | phone.getImsRegistrationTech(regTech -> { |
| 3427 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3428 | int regTechConverted = (regTech == null) |
| 3429 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3430 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3431 | regTechConverted); |
| 3432 | try { |
| 3433 | consumer.accept(regTechConverted); |
| 3434 | } catch (RemoteException e) { |
| 3435 | // Ignore if the remote process is no longer available to call back. |
| 3436 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3437 | } |
| 3438 | }); |
| 3439 | } finally { |
| 3440 | Binder.restoreCallingIdentity(token); |
| 3441 | } |
| 3442 | } |
| 3443 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3444 | /** |
| 3445 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3446 | * @param subId The subscription to use to check the configuration. |
| 3447 | * @param c The callback that will be used to send the result. |
| 3448 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3449 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3450 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3451 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3452 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3453 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3454 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3455 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3456 | "IMS not available on device."); |
| 3457 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3458 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3459 | final long token = Binder.clearCallingIdentity(); |
| 3460 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3461 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3462 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3463 | } catch (ImsException e) { |
| 3464 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3465 | } finally { |
| 3466 | Binder.restoreCallingIdentity(token); |
| 3467 | } |
| 3468 | } |
| 3469 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3470 | /** |
| 3471 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3472 | * @param subId The subscription to use to check the configuration. |
| 3473 | * @param c The callback that will be used to send the result. |
| 3474 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3475 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3476 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3477 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3478 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3479 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3480 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3481 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3482 | |
| 3483 | final long token = Binder.clearCallingIdentity(); |
| 3484 | try { |
| 3485 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3486 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3487 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3488 | } catch (ImsException e) { |
| 3489 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3490 | + "is inactive, ignoring unregister."); |
| 3491 | // If the subscription is no longer active, just return, since the callback |
| 3492 | // will already have been removed internally. |
| 3493 | } finally { |
| 3494 | Binder.restoreCallingIdentity(token); |
| 3495 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3496 | } |
| 3497 | |
| 3498 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3499 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3500 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3501 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3502 | final long token = Binder.clearCallingIdentity(); |
| 3503 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3504 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3505 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3506 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3507 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3508 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3509 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3510 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3511 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3512 | } finally { |
| 3513 | Binder.restoreCallingIdentity(token); |
| 3514 | } |
| 3515 | } |
| 3516 | |
| 3517 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3518 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3519 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3520 | final long token = Binder.clearCallingIdentity(); |
| 3521 | try { |
| 3522 | Phone phone = getPhone(subId); |
| 3523 | if (phone == null) return false; |
| 3524 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 32706d9 | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3525 | } catch (com.android.ims.ImsException e) { |
| 3526 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3527 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3528 | } finally { |
| 3529 | Binder.restoreCallingIdentity(token); |
| 3530 | } |
| 3531 | } |
| 3532 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3533 | /** |
| 3534 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3535 | * subscription. |
| 3536 | * @param subId The subscription to use to check the configuration. |
| 3537 | * @param callback The callback that will be used to send the result. |
| 3538 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3539 | * @param transportType The transport type of the MmTelFeature capability. |
| 3540 | */ |
| 3541 | @Override |
| 3542 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3543 | int transportType) { |
| 3544 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3545 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3546 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3547 | "IMS not available on device."); |
| 3548 | } |
| 3549 | final long token = Binder.clearCallingIdentity(); |
| 3550 | try { |
| 3551 | int slotId = getSlotIndex(subId); |
| 3552 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3553 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3554 | + subId + "'"); |
| 3555 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3556 | } |
| 3557 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3558 | transportType, aBoolean -> { |
| 3559 | try { |
| 3560 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3561 | } catch (RemoteException e) { |
| 3562 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3563 | + "running. Ignore"); |
| 3564 | } |
| 3565 | }); |
| 3566 | } finally { |
| 3567 | Binder.restoreCallingIdentity(token); |
| 3568 | } |
| 3569 | } |
| 3570 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3571 | /** |
| 3572 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3573 | * @param subId The subscription to use to check the configuration. |
| 3574 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3575 | @Override |
| 3576 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3577 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3578 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3579 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3580 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3581 | final long token = Binder.clearCallingIdentity(); |
| 3582 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3583 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3584 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3585 | } catch (ImsException e) { |
| 3586 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3587 | } finally { |
| 3588 | Binder.restoreCallingIdentity(token); |
| 3589 | } |
| 3590 | } |
| 3591 | |
| 3592 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3593 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3594 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3595 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3596 | final long identity = Binder.clearCallingIdentity(); |
| 3597 | try { |
| 3598 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3599 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3600 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3601 | } catch (ImsException e) { |
| 3602 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3603 | } finally { |
| 3604 | Binder.restoreCallingIdentity(identity); |
| 3605 | } |
| 3606 | } |
| 3607 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3608 | /** |
| 3609 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3610 | * @param subId The subscription to use to check the configuration. |
| 3611 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3612 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3613 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3614 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3615 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3616 | final long identity = Binder.clearCallingIdentity(); |
| 3617 | try { |
| 3618 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3619 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3620 | } catch (ImsException e) { |
| 3621 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3622 | } finally { |
| 3623 | Binder.restoreCallingIdentity(identity); |
| 3624 | } |
| 3625 | } |
| 3626 | |
| 3627 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3628 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3629 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3630 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3631 | final long identity = Binder.clearCallingIdentity(); |
| 3632 | try { |
| 3633 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3634 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3635 | } catch (ImsException e) { |
| 3636 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3637 | } finally { |
| 3638 | Binder.restoreCallingIdentity(identity); |
| 3639 | } |
| 3640 | } |
| 3641 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3642 | /** |
| 3643 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3644 | * @param subId The subscription to use to check the configuration. |
| 3645 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3646 | @Override |
| 3647 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3648 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3649 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3650 | final long identity = Binder.clearCallingIdentity(); |
| 3651 | try { |
| 3652 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3653 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3654 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3655 | } catch (ImsException e) { |
| 3656 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3657 | } finally { |
| 3658 | Binder.restoreCallingIdentity(identity); |
| 3659 | } |
| 3660 | } |
| 3661 | |
| 3662 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3663 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3664 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3665 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3666 | final long identity = Binder.clearCallingIdentity(); |
| 3667 | try { |
| 3668 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3669 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3670 | } catch (ImsException e) { |
| 3671 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3672 | } finally { |
| 3673 | Binder.restoreCallingIdentity(identity); |
| 3674 | } |
| 3675 | } |
| 3676 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3677 | /** |
| 3678 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3679 | * @param subId The subscription to use to check the configuration. |
| 3680 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3681 | @Override |
| 3682 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3683 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3684 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3685 | final long identity = Binder.clearCallingIdentity(); |
| 3686 | try { |
| 3687 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3688 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3689 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3690 | } catch (ImsException e) { |
| 3691 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3692 | } finally { |
| 3693 | Binder.restoreCallingIdentity(identity); |
| 3694 | } |
| 3695 | } |
| 3696 | |
| 3697 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3698 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3699 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3700 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3701 | final long identity = Binder.clearCallingIdentity(); |
| 3702 | try { |
| 3703 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3704 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3705 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
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(identity); |
| 3710 | } |
| 3711 | } |
| 3712 | |
| 3713 | @Override |
| 3714 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3715 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3716 | "setVoWiFiNonPersistent"); |
| 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 | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3721 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
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 |
| 3734 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3735 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3736 | mApp, subId, "getVoWiFiModeSetting"); |
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. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3740 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3741 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3742 | } catch (ImsException e) { |
| 3743 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3744 | } finally { |
| 3745 | Binder.restoreCallingIdentity(identity); |
| 3746 | } |
| 3747 | } |
| 3748 | |
| 3749 | @Override |
| 3750 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3751 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3752 | "setVoWiFiModeSetting"); |
| 3753 | final long identity = Binder.clearCallingIdentity(); |
| 3754 | try { |
| 3755 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3756 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3757 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3758 | } catch (ImsException e) { |
| 3759 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3760 | } finally { |
| 3761 | Binder.restoreCallingIdentity(identity); |
| 3762 | } |
| 3763 | } |
| 3764 | |
| 3765 | @Override |
| 3766 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3767 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3768 | final long identity = Binder.clearCallingIdentity(); |
| 3769 | try { |
| 3770 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3771 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3772 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3773 | } catch (ImsException e) { |
| 3774 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3775 | } finally { |
| 3776 | Binder.restoreCallingIdentity(identity); |
| 3777 | } |
| 3778 | } |
| 3779 | |
| 3780 | @Override |
| 3781 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3782 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3783 | "setVoWiFiRoamingModeSetting"); |
| 3784 | final long identity = Binder.clearCallingIdentity(); |
| 3785 | try { |
| 3786 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3787 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3788 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3789 | } catch (ImsException e) { |
| 3790 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3791 | } finally { |
| 3792 | Binder.restoreCallingIdentity(identity); |
| 3793 | } |
| 3794 | } |
| 3795 | |
| 3796 | @Override |
| 3797 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3798 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3799 | "setRttCapabilityEnabled"); |
| 3800 | final long identity = Binder.clearCallingIdentity(); |
| 3801 | try { |
| 3802 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3803 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3804 | } catch (ImsException e) { |
| 3805 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3806 | } finally { |
| 3807 | Binder.restoreCallingIdentity(identity); |
| 3808 | } |
| 3809 | } |
| 3810 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3811 | /** |
| 3812 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3813 | * @param subId The subscription to use to check the configuration. |
| 3814 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3815 | @Override |
| 3816 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3817 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3818 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3819 | final long identity = Binder.clearCallingIdentity(); |
| 3820 | try { |
| 3821 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3822 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3823 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3824 | } catch (ImsException e) { |
| 3825 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3826 | } finally { |
| 3827 | Binder.restoreCallingIdentity(identity); |
| 3828 | } |
| 3829 | } |
| 3830 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3831 | @Override |
| 3832 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3833 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3834 | final long identity = Binder.clearCallingIdentity(); |
| 3835 | try { |
Brad Ebinger | 6cf0f65 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 3836 | if (!isImsAvailableOnDevice()) { |
| 3837 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3838 | "IMS not available on device."); |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 3839 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 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, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3842 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3843 | } catch (ImsException e) { |
| 3844 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3845 | } finally { |
| 3846 | Binder.restoreCallingIdentity(identity); |
| 3847 | } |
| 3848 | } |
| 3849 | |
| 3850 | @Override |
| 3851 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3852 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3853 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3854 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3855 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3856 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3857 | try { |
| 3858 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3859 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3860 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3861 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3862 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3863 | + "is inactive, ignoring unregister."); |
| 3864 | // If the subscription is no longer active, just return, since the callback will already |
| 3865 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3866 | } finally { |
| 3867 | Binder.restoreCallingIdentity(identity); |
| 3868 | } |
| 3869 | } |
| 3870 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3871 | |
| 3872 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 3873 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3874 | message); |
| 3875 | } |
| 3876 | |
| 3877 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 3878 | boolean isMmtelCapability) { |
| 3879 | Phone phone = getPhone(subId); |
| 3880 | if (phone == null) { |
| 3881 | loge("phone instance null for subid " + subId); |
| 3882 | return false; |
| 3883 | } |
| 3884 | if (isMmtelCapability) { |
| 3885 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3886 | return false; |
| 3887 | } |
| 3888 | } else { |
| 3889 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3890 | return false; |
| 3891 | } |
| 3892 | } |
| 3893 | return true; |
| 3894 | } |
| 3895 | |
| 3896 | @Override |
| 3897 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 3898 | boolean isProvisioned) { |
| 3899 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 3900 | |
| 3901 | final long identity = Binder.clearCallingIdentity(); |
| 3902 | try { |
| 3903 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3904 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3905 | return; |
| 3906 | } |
| 3907 | |
| 3908 | // this capability requires provisioning, route to the correct API. |
| 3909 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3910 | switch (capability) { |
| 3911 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3912 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3913 | ims.setEabProvisioned(isProvisioned); |
| 3914 | break; |
| 3915 | default: { |
| 3916 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3917 | + "rcs capability '" + capability + "', which does not require " |
| 3918 | + "provisioning."); |
| 3919 | } |
| 3920 | } |
| 3921 | } finally { |
| 3922 | Binder.restoreCallingIdentity(identity); |
| 3923 | } |
| 3924 | |
| 3925 | } |
| 3926 | |
| 3927 | |
| 3928 | @Override |
| 3929 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 3930 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 3931 | final long identity = Binder.clearCallingIdentity(); |
| 3932 | try { |
| 3933 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3934 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3935 | return true; |
| 3936 | } |
| 3937 | |
| 3938 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3939 | switch (capability) { |
| 3940 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3941 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3942 | return ims.isEabProvisionedOnDevice(); |
| 3943 | |
| 3944 | default: { |
| 3945 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 3946 | + "capability '" + capability + "', which does not require " |
| 3947 | + "provisioning."); |
| 3948 | } |
| 3949 | } |
| 3950 | |
| 3951 | } finally { |
| 3952 | Binder.restoreCallingIdentity(identity); |
| 3953 | } |
| 3954 | } |
| 3955 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3956 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3957 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3958 | boolean isProvisioned) { |
| 3959 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3960 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3961 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3962 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3963 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3964 | final long identity = Binder.clearCallingIdentity(); |
| 3965 | try { |
| 3966 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3967 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3968 | return; |
| 3969 | } |
| 3970 | |
| 3971 | // this capability requires provisioning, route to the correct API. |
| 3972 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3973 | switch (capability) { |
| 3974 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3975 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3976 | ims.setVolteProvisioned(isProvisioned); |
| 3977 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3978 | ims.setWfcProvisioned(isProvisioned); |
| 3979 | } |
| 3980 | break; |
| 3981 | } |
| 3982 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3983 | // There is currently no difference in VT provisioning type. |
| 3984 | ims.setVtProvisioned(isProvisioned); |
| 3985 | break; |
| 3986 | } |
| 3987 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3988 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3989 | // change the capability of the feature instead if needed. |
| 3990 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3991 | == isProvisioned) { |
| 3992 | // No change in provisioning. |
| 3993 | return; |
| 3994 | } |
| 3995 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3996 | try { |
| 3997 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3998 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3999 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4000 | + ", Exception" + e.getMessage()); |
| 4001 | } |
| 4002 | break; |
| 4003 | } |
| 4004 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4005 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4006 | + "MmTel capability '" + capability + "', which does not require " |
| 4007 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4008 | } |
| 4009 | } |
| 4010 | |
| 4011 | } finally { |
| 4012 | Binder.restoreCallingIdentity(identity); |
| 4013 | } |
| 4014 | } |
| 4015 | |
| 4016 | @Override |
| 4017 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4018 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4019 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4020 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4021 | } |
| 4022 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4023 | final long identity = Binder.clearCallingIdentity(); |
| 4024 | try { |
| 4025 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4026 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4027 | return true; |
| 4028 | } |
| 4029 | |
| 4030 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4031 | switch (capability) { |
| 4032 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4033 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4034 | return ims.isVolteProvisionedOnDevice(); |
| 4035 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4036 | return ims.isWfcProvisionedOnDevice(); |
| 4037 | } |
| 4038 | // This should never happen, since we are checking tech above to make sure it |
| 4039 | // is either LTE or IWLAN. |
| 4040 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4041 | + "capability."); |
| 4042 | } |
| 4043 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4044 | // There is currently no difference in VT provisioning type. |
| 4045 | return ims.isVtProvisionedOnDevice(); |
| 4046 | } |
| 4047 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4048 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4049 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4050 | } |
| 4051 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4052 | throw new IllegalArgumentException( |
| 4053 | "Tried to get provisioning for MmTel capability '" + capability |
| 4054 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4055 | } |
| 4056 | } |
| 4057 | |
| 4058 | } finally { |
| 4059 | Binder.restoreCallingIdentity(identity); |
| 4060 | } |
| 4061 | } |
| 4062 | |
| 4063 | @Override |
| 4064 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4065 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4066 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4067 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4068 | } |
| 4069 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4070 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4071 | return (provisionedBits & capability) > 0; |
| 4072 | } |
| 4073 | |
| 4074 | @Override |
| 4075 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4076 | boolean isProvisioned) { |
| 4077 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4078 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4079 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4080 | } |
| 4081 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4082 | "setProvisioningStatusForCapability"); |
| 4083 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4084 | // If the current provisioning status for capability already matches isProvisioned, |
| 4085 | // do nothing. |
| 4086 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4087 | return; |
| 4088 | } |
| 4089 | if (isProvisioned) { |
| 4090 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4091 | } else { |
| 4092 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4093 | } |
| 4094 | } |
| 4095 | |
| 4096 | /** |
| 4097 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4098 | * technology. The bitfield should mirror the bitfield defined by |
| 4099 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4100 | */ |
| 4101 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4102 | String key = getMmTelProvisioningKey(subId, tech); |
| 4103 | // Default is no capabilities are provisioned. |
| 4104 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4105 | } |
| 4106 | |
| 4107 | /** |
| 4108 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4109 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4110 | * technology specified. |
| 4111 | * |
| 4112 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4113 | */ |
| 4114 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4115 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4116 | String key = getMmTelProvisioningKey(subId, tech); |
| 4117 | editor.putInt(key, newField); |
| 4118 | editor.commit(); |
| 4119 | } |
| 4120 | |
| 4121 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4122 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4123 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4124 | } |
| 4125 | |
| 4126 | /** |
| 4127 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4128 | * carrier associated with the subscription id. |
| 4129 | */ |
| 4130 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4131 | int capability) { |
| 4132 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4133 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4134 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4135 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4136 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4137 | false); |
| 4138 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4139 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4140 | |
| 4141 | // First check to make sure that the capability requires provisioning. |
| 4142 | switch (capability) { |
| 4143 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4144 | // intentional fallthrough |
| 4145 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4146 | if (requireVoiceVtProvisioning) { |
| 4147 | // Voice and Video requires provisioning |
| 4148 | return true; |
| 4149 | } |
| 4150 | break; |
| 4151 | } |
| 4152 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4153 | if (requireUtProvisioning) { |
| 4154 | // UT requires provisioning |
| 4155 | return true; |
| 4156 | } |
| 4157 | break; |
| 4158 | } |
| 4159 | } |
| 4160 | return false; |
| 4161 | } |
| 4162 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4163 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4164 | int capability) { |
| 4165 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4166 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4167 | |
| 4168 | boolean requireRcsProvisioning = c.getBoolean( |
| 4169 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4170 | |
| 4171 | // First check to make sure that the capability requires provisioning. |
| 4172 | switch (capability) { |
| 4173 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4174 | // intentional fallthrough |
| 4175 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4176 | if (requireRcsProvisioning) { |
| 4177 | // OPTION or PRESENCE requires provisioning |
| 4178 | return true; |
| 4179 | } |
| 4180 | break; |
| 4181 | } |
| 4182 | } |
| 4183 | return false; |
| 4184 | } |
| 4185 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4186 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4187 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4188 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4189 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4190 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4191 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4192 | final long identity = Binder.clearCallingIdentity(); |
| 4193 | try { |
| 4194 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4195 | int slotId = getSlotIndex(subId); |
| 4196 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4197 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4198 | + subId + "' for key:" + key); |
| 4199 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4200 | } |
| 4201 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4202 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4203 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4204 | + subId + "' for key:" + key); |
| 4205 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4206 | } finally { |
| 4207 | Binder.restoreCallingIdentity(identity); |
| 4208 | } |
| 4209 | } |
| 4210 | |
| 4211 | @Override |
| 4212 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4213 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4214 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4215 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4216 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4217 | final long identity = Binder.clearCallingIdentity(); |
| 4218 | try { |
| 4219 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4220 | int slotId = getSlotIndex(subId); |
| 4221 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4222 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4223 | + subId + "' for key:" + key); |
| 4224 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4225 | } |
| 4226 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4227 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4228 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4229 | + subId + "' for key:" + key); |
| 4230 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4231 | } finally { |
| 4232 | Binder.restoreCallingIdentity(identity); |
| 4233 | } |
| 4234 | } |
| 4235 | |
| 4236 | @Override |
| 4237 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4238 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4239 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4240 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4241 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4242 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4243 | final long identity = Binder.clearCallingIdentity(); |
| 4244 | try { |
| 4245 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4246 | int slotId = getSlotIndex(subId); |
| 4247 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4248 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4249 | + subId + "' for key:" + key); |
| 4250 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4251 | } |
| 4252 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4253 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4254 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4255 | + "' for key:" + key); |
| 4256 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4257 | } finally { |
| 4258 | Binder.restoreCallingIdentity(identity); |
| 4259 | } |
| 4260 | } |
| 4261 | |
| 4262 | @Override |
| 4263 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4264 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4265 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4266 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4267 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4268 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4269 | final long identity = Binder.clearCallingIdentity(); |
| 4270 | try { |
| 4271 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4272 | int slotId = getSlotIndex(subId); |
| 4273 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4274 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4275 | + subId + "' for key:" + key); |
| 4276 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4277 | } |
| 4278 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4279 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4280 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4281 | + "' for key:" + key); |
| 4282 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4283 | } finally { |
| 4284 | Binder.restoreCallingIdentity(identity); |
| 4285 | } |
| 4286 | } |
| 4287 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4288 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4289 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4290 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4291 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4292 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4293 | } |
| 4294 | return slotId; |
| 4295 | } |
| 4296 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4297 | private int getSlotIndex(int subId) { |
| 4298 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4299 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4300 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4301 | } |
| 4302 | return slotId; |
| 4303 | } |
| 4304 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4305 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4306 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4307 | */ |
| 4308 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4309 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4310 | String callingFeatureId) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4311 | final int targetSdk = getTargetSdk(callingPackage); |
| 4312 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4313 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4314 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4315 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4316 | mApp, subId, callingPackage, callingFeatureId, |
| 4317 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4318 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4319 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4320 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4321 | final long identity = Binder.clearCallingIdentity(); |
| 4322 | try { |
| 4323 | final Phone phone = getPhone(subId); |
| 4324 | if (phone != null) { |
| 4325 | return phone.getServiceState().getDataNetworkType(); |
| 4326 | } else { |
| 4327 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4328 | } |
| 4329 | } finally { |
| 4330 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4331 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4332 | } |
| 4333 | |
| 4334 | /** |
| 4335 | * Returns the data network type |
| 4336 | */ |
| 4337 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4338 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4339 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4340 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4341 | } |
| 4342 | |
| 4343 | /** |
| 4344 | * Returns the data network type for a subId |
| 4345 | */ |
| 4346 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4347 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4348 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4349 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4350 | mApp, subId, callingPackage, callingFeatureId, |
| 4351 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4352 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4353 | } |
| 4354 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4355 | final long identity = Binder.clearCallingIdentity(); |
| 4356 | try { |
| 4357 | final Phone phone = getPhone(subId); |
| 4358 | if (phone != null) { |
| 4359 | return phone.getServiceState().getDataNetworkType(); |
| 4360 | } else { |
| 4361 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4362 | } |
| 4363 | } finally { |
| 4364 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4365 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4366 | } |
| 4367 | |
| 4368 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4369 | * Returns the Voice network type for a subId |
| 4370 | */ |
| 4371 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4372 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4373 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4374 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4375 | mApp, subId, callingPackage, callingFeatureId, |
| 4376 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4377 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4378 | } |
| 4379 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4380 | final long identity = Binder.clearCallingIdentity(); |
| 4381 | try { |
| 4382 | final Phone phone = getPhone(subId); |
| 4383 | if (phone != null) { |
| 4384 | return phone.getServiceState().getVoiceNetworkType(); |
| 4385 | } else { |
| 4386 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4387 | } |
| 4388 | } finally { |
| 4389 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4390 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4391 | } |
| 4392 | |
| 4393 | /** |
| 4394 | * @return true if a ICC card is present |
| 4395 | */ |
| 4396 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4397 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4398 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4399 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4400 | } |
| 4401 | |
| 4402 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4403 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4404 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4405 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4406 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4407 | final long identity = Binder.clearCallingIdentity(); |
| 4408 | try { |
| 4409 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4410 | if (phone != null) { |
| 4411 | return phone.getIccCard().hasIccCard(); |
| 4412 | } else { |
| 4413 | return false; |
| 4414 | } |
| 4415 | } finally { |
| 4416 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4417 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4418 | } |
| 4419 | |
| 4420 | /** |
| 4421 | * Return if the current radio is LTE on CDMA. This |
| 4422 | * is a tri-state return value as for a period of time |
| 4423 | * the mode may be unknown. |
| 4424 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4425 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4426 | * @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] | 4427 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4428 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4429 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4430 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4431 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4432 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4433 | } |
| 4434 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4435 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4436 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4437 | String callingFeatureId) { |
Sarah Chin | f6656a6 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4438 | try { |
| 4439 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4440 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4441 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4442 | } |
| 4443 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4444 | final long identity = Binder.clearCallingIdentity(); |
| 4445 | try { |
| 4446 | final Phone phone = getPhone(subId); |
| 4447 | if (phone == null) { |
| 4448 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4449 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 4450 | return TelephonyProperties.lte_on_cdma_device() |
| 4451 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4452 | } |
| 4453 | } finally { |
| 4454 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4455 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4456 | } |
| 4457 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4458 | /** |
| 4459 | * {@hide} |
| 4460 | * Returns Default subId, 0 in the case of single standby. |
| 4461 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4462 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4463 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4464 | } |
| 4465 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4466 | private int getSlotForDefaultSubscription() { |
| 4467 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4468 | } |
| 4469 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4470 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4471 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4472 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4473 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4474 | private boolean isActiveSubscription(int subId) { |
| 4475 | return mSubscriptionController.isActiveSubId(subId); |
| 4476 | } |
| 4477 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4478 | /** |
| 4479 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4480 | */ |
| 4481 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4482 | final long identity = Binder.clearCallingIdentity(); |
| 4483 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4484 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4485 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4486 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4487 | } finally { |
| 4488 | Binder.restoreCallingIdentity(identity); |
| 4489 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4490 | } |
| 4491 | |
| 4492 | /** |
| 4493 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4494 | */ |
| 4495 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4496 | final long identity = Binder.clearCallingIdentity(); |
| 4497 | try { |
| 4498 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4499 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4500 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4501 | } finally { |
| 4502 | Binder.restoreCallingIdentity(identity); |
| 4503 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4504 | } |
| 4505 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4506 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4507 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4508 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4509 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4510 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4511 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4512 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4513 | if (phoneId == -1) { |
| 4514 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4515 | + " does not correspond to an active phone"); |
| 4516 | } |
| 4517 | return PhoneFactory.getPhone(phoneId); |
| 4518 | } |
| 4519 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4520 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4521 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4522 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4523 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4524 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4525 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4526 | if (DBG) { |
| 4527 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4528 | } |
| 4529 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4530 | p2); |
| 4531 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4532 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4533 | |
| 4534 | @Override |
| 4535 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4536 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4537 | enforceModifyPermission(); |
| 4538 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4539 | if (DBG) { |
| 4540 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4541 | } |
| 4542 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4543 | callingPackage, aid, p2); |
| 4544 | } |
| 4545 | |
| 4546 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4547 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4548 | final long identity = Binder.clearCallingIdentity(); |
| 4549 | try { |
| 4550 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4551 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4552 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4553 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4554 | if (bestComponent == null |
| 4555 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4556 | loge("The calling package is not allowed to access ISD-R."); |
| 4557 | throw new SecurityException( |
| 4558 | "The calling package is not allowed to access ISD-R."); |
| 4559 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4560 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4561 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4562 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4563 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4564 | null /* workSource */); |
| 4565 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4566 | return response; |
| 4567 | } finally { |
| 4568 | Binder.restoreCallingIdentity(identity); |
| 4569 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4570 | } |
| 4571 | |
| 4572 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4573 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4574 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4575 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4576 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4577 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4578 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4579 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4580 | @Override |
| 4581 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4582 | enforceModifyPermission(); |
| 4583 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4584 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4585 | channel); |
| 4586 | } |
| 4587 | |
| 4588 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4589 | final long identity = Binder.clearCallingIdentity(); |
| 4590 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4591 | if (channel < 0) { |
| 4592 | return false; |
| 4593 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4594 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4595 | null /* workSource */); |
| 4596 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4597 | return success; |
| 4598 | } finally { |
| 4599 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4600 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4601 | } |
| 4602 | |
| 4603 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4604 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4605 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4606 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4607 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4608 | if (DBG) { |
| 4609 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4610 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4611 | + p3 + " data=" + data); |
| 4612 | } |
| 4613 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4614 | command, p1, p2, p3, data); |
| 4615 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4616 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4617 | @Override |
| 4618 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4619 | int command, int p1, int p2, int p3, String data) { |
| 4620 | enforceModifyPermission(); |
| 4621 | if (DBG) { |
| 4622 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4623 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4624 | + p3 + " data=" + data); |
| 4625 | } |
| 4626 | return iccTransmitApduLogicalChannelWithPermission( |
| 4627 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4628 | data); |
| 4629 | } |
| 4630 | |
| 4631 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4632 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4633 | final long identity = Binder.clearCallingIdentity(); |
| 4634 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4635 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4636 | return ""; |
| 4637 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4638 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4639 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4640 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4641 | null /* workSource */); |
| 4642 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4643 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4644 | // Append the returned status code to the end of the response payload. |
| 4645 | String s = Integer.toHexString( |
| 4646 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4647 | if (response.payload != null) { |
| 4648 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4649 | } |
| 4650 | return s; |
| 4651 | } finally { |
| 4652 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4653 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4654 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4655 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4656 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4657 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4658 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4659 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4660 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4661 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4662 | if (DBG) { |
| 4663 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4664 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4665 | } |
| 4666 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4667 | cla, command, p1, p2, p3, data); |
| 4668 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4669 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4670 | @Override |
| 4671 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4672 | int command, int p1, int p2, int p3, String data) { |
| 4673 | enforceModifyPermission(); |
| 4674 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4675 | if (DBG) { |
| 4676 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4677 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4678 | + " data=" + data); |
| 4679 | } |
| 4680 | |
| 4681 | return iccTransmitApduBasicChannelWithPermission( |
| 4682 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4683 | p2, p3, data); |
| 4684 | } |
| 4685 | |
| 4686 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4687 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4688 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4689 | final long identity = Binder.clearCallingIdentity(); |
| 4690 | try { |
| 4691 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4692 | && TextUtils.equals(ISDR_AID, data)) { |
| 4693 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4694 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4695 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4696 | if (bestComponent == null |
| 4697 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4698 | loge("The calling package is not allowed to select ISD-R."); |
| 4699 | throw new SecurityException( |
| 4700 | "The calling package is not allowed to select ISD-R."); |
| 4701 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4702 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4703 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4704 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4705 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4706 | null /* workSource */); |
| 4707 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4708 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4709 | // Append the returned status code to the end of the response payload. |
| 4710 | String s = Integer.toHexString( |
| 4711 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4712 | if (response.payload != null) { |
| 4713 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4714 | } |
| 4715 | return s; |
| 4716 | } finally { |
| 4717 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4718 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4719 | } |
| 4720 | |
| 4721 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4722 | 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] | 4723 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4724 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4725 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4726 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4727 | final long identity = Binder.clearCallingIdentity(); |
| 4728 | try { |
| 4729 | if (DBG) { |
| 4730 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4731 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4732 | } |
| 4733 | |
| 4734 | IccIoResult response = |
| 4735 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4736 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4737 | subId); |
| 4738 | |
| 4739 | if (DBG) { |
| 4740 | log("Exchange SIM_IO [R]" + response); |
| 4741 | } |
| 4742 | |
| 4743 | byte[] result = null; |
| 4744 | int length = 2; |
| 4745 | if (response.payload != null) { |
| 4746 | length = 2 + response.payload.length; |
| 4747 | result = new byte[length]; |
| 4748 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4749 | } else { |
| 4750 | result = new byte[length]; |
| 4751 | } |
| 4752 | |
| 4753 | result[length - 1] = (byte) response.sw2; |
| 4754 | result[length - 2] = (byte) response.sw1; |
| 4755 | return result; |
| 4756 | } finally { |
| 4757 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4758 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4759 | } |
| 4760 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4761 | /** |
| 4762 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4763 | * on a particular subscription |
| 4764 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4765 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 4766 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4767 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4768 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4769 | return null; |
| 4770 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4771 | |
| 4772 | final long identity = Binder.clearCallingIdentity(); |
| 4773 | try { |
| 4774 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4775 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4776 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4777 | return null; |
| 4778 | } |
| 4779 | Object response = sendRequest( |
| 4780 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4781 | if (response instanceof String[]) { |
| 4782 | return (String[]) response; |
| 4783 | } |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4784 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4785 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4786 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4787 | } finally { |
| 4788 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4789 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4790 | } |
| 4791 | |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4792 | /** |
| 4793 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 4794 | * subscription. |
| 4795 | * |
| 4796 | * @param subId the id of the subscription. |
| 4797 | * @param appType the uicc app type, must be USIM or SIM. |
| 4798 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 4799 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4800 | * @param callingFeatureId the feature in the package. |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4801 | * @return number of fplmns that is successfully written to the SIM. |
| 4802 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4803 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 4804 | String callingFeatureId) { |
| 4805 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 4806 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4807 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 4808 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 4809 | } |
| 4810 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 4811 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4812 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 4813 | } |
| 4814 | if (fplmns == null) { |
| 4815 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 4816 | } |
| 4817 | for (String fplmn : fplmns) { |
| 4818 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 4819 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 4820 | } |
| 4821 | } |
| 4822 | final long identity = Binder.clearCallingIdentity(); |
| 4823 | try { |
| 4824 | Object response = sendRequest( |
| 4825 | CMD_SET_FORBIDDEN_PLMNS, |
| 4826 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 4827 | subId); |
| 4828 | return (int) response; |
| 4829 | } finally { |
| 4830 | Binder.restoreCallingIdentity(identity); |
| 4831 | } |
| 4832 | } |
| 4833 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4834 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4835 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4836 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4837 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4838 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4839 | final long identity = Binder.clearCallingIdentity(); |
| 4840 | try { |
| 4841 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4842 | if (response.payload == null) { |
| 4843 | return ""; |
| 4844 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4845 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4846 | // Append the returned status code to the end of the response payload. |
| 4847 | String s = Integer.toHexString( |
| 4848 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4849 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4850 | return s; |
| 4851 | } finally { |
| 4852 | Binder.restoreCallingIdentity(identity); |
| 4853 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4854 | } |
| 4855 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4856 | /** |
| 4857 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4858 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4859 | * |
| 4860 | * @param itemID the ID of the item to read |
| 4861 | * @return the NV item as a String, or null on error. |
| 4862 | */ |
| 4863 | @Override |
| 4864 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4865 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4866 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4867 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4868 | |
| 4869 | final long identity = Binder.clearCallingIdentity(); |
| 4870 | try { |
| 4871 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4872 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4873 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4874 | return value; |
| 4875 | } finally { |
| 4876 | Binder.restoreCallingIdentity(identity); |
| 4877 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4878 | } |
| 4879 | |
| 4880 | /** |
| 4881 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4882 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4883 | * |
| 4884 | * @param itemID the ID of the item to read |
| 4885 | * @param itemValue the value to write, as a String |
| 4886 | * @return true on success; false on any failure |
| 4887 | */ |
| 4888 | @Override |
| 4889 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4890 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4891 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4892 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4893 | |
| 4894 | final long identity = Binder.clearCallingIdentity(); |
| 4895 | try { |
| 4896 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4897 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4898 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4899 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4900 | return success; |
| 4901 | } finally { |
| 4902 | Binder.restoreCallingIdentity(identity); |
| 4903 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4904 | } |
| 4905 | |
| 4906 | /** |
| 4907 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4908 | * Used for device configuration by some CDMA operators. |
| 4909 | * |
| 4910 | * @param preferredRoamingList byte array containing the new PRL |
| 4911 | * @return true on success; false on any failure |
| 4912 | */ |
| 4913 | @Override |
| 4914 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4915 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4916 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4917 | |
| 4918 | final long identity = Binder.clearCallingIdentity(); |
| 4919 | try { |
| 4920 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4921 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4922 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4923 | return success; |
| 4924 | } finally { |
| 4925 | Binder.restoreCallingIdentity(identity); |
| 4926 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4927 | } |
| 4928 | |
| 4929 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4930 | * 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] | 4931 | * Used for device configuration by some CDMA operators. |
| 4932 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4933 | * @param slotIndex - device slot. |
| 4934 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4935 | * @return true on success; false on any failure |
| 4936 | */ |
| 4937 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4938 | public boolean resetModemConfig(int slotIndex) { |
| 4939 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4940 | if (phone != null) { |
| 4941 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4942 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4943 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4944 | final long identity = Binder.clearCallingIdentity(); |
| 4945 | try { |
| 4946 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4947 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4948 | return success; |
| 4949 | } finally { |
| 4950 | Binder.restoreCallingIdentity(identity); |
| 4951 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4952 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4953 | return false; |
| 4954 | } |
| 4955 | |
| 4956 | /** |
| 4957 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4958 | * |
| 4959 | * @param slotIndex - device slot. |
| 4960 | * |
| 4961 | * @return true on success; false on any failure |
| 4962 | */ |
| 4963 | @Override |
| 4964 | public boolean rebootModem(int slotIndex) { |
| 4965 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4966 | if (phone != null) { |
| 4967 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4968 | mApp, phone.getSubId(), "rebootModem"); |
| 4969 | |
| 4970 | final long identity = Binder.clearCallingIdentity(); |
| 4971 | try { |
| 4972 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4973 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4974 | return success; |
| 4975 | } finally { |
| 4976 | Binder.restoreCallingIdentity(identity); |
| 4977 | } |
| 4978 | } |
| 4979 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4980 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4981 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4982 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 4983 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4984 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4985 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4986 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4987 | return new String[0]; |
| 4988 | } |
| 4989 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4990 | final long identity = Binder.clearCallingIdentity(); |
| 4991 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4992 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4993 | } finally { |
| 4994 | Binder.restoreCallingIdentity(identity); |
| 4995 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4996 | } |
| 4997 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4998 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 4999 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5000 | * {@link #disableIms(int)}. |
| 5001 | * @param slotIndex device slot. |
| 5002 | */ |
| 5003 | public void resetIms(int slotIndex) { |
| 5004 | enforceModifyPermission(); |
| 5005 | |
| 5006 | final long identity = Binder.clearCallingIdentity(); |
| 5007 | try { |
| 5008 | if (mImsResolver == null) { |
| 5009 | // may happen if the does not support IMS. |
| 5010 | return; |
| 5011 | } |
| 5012 | mImsResolver.disableIms(slotIndex); |
| 5013 | mImsResolver.enableIms(slotIndex); |
| 5014 | } finally { |
| 5015 | Binder.restoreCallingIdentity(identity); |
| 5016 | } |
| 5017 | } |
| 5018 | |
| 5019 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5020 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5021 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5022 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5023 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5024 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5025 | |
| 5026 | final long identity = Binder.clearCallingIdentity(); |
| 5027 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5028 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5029 | // may happen if the device does not support IMS. |
| 5030 | return; |
| 5031 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5032 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5033 | } finally { |
| 5034 | Binder.restoreCallingIdentity(identity); |
| 5035 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5036 | } |
| 5037 | |
| 5038 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5039 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5040 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5041 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5042 | public void disableIms(int slotId) { |
| 5043 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5044 | |
| 5045 | final long identity = Binder.clearCallingIdentity(); |
| 5046 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5047 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5048 | // may happen if the device does not support IMS. |
| 5049 | return; |
| 5050 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5051 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5052 | } finally { |
| 5053 | Binder.restoreCallingIdentity(identity); |
| 5054 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5055 | } |
| 5056 | |
| 5057 | /** |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5058 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5059 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5060 | */ |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5061 | @Override |
Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5062 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5063 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5064 | |
| 5065 | final long identity = Binder.clearCallingIdentity(); |
| 5066 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5067 | if (mImsResolver == null) { |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5068 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5069 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5070 | } |
Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5071 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5072 | } finally { |
| 5073 | Binder.restoreCallingIdentity(identity); |
| 5074 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5075 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5076 | /** |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5077 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5078 | */ |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5079 | @Override |
| 5080 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5081 | enforceModifyPermission(); |
| 5082 | |
| 5083 | final long identity = Binder.clearCallingIdentity(); |
| 5084 | try { |
| 5085 | if (mImsResolver == null) return; |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5086 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5087 | } finally { |
| 5088 | Binder.restoreCallingIdentity(identity); |
| 5089 | } |
| 5090 | } |
| 5091 | |
| 5092 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5093 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5094 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5095 | */ |
| 5096 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5097 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5098 | |
| 5099 | final long identity = Binder.clearCallingIdentity(); |
| 5100 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5101 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5102 | // may happen if the device does not support IMS. |
| 5103 | return null; |
| 5104 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5105 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5106 | } finally { |
| 5107 | Binder.restoreCallingIdentity(identity); |
| 5108 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5109 | } |
| 5110 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5111 | /** |
| 5112 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5113 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5114 | */ |
| 5115 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5116 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5117 | |
| 5118 | final long identity = Binder.clearCallingIdentity(); |
| 5119 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5120 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5121 | // may happen if the device does not support IMS. |
| 5122 | return null; |
| 5123 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5124 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5125 | } finally { |
| 5126 | Binder.restoreCallingIdentity(identity); |
| 5127 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5128 | } |
| 5129 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5130 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5131 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5132 | * |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5133 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5134 | * @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] | 5135 | * ImsService is the device default ImsService. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5136 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5137 | * @param packageName The name of the package that the current configuration will be replaced |
| 5138 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5139 | * @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] | 5140 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5141 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5142 | int[] featureTypes, String packageName) { |
| 5143 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5144 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5145 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5146 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5147 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5148 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5149 | final long identity = Binder.clearCallingIdentity(); |
| 5150 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5151 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5152 | // may happen if the device does not support IMS. |
| 5153 | return false; |
| 5154 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5155 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5156 | for (int featureType : featureTypes) { |
| 5157 | featureConfig.put(featureType, packageName); |
| 5158 | } |
| 5159 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5160 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5161 | } finally { |
| 5162 | Binder.restoreCallingIdentity(identity); |
| 5163 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5164 | } |
| 5165 | |
| 5166 | /** |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5167 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5168 | * |
| 5169 | * @param slotId The slot that the ImsService is associated with. |
| 5170 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5171 | * the device default. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5172 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5173 | * @return the package name of the ImsService configuration. |
| 5174 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5175 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5176 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5177 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5178 | TelephonyPermissions |
| 5179 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5180 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5181 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5182 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5183 | final long identity = Binder.clearCallingIdentity(); |
| 5184 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5185 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5186 | // may happen if the device does not support IMS. |
| 5187 | return ""; |
| 5188 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5189 | // TODO: change API to query RCS separately. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5190 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5191 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5192 | } finally { |
| 5193 | Binder.restoreCallingIdentity(identity); |
| 5194 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5195 | } |
| 5196 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5197 | /** |
| 5198 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5199 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5200 | * @param callback A callback with an integer containing the |
| 5201 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5202 | */ |
| 5203 | @Override |
| 5204 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5205 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5206 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5207 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5208 | "IMS not available on device."); |
| 5209 | } |
| 5210 | final long token = Binder.clearCallingIdentity(); |
| 5211 | try { |
| 5212 | int slotId = getSlotIndex(subId); |
| 5213 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5214 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5215 | + subId + "'"); |
| 5216 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5217 | } |
| 5218 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5219 | try { |
| 5220 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5221 | } catch (RemoteException e) { |
| 5222 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5223 | + "Ignore"); |
| 5224 | } |
| 5225 | }); |
| 5226 | } finally { |
| 5227 | Binder.restoreCallingIdentity(token); |
| 5228 | } |
| 5229 | } |
| 5230 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5231 | public void setImsRegistrationState(boolean registered) { |
| 5232 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5233 | |
| 5234 | final long identity = Binder.clearCallingIdentity(); |
| 5235 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5236 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5237 | } finally { |
| 5238 | Binder.restoreCallingIdentity(identity); |
| 5239 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5240 | } |
| 5241 | |
| 5242 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5243 | * Set the network selection mode to automatic. |
| 5244 | * |
| 5245 | */ |
| 5246 | @Override |
| 5247 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5248 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5249 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5250 | |
| 5251 | final long identity = Binder.clearCallingIdentity(); |
| 5252 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5253 | if (!isActiveSubscription(subId)) { |
| 5254 | return; |
| 5255 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5256 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 5257 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 5258 | } finally { |
| 5259 | Binder.restoreCallingIdentity(identity); |
| 5260 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5261 | } |
| 5262 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5263 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5264 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5265 | * |
| 5266 | * @param subId the id of the subscription. |
| 5267 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5268 | * the operator to attach to. |
| 5269 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5270 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5271 | * normal network selection next time. |
| 5272 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5273 | */ |
| 5274 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5275 | public boolean setNetworkSelectionModeManual( |
| 5276 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5277 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5278 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5279 | |
| 5280 | if (!isActiveSubscription(subId)) { |
| 5281 | return false; |
| 5282 | } |
| 5283 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5284 | final long identity = Binder.clearCallingIdentity(); |
| 5285 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5286 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5287 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5288 | if (DBG) { |
| 5289 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5290 | + " operator: " + operatorInfo); |
| 5291 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5292 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5293 | } finally { |
| 5294 | Binder.restoreCallingIdentity(identity); |
| 5295 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5296 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5297 | /** |
| 5298 | * Get the manual network selection |
| 5299 | * |
| 5300 | * @param subId the id of the subscription. |
| 5301 | * |
| 5302 | * @return the previously saved user selected PLMN |
| 5303 | */ |
| 5304 | @Override |
| 5305 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5306 | TelephonyPermissions |
| 5307 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5308 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5309 | |
| 5310 | final long identity = Binder.clearCallingIdentity(); |
| 5311 | try { |
| 5312 | if (!isActiveSubscription(subId)) { |
| 5313 | return ""; |
| 5314 | } |
| 5315 | |
| 5316 | final Phone phone = getPhone(subId); |
| 5317 | if (phone == null) { |
| 5318 | return ""; |
| 5319 | } |
| 5320 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5321 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5322 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5323 | } finally { |
| 5324 | Binder.restoreCallingIdentity(identity); |
| 5325 | } |
| 5326 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5327 | |
| 5328 | /** |
| 5329 | * Scans for available networks. |
| 5330 | */ |
| 5331 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5332 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5333 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5334 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5335 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5336 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5337 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5338 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5339 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5340 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5341 | .setCallingPid(Binder.getCallingPid()) |
| 5342 | .setCallingUid(Binder.getCallingUid()) |
| 5343 | .setMethod("getCellNetworkScanResults") |
| 5344 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5345 | .build()); |
| 5346 | switch (locationResult) { |
| 5347 | case DENIED_HARD: |
| 5348 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5349 | case DENIED_SOFT: |
| 5350 | return null; |
| 5351 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5352 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5353 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5354 | try { |
| 5355 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5356 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5357 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5358 | } finally { |
| 5359 | Binder.restoreCallingIdentity(identity); |
| 5360 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5361 | } |
| 5362 | |
| 5363 | /** |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5364 | * Get the call forwarding info, given the call forwarding reason. |
| 5365 | */ |
| 5366 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5367 | public void getCallForwarding(int subId, int callForwardingReason, |
| 5368 | ICallForwardingInfoCallback callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5369 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5370 | long identity = Binder.clearCallingIdentity(); |
| 5371 | try { |
| 5372 | if (DBG) { |
| 5373 | log("getCallForwarding: subId " + subId |
| 5374 | + " callForwardingReason" + callForwardingReason); |
| 5375 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5376 | |
| 5377 | Phone phone = getPhone(subId); |
| 5378 | if (phone == null) { |
| 5379 | try { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5380 | callback.onError( |
| 5381 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5382 | } catch (RemoteException e) { |
| 5383 | // ignore |
| 5384 | } |
| 5385 | return; |
| 5386 | } |
| 5387 | |
| 5388 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 5389 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 5390 | @Override |
| 5391 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 5392 | try { |
| 5393 | callback.onCallForwardingInfoAvailable(info); |
| 5394 | } catch (RemoteException e) { |
| 5395 | // ignore |
| 5396 | } |
| 5397 | } |
| 5398 | |
| 5399 | @Override |
| 5400 | public void onError(int error) { |
| 5401 | try { |
| 5402 | callback.onError(error); |
| 5403 | } catch (RemoteException e) { |
| 5404 | // ignore |
| 5405 | } |
| 5406 | } |
| 5407 | }); |
| 5408 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5409 | } finally { |
| 5410 | Binder.restoreCallingIdentity(identity); |
| 5411 | } |
| 5412 | } |
| 5413 | |
| 5414 | /** |
| 5415 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5416 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5417 | */ |
| 5418 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5419 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 5420 | IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5421 | enforceModifyPermission(); |
| 5422 | long identity = Binder.clearCallingIdentity(); |
| 5423 | try { |
| 5424 | if (DBG) { |
| 5425 | log("setCallForwarding: subId " + subId |
| 5426 | + " callForwardingInfo" + callForwardingInfo); |
| 5427 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5428 | |
| 5429 | Phone phone = getPhone(subId); |
| 5430 | if (phone == null) { |
| 5431 | try { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5432 | callback.accept( |
| 5433 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5434 | } catch (RemoteException e) { |
| 5435 | // ignore |
| 5436 | } |
| 5437 | return; |
| 5438 | } |
| 5439 | |
| 5440 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 5441 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5442 | |
| 5443 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5444 | } finally { |
| 5445 | Binder.restoreCallingIdentity(identity); |
| 5446 | } |
| 5447 | } |
| 5448 | |
| 5449 | /** |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5450 | * Get the call waiting status for a subId. |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5451 | */ |
| 5452 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5453 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5454 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5455 | long identity = Binder.clearCallingIdentity(); |
| 5456 | try { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5457 | |
| 5458 | Phone phone = getPhone(subId); |
| 5459 | if (phone == null) { |
| 5460 | try { |
| 5461 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5462 | } catch (RemoteException e) { |
| 5463 | // ignore |
| 5464 | } |
| 5465 | return; |
| 5466 | } |
| 5467 | |
| 5468 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 5469 | |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5470 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5471 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5472 | } finally { |
| 5473 | Binder.restoreCallingIdentity(identity); |
| 5474 | } |
| 5475 | } |
| 5476 | |
| 5477 | /** |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5478 | * Sets whether call waiting is enabled for a given subId. |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5479 | */ |
| 5480 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5481 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5482 | enforceModifyPermission(); |
| 5483 | long identity = Binder.clearCallingIdentity(); |
| 5484 | try { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5485 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 5486 | |
| 5487 | Phone phone = getPhone(subId); |
| 5488 | if (phone == null) { |
| 5489 | try { |
| 5490 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5491 | } catch (RemoteException e) { |
| 5492 | // ignore |
| 5493 | } |
| 5494 | return; |
| 5495 | } |
| 5496 | |
| 5497 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 5498 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5499 | |
| 5500 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5501 | } finally { |
| 5502 | Binder.restoreCallingIdentity(identity); |
| 5503 | } |
| 5504 | } |
| 5505 | |
| 5506 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5507 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5508 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5509 | * @param subId id of the subscription |
| 5510 | * @param request contains the radio access networks with bands/channels to scan |
| 5511 | * @param messenger callback messenger for scan results or errors |
| 5512 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5513 | * @return the id of the requested scan which can be used to stop the scan. |
| 5514 | */ |
| 5515 | @Override |
| 5516 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5517 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5518 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5519 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5520 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5521 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5522 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5523 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5524 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5525 | .setCallingPid(Binder.getCallingPid()) |
| 5526 | .setCallingUid(Binder.getCallingUid()) |
| 5527 | .setMethod("requestNetworkScan") |
| 5528 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5529 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5530 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 284aa04 | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5531 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 5532 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5533 | if (e != null) { |
| 5534 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5535 | throw e; |
| 5536 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5537 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5538 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5539 | } |
| 5540 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5541 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5542 | int callingUid = Binder.getCallingUid(); |
| 5543 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5544 | final long identity = Binder.clearCallingIdentity(); |
| 5545 | try { |
| 5546 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5547 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5548 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5549 | } finally { |
| 5550 | Binder.restoreCallingIdentity(identity); |
| 5551 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5552 | } |
| 5553 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5554 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 284aa04 | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5555 | NetworkScanRequest request, int subId, String callingPackage) { |
| 5556 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5557 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5558 | boolean hasNetworkScanPermission = |
| 5559 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5560 | == PERMISSION_GRANTED; |
| 5561 | |
| 5562 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5563 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5564 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5565 | } |
| 5566 | |
| 5567 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5568 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5569 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5570 | return new SecurityException("Specific channels must not be" |
| 5571 | + " scanned without location access."); |
| 5572 | } |
| 5573 | } |
| 5574 | } |
| 5575 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5576 | return null; |
| 5577 | } |
| 5578 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5579 | /** |
| 5580 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5581 | * |
| 5582 | * @param subId id of the subscription |
| 5583 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5584 | */ |
| 5585 | @Override |
| 5586 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5587 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5588 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5589 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5590 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5591 | final long identity = Binder.clearCallingIdentity(); |
| 5592 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5593 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5594 | } finally { |
| 5595 | Binder.restoreCallingIdentity(identity); |
| 5596 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5597 | } |
| 5598 | |
| 5599 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5600 | * Get the calculated preferred network type. |
| 5601 | * Used for debugging incorrect network type. |
| 5602 | * |
| 5603 | * @return the preferred network type, defined in RILConstants.java. |
| 5604 | */ |
| 5605 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5606 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5607 | final Phone defaultPhone = getDefaultPhone(); |
| 5608 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5609 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5610 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5611 | } |
| 5612 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5613 | final long identity = Binder.clearCallingIdentity(); |
| 5614 | try { |
| 5615 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5616 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5617 | } finally { |
| 5618 | Binder.restoreCallingIdentity(identity); |
| 5619 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5620 | } |
| 5621 | |
| 5622 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5623 | * Get the preferred network type. |
| 5624 | * Used for device configuration by some CDMA operators. |
| 5625 | * |
| 5626 | * @return the preferred network type, defined in RILConstants.java. |
| 5627 | */ |
| 5628 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5629 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5630 | TelephonyPermissions |
| 5631 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5632 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5633 | |
| 5634 | final long identity = Binder.clearCallingIdentity(); |
| 5635 | try { |
| 5636 | if (DBG) log("getPreferredNetworkType"); |
| 5637 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5638 | int networkType = (result != null ? result[0] : -1); |
| 5639 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5640 | return networkType; |
| 5641 | } finally { |
| 5642 | Binder.restoreCallingIdentity(identity); |
| 5643 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5644 | } |
| 5645 | |
| 5646 | /** |
| 5647 | * Set the preferred network type. |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5648 | * |
| 5649 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5650 | * @return true on success; false on any failure. |
| 5651 | */ |
| 5652 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5653 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5654 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5655 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5656 | |
| 5657 | final long identity = Binder.clearCallingIdentity(); |
| 5658 | try { |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5659 | Settings.Global.putInt(mApp.getContentResolver(), |
| 5660 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5661 | |
| 5662 | Boolean success = (Boolean) sendRequest( |
| 5663 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 5664 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 5665 | return success; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5666 | } finally { |
| 5667 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5668 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5669 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5670 | |
| 5671 | /** |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5672 | * Get the allowed network types that store in the telephony provider. |
| 5673 | * |
| 5674 | * @param subId the id of the subscription. |
| 5675 | * @return allowedNetworkTypes the allowed network types. |
| 5676 | */ |
| 5677 | @Override |
| 5678 | public long getAllowedNetworkTypes(int subId) { |
| 5679 | TelephonyPermissions |
| 5680 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5681 | mApp, subId, "getAllowedNetworkTypes"); |
| 5682 | |
| 5683 | final long identity = Binder.clearCallingIdentity(); |
| 5684 | try { |
| 5685 | return SubscriptionManager.getLongSubscriptionProperty( |
| 5686 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5687 | } finally { |
| 5688 | Binder.restoreCallingIdentity(identity); |
| 5689 | } |
| 5690 | } |
| 5691 | |
| 5692 | /** |
| 5693 | * Set the allowed network types. |
| 5694 | * |
| 5695 | * @param subId the id of the subscription. |
| 5696 | * @param allowedNetworkTypes the allowed network types. |
| 5697 | * @return true on success; false on any failure. |
| 5698 | */ |
| 5699 | @Override |
| 5700 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 5701 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5702 | mApp, subId, "setAllowedNetworkTypes"); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5703 | |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5704 | SubscriptionManager.setSubscriptionProperty(subId, |
| 5705 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 5706 | String.valueOf(allowedNetworkTypes)); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5707 | |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5708 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 5709 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5710 | RILConstants.PREFERRED_NETWORK_MODE); |
| 5711 | return setPreferredNetworkType(subId, preferredNetworkMode); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5712 | } |
| 5713 | |
| 5714 | /** |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 5715 | * Get the allowed network types for certain reason. |
| 5716 | * |
| 5717 | * @param subId the id of the subscription. |
| 5718 | * @param reason the reason the allowed network type change is taking place |
| 5719 | * @return the allowed network types. |
| 5720 | */ |
| 5721 | @Override |
| 5722 | public long getAllowedNetworkTypesForReason(int subId, |
| 5723 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
| 5724 | TelephonyPermissions |
| 5725 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5726 | mApp, subId, "getAllowedNetworkTypesForReason"); |
| 5727 | final long identity = Binder.clearCallingIdentity(); |
| 5728 | try { |
| 5729 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 5730 | } finally { |
| 5731 | Binder.restoreCallingIdentity(identity); |
| 5732 | } |
| 5733 | } |
| 5734 | |
| 5735 | /** |
| 5736 | * Get the effective allowed network types on the device. |
| 5737 | * This API will return an intersection of allowed network types for all reasons, |
| 5738 | * including the configuration done through setAllowedNetworkTypes |
| 5739 | * |
| 5740 | * @param subId the id of the subscription. |
| 5741 | * @return the allowed network types |
| 5742 | */ |
| 5743 | @Override |
| 5744 | public long getEffectiveAllowedNetworkTypes(int subId) { |
| 5745 | TelephonyPermissions |
| 5746 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5747 | mApp, subId, "getEffectiveAllowedNetworkTypes"); |
| 5748 | final long identity = Binder.clearCallingIdentity(); |
| 5749 | try { |
| 5750 | return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes(); |
| 5751 | } finally { |
| 5752 | Binder.restoreCallingIdentity(identity); |
| 5753 | } |
| 5754 | } |
| 5755 | |
| 5756 | /** |
| 5757 | * Set the allowed network types of the device and |
| 5758 | * provide the reason triggering the allowed network change. |
| 5759 | * |
| 5760 | * @param subId the id of the subscription. |
| 5761 | * @param reason the reason the allowed network type change is taking place |
| 5762 | * @param allowedNetworkTypes the allowed network types. |
| 5763 | * @return true on success; false on any failure. |
| 5764 | */ |
| 5765 | @Override |
| 5766 | public boolean setAllowedNetworkTypesForReason(int subId, |
| 5767 | @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) { |
| 5768 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5769 | mApp, subId, "setAllowedNetworkTypesForReason"); |
| 5770 | final long identity = Binder.clearCallingIdentity(); |
| 5771 | try { |
| 5772 | getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes); |
| 5773 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 5774 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5775 | RILConstants.PREFERRED_NETWORK_MODE); |
| 5776 | return setPreferredNetworkType(subId, preferredNetworkMode); |
| 5777 | } finally { |
| 5778 | Binder.restoreCallingIdentity(identity); |
| 5779 | } |
| 5780 | } |
| 5781 | |
| 5782 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5783 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5784 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5785 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 5786 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5787 | * @hide |
| 5788 | */ |
| 5789 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 5790 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5791 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5792 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5793 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5794 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5795 | if (phone != null) { |
| 5796 | return phone.hasMatchedTetherApnSetting(); |
| 5797 | } else { |
| 5798 | return false; |
| 5799 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5800 | } finally { |
| 5801 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5802 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5803 | } |
| 5804 | |
| 5805 | /** |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 5806 | * Enable or disable always reporting signal strength changes from radio. |
| 5807 | * |
| 5808 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 5809 | */ |
| 5810 | @Override |
| 5811 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 5812 | enforceModifyPermission(); |
| 5813 | enforceSystemCaller(); |
| 5814 | |
| 5815 | final long identity = Binder.clearCallingIdentity(); |
| 5816 | final Phone phone = getPhone(subId); |
| 5817 | try { |
| 5818 | if (phone != null) { |
| 5819 | if (DBG) { |
| 5820 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 5821 | + " isEnable=" + isEnable); |
| 5822 | } |
| 5823 | phone.setAlwaysReportSignalStrength(isEnable); |
| 5824 | } else { |
| 5825 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 5826 | + subId); |
| 5827 | } |
| 5828 | } finally { |
| 5829 | Binder.restoreCallingIdentity(identity); |
| 5830 | } |
| 5831 | } |
| 5832 | |
| 5833 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5834 | * Get the user enabled state of Mobile Data. |
| 5835 | * |
| 5836 | * TODO: remove and use isUserDataEnabled. |
| 5837 | * This can't be removed now because some vendor codes |
| 5838 | * calls through ITelephony directly while they should |
| 5839 | * use TelephonyManager. |
| 5840 | * |
| 5841 | * @return true on enabled |
| 5842 | */ |
| 5843 | @Override |
| 5844 | public boolean getDataEnabled(int subId) { |
| 5845 | return isUserDataEnabled(subId); |
| 5846 | } |
| 5847 | |
| 5848 | /** |
| 5849 | * Get whether mobile data is enabled per user setting. |
| 5850 | * |
| 5851 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 5852 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5853 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 5854 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5855 | * |
| 5856 | * @return {@code true} if data is enabled else {@code false} |
| 5857 | */ |
| 5858 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5859 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5860 | try { |
| 5861 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 5862 | null); |
| 5863 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5864 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5865 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5866 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5867 | |
| 5868 | final long identity = Binder.clearCallingIdentity(); |
| 5869 | try { |
| 5870 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5871 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5872 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5873 | if (phone != null) { |
| 5874 | boolean retVal = phone.isUserDataEnabled(); |
| 5875 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5876 | return retVal; |
| 5877 | } else { |
| 5878 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5879 | return false; |
| 5880 | } |
| 5881 | } finally { |
| 5882 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5883 | } |
| 5884 | } |
| 5885 | |
| 5886 | /** |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5887 | * Checks if the device is capable of mobile data by considering whether whether the |
| 5888 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 5889 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5890 | * |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5891 | * @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] | 5892 | */ |
| 5893 | @Override |
| 5894 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame^] | 5895 | try { |
| 5896 | try { |
| 5897 | mApp.enforceCallingOrSelfPermission( |
| 5898 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 5899 | null); |
| 5900 | } catch (Exception e) { |
| 5901 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 5902 | "isDataEnabled"); |
| 5903 | } |
| 5904 | } catch (Exception e) { |
| 5905 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 5906 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5907 | |
| 5908 | final long identity = Binder.clearCallingIdentity(); |
| 5909 | try { |
| 5910 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5911 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5912 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5913 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5914 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5915 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5916 | return retVal; |
| 5917 | } else { |
| 5918 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5919 | return false; |
| 5920 | } |
| 5921 | } finally { |
| 5922 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5923 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5924 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5925 | |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 5926 | /** |
| 5927 | * Check if data is enabled for a specific reason |
| 5928 | * @param subId Subscription index |
| 5929 | * @param reason the reason the data enable change is taking place |
| 5930 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 5931 | */ |
| 5932 | @Override |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame^] | 5933 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 5934 | @TelephonyManager.DataEnabledReason int reason) { |
| 5935 | try { |
| 5936 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 5937 | null); |
| 5938 | } catch (Exception e) { |
| 5939 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame^] | 5940 | "isDataEnabledForReason"); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 5941 | } |
| 5942 | |
| 5943 | |
| 5944 | final long identity = Binder.clearCallingIdentity(); |
| 5945 | try { |
| 5946 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5947 | if (DBG) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame^] | 5948 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 5949 | + " reason=" + reason); |
| 5950 | } |
| 5951 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5952 | if (phone != null) { |
| 5953 | boolean retVal; |
| 5954 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 5955 | retVal = phone.isUserDataEnabled(); |
| 5956 | } else { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame^] | 5957 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 5958 | } |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame^] | 5959 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 5960 | return retVal; |
| 5961 | } else { |
| 5962 | if (DBG) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame^] | 5963 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 5964 | + subId + " retVal=false"); |
| 5965 | } |
| 5966 | return false; |
| 5967 | } |
| 5968 | } finally { |
| 5969 | Binder.restoreCallingIdentity(identity); |
| 5970 | } |
| 5971 | } |
| 5972 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 5973 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5974 | Phone phone) { |
Hall Liu | ce478d2 | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 5975 | if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) { |
| 5976 | // Skip the check if it's one of these special uids |
| 5977 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5978 | } |
| 5979 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5980 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5981 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5982 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5983 | || subController == null) return privilegeFromSim; |
| 5984 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5985 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 5986 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 5987 | |
| 5988 | final long identity = Binder.clearCallingIdentity(); |
| 5989 | try { |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 5990 | int subId = phone.getSubId(); |
| 5991 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 5992 | // A test override is in place for the privileges for this subId, so don't try to |
| 5993 | // read the subscription privileges. |
| 5994 | return privilegeFromSim; |
| 5995 | } |
| 5996 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5997 | SubscriptionManager subManager = (SubscriptionManager) |
| 5998 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5999 | for (String pkg : packages) { |
| 6000 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6001 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6002 | } |
| 6003 | } |
| 6004 | return privilegeFromSim; |
| 6005 | } finally { |
| 6006 | Binder.restoreCallingIdentity(identity); |
| 6007 | } |
| 6008 | } |
| 6009 | |
| 6010 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6011 | String pkgName) { |
| 6012 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6013 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6014 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6015 | || subController == null) return privilegeFromSim; |
| 6016 | |
| 6017 | final long identity = Binder.clearCallingIdentity(); |
| 6018 | try { |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6019 | int subId = phone.getSubId(); |
| 6020 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6021 | // A test override is in place for the privileges for this subId, so don't try to |
| 6022 | // read the subscription privileges. |
| 6023 | return privilegeFromSim; |
| 6024 | } |
| 6025 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6026 | SubscriptionManager subManager = (SubscriptionManager) |
| 6027 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6028 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6029 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6030 | } finally { |
| 6031 | Binder.restoreCallingIdentity(identity); |
| 6032 | } |
| 6033 | } |
| 6034 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6035 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6036 | public int getCarrierPrivilegeStatus(int subId) { |
| 6037 | final Phone phone = getPhone(subId); |
| 6038 | if (phone == null) { |
| 6039 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6040 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6041 | } |
| 6042 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6043 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6044 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6045 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6046 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6047 | |
| 6048 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6049 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6050 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6051 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6052 | |
| 6053 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6054 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6055 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6056 | final Phone phone = getPhone(subId); |
| 6057 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6058 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6059 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6060 | } |
| 6061 | UiccProfile profile = |
| 6062 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6063 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6064 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6065 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6066 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6067 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6068 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6069 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6070 | } |
| 6071 | |
| 6072 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6073 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 6074 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6075 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6076 | } |
| 6077 | |
| 6078 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 6079 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6080 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6081 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6082 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6083 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6084 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6085 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6086 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6087 | } |
| 6088 | |
| 6089 | @Override |
| 6090 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6091 | if (TextUtils.isEmpty(pkgName)) |
| 6092 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6093 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6094 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6095 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 6096 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6097 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6098 | continue; |
| 6099 | } |
| 6100 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6101 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6102 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6103 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6104 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6105 | break; |
| 6106 | } |
| 6107 | } |
| 6108 | |
| 6109 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6110 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6111 | |
| 6112 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6113 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 6114 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6115 | loge("phoneId " + phoneId + " is not valid."); |
| 6116 | return null; |
| 6117 | } |
| 6118 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6119 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6120 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6121 | return null ; |
| 6122 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6123 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6124 | } |
| 6125 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6126 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6127 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6128 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6129 | List<String> privilegedPackages = new ArrayList<>(); |
| 6130 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6131 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 6132 | // has UICC in that slot. |
| 6133 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6134 | if (card.hasCarrierPrivilegeRules()) { |
| 6135 | if (packages == null) { |
| 6136 | // Only check packages in user 0 for now |
| 6137 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6138 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6139 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6140 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6141 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6142 | } |
| 6143 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6144 | PackageInfo pkgInfo = packages.get(p); |
| 6145 | if (pkgInfo != null && pkgInfo.packageName != null |
| 6146 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6147 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6148 | privilegedPackages.add(pkgInfo.packageName); |
| 6149 | } |
| 6150 | } |
| 6151 | } |
| 6152 | } |
| 6153 | return privilegedPackages; |
| 6154 | } |
| 6155 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6156 | @Override |
| 6157 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6158 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6159 | |
| 6160 | final long identity = Binder.clearCallingIdentity(); |
| 6161 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6162 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6163 | try { |
| 6164 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6165 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6166 | } |
| 6167 | } finally { |
| 6168 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6169 | } |
| 6170 | return privilegedPackages; |
| 6171 | } |
| 6172 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6173 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6174 | final Phone phone = getPhone(subId); |
| 6175 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6176 | if (card == null) { |
| 6177 | loge("getIccId: No UICC"); |
| 6178 | return null; |
| 6179 | } |
| 6180 | String iccId = card.getIccId(); |
| 6181 | if (TextUtils.isEmpty(iccId)) { |
| 6182 | loge("getIccId: ICC ID is null or empty."); |
| 6183 | return null; |
| 6184 | } |
| 6185 | return iccId; |
| 6186 | } |
| 6187 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6188 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6189 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6190 | String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6191 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6192 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6193 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6194 | final long identity = Binder.clearCallingIdentity(); |
| 6195 | try { |
| 6196 | final String iccId = getIccId(subId); |
| 6197 | final Phone phone = getPhone(subId); |
| 6198 | if (phone == null) { |
| 6199 | return false; |
| 6200 | } |
| 6201 | final String subscriberId = phone.getSubscriberId(); |
| 6202 | |
| 6203 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6204 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6205 | + subscriberId + " to " + number); |
| 6206 | } |
| 6207 | |
| 6208 | if (TextUtils.isEmpty(iccId)) { |
| 6209 | return false; |
| 6210 | } |
| 6211 | |
| 6212 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6213 | |
| 6214 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6215 | if (alphaTag == null) { |
| 6216 | editor.remove(alphaTagPrefKey); |
| 6217 | } else { |
| 6218 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6219 | } |
| 6220 | |
| 6221 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6222 | // track all merged IMSIs based on line number |
| 6223 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6224 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6225 | if (number == null) { |
| 6226 | editor.remove(numberPrefKey); |
| 6227 | editor.remove(subscriberPrefKey); |
| 6228 | } else { |
| 6229 | editor.putString(numberPrefKey, number); |
| 6230 | editor.putString(subscriberPrefKey, subscriberId); |
| 6231 | } |
| 6232 | |
| 6233 | editor.commit(); |
| 6234 | return true; |
| 6235 | } finally { |
| 6236 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6237 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6238 | } |
| 6239 | |
| 6240 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6241 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6242 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6243 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6244 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6245 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6246 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6247 | return null; |
| 6248 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6249 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6250 | final long identity = Binder.clearCallingIdentity(); |
| 6251 | try { |
| 6252 | String iccId = getIccId(subId); |
| 6253 | if (iccId != null) { |
| 6254 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6255 | if (DBG_MERGE) { |
| 6256 | log("getLine1NumberForDisplay returning " |
| 6257 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6258 | } |
| 6259 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6260 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6261 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6262 | return null; |
| 6263 | } finally { |
| 6264 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6265 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6266 | } |
| 6267 | |
| 6268 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6269 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6270 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6271 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6272 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6273 | return null; |
| 6274 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6275 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6276 | final long identity = Binder.clearCallingIdentity(); |
| 6277 | try { |
| 6278 | String iccId = getIccId(subId); |
| 6279 | if (iccId != null) { |
| 6280 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6281 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6282 | } |
| 6283 | return null; |
| 6284 | } finally { |
| 6285 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6286 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6287 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6288 | |
| 6289 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6290 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6291 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6292 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6293 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6294 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6295 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6296 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6297 | return null; |
| 6298 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6299 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6300 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6301 | // the process, where TelephonyManager was instantiated. |
| 6302 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6303 | final long identity = Binder.clearCallingIdentity(); |
| 6304 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6305 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6306 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6307 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6308 | |
| 6309 | // Figure out what subscribers are currently active |
| 6310 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6311 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6312 | // Only consider subs which match the current subId |
| 6313 | // This logic can be simplified. See b/131189269 for progress. |
| 6314 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6315 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6316 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6317 | |
| 6318 | // First pass, find a number override for an active subscriber |
| 6319 | String mergeNumber = null; |
| 6320 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6321 | for (String key : prefs.keySet()) { |
| 6322 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6323 | final String subscriberId = (String) prefs.get(key); |
| 6324 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6325 | final String iccId = key.substring( |
| 6326 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6327 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6328 | mergeNumber = (String) prefs.get(numberKey); |
| 6329 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6330 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6331 | + " for active subscriber " + subscriberId); |
| 6332 | } |
| 6333 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6334 | break; |
| 6335 | } |
| 6336 | } |
| 6337 | } |
| 6338 | } |
| 6339 | |
| 6340 | // Shortcut when no active merged subscribers |
| 6341 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6342 | return null; |
| 6343 | } |
| 6344 | |
| 6345 | // Second pass, find all subscribers under that line override |
| 6346 | final ArraySet<String> result = new ArraySet<>(); |
| 6347 | for (String key : prefs.keySet()) { |
| 6348 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6349 | final String number = (String) prefs.get(key); |
| 6350 | if (mergeNumber.equals(number)) { |
| 6351 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6352 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6353 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6354 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6355 | result.add(subscriberId); |
| 6356 | } |
| 6357 | } |
| 6358 | } |
| 6359 | } |
| 6360 | |
| 6361 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6362 | Arrays.sort(resultArray); |
| 6363 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6364 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6365 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6366 | } |
| 6367 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6368 | } finally { |
| 6369 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6370 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6371 | } |
| 6372 | |
| 6373 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6374 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6375 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6376 | |
| 6377 | final long identity = Binder.clearCallingIdentity(); |
| 6378 | try { |
| 6379 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6380 | TelephonyManager.class); |
| 6381 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6382 | if (subscriberId == null) { |
| 6383 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6384 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6385 | + subId); |
| 6386 | } |
| 6387 | return null; |
| 6388 | } |
| 6389 | |
| 6390 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6391 | .getSubscriptionInfo(subId); |
| 6392 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6393 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6394 | if (groupUuid == null) { |
| 6395 | return new String[]{subscriberId}; |
| 6396 | } |
| 6397 | |
| 6398 | // Get all subscriberIds from the group. |
| 6399 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6400 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6401 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6402 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6403 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6404 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6405 | if (subscriberId != null) { |
| 6406 | mergedSubscriberIds.add(subscriberId); |
| 6407 | } |
| 6408 | } |
| 6409 | |
| 6410 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6411 | } finally { |
| 6412 | Binder.restoreCallingIdentity(identity); |
| 6413 | |
| 6414 | } |
| 6415 | } |
| 6416 | |
| 6417 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6418 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6419 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6420 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6421 | |
| 6422 | final long identity = Binder.clearCallingIdentity(); |
| 6423 | try { |
| 6424 | final Phone phone = getPhone(subId); |
| 6425 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6426 | } finally { |
| 6427 | Binder.restoreCallingIdentity(identity); |
| 6428 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6429 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6430 | |
| 6431 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6432 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6433 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6434 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6435 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6436 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6437 | |
| 6438 | final long identity = Binder.clearCallingIdentity(); |
| 6439 | try { |
| 6440 | final Phone phone = getPhone(subId); |
| 6441 | if (phone == null) { |
| 6442 | return false; |
| 6443 | } |
| 6444 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6445 | cdmaNonRoamingList); |
| 6446 | } finally { |
| 6447 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6448 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6449 | } |
| 6450 | |
| 6451 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6452 | @Deprecated |
| 6453 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6454 | enforceModifyPermission(); |
| 6455 | |
| 6456 | int returnValue = 0; |
| 6457 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6458 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6459 | if(result.exception == null) { |
| 6460 | if (result.result != null) { |
| 6461 | byte[] responseData = (byte[])(result.result); |
| 6462 | if(responseData.length > oemResp.length) { |
| 6463 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6464 | responseData.length + "bytes. Buffer Size is " + |
| 6465 | oemResp.length + "bytes."); |
| 6466 | } |
| 6467 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6468 | returnValue = responseData.length; |
| 6469 | } |
| 6470 | } else { |
| 6471 | CommandException ex = (CommandException) result.exception; |
| 6472 | returnValue = ex.getCommandError().ordinal(); |
| 6473 | if(returnValue > 0) returnValue *= -1; |
| 6474 | } |
| 6475 | } catch (RuntimeException e) { |
| 6476 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6477 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6478 | if(returnValue > 0) returnValue *= -1; |
| 6479 | } |
| 6480 | |
| 6481 | return returnValue; |
| 6482 | } |
| 6483 | |
| 6484 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6485 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6486 | try { |
| 6487 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6488 | } catch (RuntimeException e) { |
| 6489 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6490 | } |
| 6491 | } |
| 6492 | |
| 6493 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6494 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6495 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6496 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6497 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6498 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6499 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6500 | final long identity = Binder.clearCallingIdentity(); |
| 6501 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6502 | TelephonyPermissions |
| 6503 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6504 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6505 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6506 | } finally { |
| 6507 | Binder.restoreCallingIdentity(identity); |
| 6508 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6509 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6510 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6511 | |
| 6512 | @Override |
| 6513 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6514 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6515 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6516 | |
| 6517 | final long identity = Binder.clearCallingIdentity(); |
| 6518 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6519 | ImsManager.getInstance(defaultPhone.getContext(), |
| 6520 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6521 | } finally { |
| 6522 | Binder.restoreCallingIdentity(identity); |
| 6523 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6524 | } |
| 6525 | |
| 6526 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6527 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6528 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6529 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 6530 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6531 | return false; |
| 6532 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6533 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6534 | final long identity = Binder.clearCallingIdentity(); |
| 6535 | try { |
| 6536 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 6537 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 6538 | // In the long run, we may instead need to check if there exists a connection service |
| 6539 | // which can support video calling. |
| 6540 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6541 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6542 | return imsManager.isVtEnabledByPlatform() |
| 6543 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 6544 | && imsManager.isVtEnabledByUser(); |
| 6545 | } finally { |
| 6546 | Binder.restoreCallingIdentity(identity); |
| 6547 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6548 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 6549 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6550 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6551 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 6552 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6553 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6554 | mApp, subId, callingPackage, callingFeatureId, |
| 6555 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6556 | return false; |
| 6557 | } |
| 6558 | |
| 6559 | final long identity = Binder.clearCallingIdentity(); |
| 6560 | try { |
| 6561 | CarrierConfigManager configManager = |
| 6562 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6563 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6564 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 6565 | } finally { |
| 6566 | Binder.restoreCallingIdentity(identity); |
| 6567 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6568 | } |
| 6569 | |
| 6570 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6571 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6572 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6573 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6574 | return false; |
| 6575 | } |
| 6576 | |
| 6577 | final long identity = Binder.clearCallingIdentity(); |
| 6578 | try { |
| 6579 | CarrierConfigManager configManager = |
| 6580 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6581 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6582 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 6583 | } finally { |
| 6584 | Binder.restoreCallingIdentity(identity); |
| 6585 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6586 | } |
| 6587 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6588 | @Override |
| 6589 | public boolean isTtyModeSupported() { |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6590 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 6591 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6592 | } |
| 6593 | |
| 6594 | @Override |
| 6595 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6596 | final long identity = Binder.clearCallingIdentity(); |
| 6597 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6598 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6599 | } finally { |
| 6600 | Binder.restoreCallingIdentity(identity); |
| 6601 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6602 | } |
| 6603 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6604 | /** |
| 6605 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 6606 | * support for the feature and device firmware support. |
| 6607 | * |
| 6608 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 6609 | */ |
| 6610 | @Override |
| 6611 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6612 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6613 | final Phone phone = getPhone(subscriptionId); |
| 6614 | if (phone == null) { |
| 6615 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 6616 | return false; |
| 6617 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6618 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6619 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6620 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 6621 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6622 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6623 | return isCarrierSupported && isDeviceSupported; |
| 6624 | } finally { |
| 6625 | Binder.restoreCallingIdentity(identity); |
| 6626 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 6627 | } |
| 6628 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6629 | /** |
Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 6630 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 6631 | * RTT setting, will return true if the device and carrier both support RTT. |
| 6632 | * 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] | 6633 | */ |
| 6634 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6635 | final long identity = Binder.clearCallingIdentity(); |
| 6636 | try { |
Hall Liu | 63767ec | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 6637 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 6638 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 6639 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 6640 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 6641 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 6642 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6643 | } finally { |
| 6644 | Binder.restoreCallingIdentity(identity); |
| 6645 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 6646 | } |
| 6647 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6648 | @Deprecated |
| 6649 | @Override |
| 6650 | public String getDeviceId(String callingPackage) { |
| 6651 | return getDeviceIdWithFeature(callingPackage, null); |
| 6652 | } |
| 6653 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6654 | /** |
| 6655 | * Returns the unique device ID of phone, for example, the IMEI for |
| 6656 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 6657 | * |
| 6658 | * <p>Requires Permission: |
| 6659 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 6660 | */ |
| 6661 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6662 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6663 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6664 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6665 | return null; |
| 6666 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6667 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 6668 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6669 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6670 | return null; |
| 6671 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6672 | |
| 6673 | final long identity = Binder.clearCallingIdentity(); |
| 6674 | try { |
| 6675 | return phone.getDeviceId(); |
| 6676 | } finally { |
| 6677 | Binder.restoreCallingIdentity(identity); |
| 6678 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6679 | } |
| 6680 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6681 | /** |
| 6682 | * {@hide} |
| 6683 | * Returns the IMS Registration Status on a particular subid |
| 6684 | * |
| 6685 | * @param subId |
| 6686 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6687 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6688 | Phone phone = getPhone(subId); |
| 6689 | if (phone != null) { |
| 6690 | return phone.isImsRegistered(); |
| 6691 | } else { |
| 6692 | return false; |
| 6693 | } |
| 6694 | } |
| 6695 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6696 | @Override |
| 6697 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6698 | final long identity = Binder.clearCallingIdentity(); |
| 6699 | try { |
| 6700 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 6701 | } finally { |
| 6702 | Binder.restoreCallingIdentity(identity); |
| 6703 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6704 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 6705 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6706 | @Override |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6707 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6708 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6709 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6710 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6711 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6712 | } |
| 6713 | final long identity = Binder.clearCallingIdentity(); |
| 6714 | try { |
| 6715 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 6716 | } finally { |
| 6717 | Binder.restoreCallingIdentity(identity); |
| 6718 | } |
| 6719 | } |
| 6720 | |
| 6721 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6722 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
duki.hong | fd96bde | 2020-07-22 17:32:19 +0900 | [diff] [blame] | 6723 | enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, " |
| 6724 | + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6725 | final long identity = Binder.clearCallingIdentity(); |
| 6726 | try { |
| 6727 | Phone phone = getPhone(subscriptionId); |
| 6728 | if (phone == null) { |
| 6729 | return null; |
| 6730 | } |
| 6731 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 6732 | } finally { |
| 6733 | Binder.restoreCallingIdentity(identity); |
| 6734 | } |
| 6735 | } |
| 6736 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6737 | /** |
| 6738 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6739 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6740 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6741 | final long identity = Binder.clearCallingIdentity(); |
| 6742 | try { |
| 6743 | Phone phone = getPhone(subId); |
| 6744 | if (phone != null) { |
| 6745 | return phone.isWifiCallingEnabled(); |
| 6746 | } else { |
| 6747 | return false; |
| 6748 | } |
| 6749 | } finally { |
| 6750 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6751 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6752 | } |
| 6753 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6754 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6755 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6756 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6757 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6758 | final long identity = Binder.clearCallingIdentity(); |
| 6759 | try { |
| 6760 | Phone phone = getPhone(subId); |
| 6761 | if (phone != null) { |
| 6762 | return phone.isVideoEnabled(); |
| 6763 | } else { |
| 6764 | return false; |
| 6765 | } |
| 6766 | } finally { |
| 6767 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6768 | } |
| 6769 | } |
| 6770 | |
| 6771 | /** |
| 6772 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 6773 | * defined in {@link ImsRegistrationImplBase}. |
| 6774 | */ |
| 6775 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6776 | final long identity = Binder.clearCallingIdentity(); |
| 6777 | try { |
| 6778 | Phone phone = getPhone(subId); |
| 6779 | if (phone != null) { |
| 6780 | return phone.getImsRegistrationTech(); |
| 6781 | } else { |
| 6782 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 6783 | } |
| 6784 | } finally { |
| 6785 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6786 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6787 | } |
| 6788 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6789 | @Override |
| 6790 | public void factoryReset(int subId) { |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 6791 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6792 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 6793 | return; |
| 6794 | } |
| 6795 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6796 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6797 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6798 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6799 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 6800 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame^] | 6801 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6802 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6803 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6804 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6805 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 6806 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6807 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6808 | // There has been issues when Sms raw table somehow stores orphan |
| 6809 | // fragments. They lead to garbled message when new fragments come |
| 6810 | // in and combined with those stale ones. In case this happens again, |
| 6811 | // user can reset all network settings which will clean up this table. |
| 6812 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6813 | // Clean up IMS settings as well here. |
| 6814 | int slotId = getSlotIndex(subId); |
| 6815 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6816 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 6817 | } |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 6818 | |
| 6819 | // Erase modem config if erase modem on network setting is enabled. |
| 6820 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 6821 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 6822 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 6823 | sendEraseModemConfig(getDefaultPhone()); |
| 6824 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6825 | } finally { |
| 6826 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6827 | } |
| 6828 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6829 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6830 | private void cleanUpSmsRawTable(Context context) { |
| 6831 | ContentResolver resolver = context.getContentResolver(); |
| 6832 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 6833 | resolver.delete(uri, null, null); |
| 6834 | } |
| 6835 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6836 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6837 | public String getSimLocaleForSubscriber(int subId) { |
| 6838 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 6839 | final Phone phone = getPhone(subId); |
| 6840 | if (phone == null) { |
| 6841 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 6842 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6843 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6844 | final long identity = Binder.clearCallingIdentity(); |
| 6845 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6846 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6847 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 6848 | if (info == null) { |
| 6849 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 6850 | return null; |
| 6851 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6852 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 6853 | // preferences (EF-PL and EF-LI)... |
| 6854 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6855 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6856 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 6857 | if (localeFromDefaultSim != null) { |
| 6858 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 6859 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 6860 | + localeFromDefaultSim); |
| 6861 | return localeFromDefaultSim.toLanguageTag(); |
| 6862 | } else { |
| 6863 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6864 | } |
| 6865 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6866 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6867 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 6868 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 6869 | // the SIM and carrier preferences does not include a country we add the country |
| 6870 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 6871 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6872 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6873 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6874 | return mccLocale.toLanguageTag(); |
| 6875 | } |
| 6876 | |
| 6877 | if (DBG) log("No locale found - returning null"); |
| 6878 | return null; |
| 6879 | } finally { |
| 6880 | Binder.restoreCallingIdentity(identity); |
| 6881 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6882 | } |
| 6883 | |
| 6884 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6885 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6886 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6887 | } |
| 6888 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6889 | /** |
| 6890 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 6891 | */ |
| 6892 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6893 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6894 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6895 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6896 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6897 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6898 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6899 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6900 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6901 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 6902 | * representing the state of the modem. |
| 6903 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6904 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 6905 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6906 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6907 | */ |
| 6908 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6909 | public void requestModemActivityInfo(ResultReceiver result) { |
| 6910 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6911 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6912 | |
| 6913 | final long identity = Binder.clearCallingIdentity(); |
| 6914 | try { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 6915 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6916 | } finally { |
| 6917 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6918 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6919 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6920 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6921 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 6922 | // less than total activity duration. |
| 6923 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 6924 | if (info == null) { |
| 6925 | return false; |
| 6926 | } |
| 6927 | int activityDurationMs = |
| 6928 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 6929 | int totalTxTimeMs = 0; |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6930 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6931 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 6932 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6933 | } |
| 6934 | return (info.isValid() |
| 6935 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 6936 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6937 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6938 | && (totalTxTimeMs <= activityDurationMs)); |
| 6939 | } |
| 6940 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6941 | /** |
| 6942 | * {@hide} |
| 6943 | * Returns the service state information on specified subscription. |
| 6944 | */ |
| 6945 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6946 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 6947 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6948 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6949 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6950 | return null; |
| 6951 | } |
| 6952 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6953 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 6954 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6955 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6956 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6957 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6958 | .setCallingPid(Binder.getCallingPid()) |
| 6959 | .setCallingUid(Binder.getCallingUid()) |
| 6960 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6961 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6962 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6963 | .build()); |
| 6964 | |
| 6965 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 6966 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6967 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6968 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6969 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6970 | .setCallingPid(Binder.getCallingPid()) |
| 6971 | .setCallingUid(Binder.getCallingUid()) |
| 6972 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6973 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6974 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6975 | .build()); |
| 6976 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 6977 | boolean hasFinePermission = |
| 6978 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6979 | boolean hasCoarsePermission = |
| 6980 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6981 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6982 | final long identity = Binder.clearCallingIdentity(); |
| 6983 | try { |
| 6984 | final Phone phone = getPhone(subId); |
| 6985 | if (phone == null) { |
| 6986 | return null; |
| 6987 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6988 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6989 | ServiceState ss = phone.getServiceState(); |
| 6990 | |
| 6991 | // Scrub out the location info in ServiceState depending on what level of access |
| 6992 | // the caller has. |
| 6993 | if (hasFinePermission) return ss; |
Malcolm Chen | db33797 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 6994 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 6995 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6996 | } finally { |
| 6997 | Binder.restoreCallingIdentity(identity); |
| 6998 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6999 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7000 | |
| 7001 | /** |
| 7002 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7003 | * |
| 7004 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7005 | * voicemail ringtone. |
| 7006 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7007 | * PhoneAccount. |
| 7008 | */ |
| 7009 | @Override |
| 7010 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7011 | final long identity = Binder.clearCallingIdentity(); |
| 7012 | try { |
| 7013 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7014 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7015 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7016 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7017 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7018 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7019 | } finally { |
| 7020 | Binder.restoreCallingIdentity(identity); |
| 7021 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7022 | } |
| 7023 | |
| 7024 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7025 | * Sets the per-account voicemail ringtone. |
| 7026 | * |
| 7027 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7028 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7029 | * |
| 7030 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7031 | * voicemail ringtone. |
| 7032 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7033 | * PhoneAccount. |
| 7034 | */ |
| 7035 | @Override |
| 7036 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7037 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7038 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7039 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7040 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7041 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7042 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7043 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7044 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7045 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7046 | |
| 7047 | final long identity = Binder.clearCallingIdentity(); |
| 7048 | try { |
| 7049 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7050 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7051 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7052 | } |
| 7053 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7054 | } finally { |
| 7055 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7056 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7057 | } |
| 7058 | |
| 7059 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7060 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7061 | * |
| 7062 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7063 | * voicemail vibration setting. |
| 7064 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7065 | */ |
| 7066 | @Override |
| 7067 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7068 | final long identity = Binder.clearCallingIdentity(); |
| 7069 | try { |
| 7070 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7071 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7072 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7073 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7074 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7075 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7076 | } finally { |
| 7077 | Binder.restoreCallingIdentity(identity); |
| 7078 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7079 | } |
| 7080 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7081 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7082 | * Sets the per-account voicemail vibration. |
| 7083 | * |
| 7084 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7085 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7086 | * |
| 7087 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7088 | * voicemail vibration setting. |
| 7089 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7090 | * specific PhoneAccount. |
| 7091 | */ |
| 7092 | @Override |
| 7093 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7094 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7095 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7096 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7097 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7098 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7099 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7100 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7101 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7102 | } |
| 7103 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7104 | final long identity = Binder.clearCallingIdentity(); |
| 7105 | try { |
| 7106 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7107 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7108 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7109 | } |
| 7110 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7111 | } finally { |
| 7112 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7113 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7114 | } |
| 7115 | |
| 7116 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7117 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 7118 | * |
| 7119 | * @throws SecurityException if the caller does not have the required permission |
| 7120 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7121 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7122 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7123 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7124 | } |
| 7125 | |
| 7126 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7127 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 7128 | * permission. |
| 7129 | * |
| 7130 | * @throws SecurityException if the caller does not have the required permission |
| 7131 | */ |
| 7132 | private void enforceSendSmsPermission() { |
| 7133 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 7134 | } |
| 7135 | |
| 7136 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7137 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7138 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7139 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7140 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7141 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7142 | final long identity = Binder.clearCallingIdentity(); |
| 7143 | try { |
| 7144 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7145 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7146 | if (componentName == null) { |
| 7147 | throw new SecurityException( |
| 7148 | "Caller not current active visual voicemail package[null]"); |
| 7149 | } |
| 7150 | String vvmPackage = componentName.getPackageName(); |
| 7151 | if (!callingPackage.equals(vvmPackage)) { |
| 7152 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 7153 | + vvmPackage + "]"); |
| 7154 | } |
| 7155 | } finally { |
| 7156 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7157 | } |
| 7158 | } |
| 7159 | |
| 7160 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7161 | * Return the application ID for the app type. |
| 7162 | * |
| 7163 | * @param subId the subscription ID that this request applies to. |
| 7164 | * @param appType the uicc app type. |
| 7165 | * @return Application ID for specificied app type, or null if no uicc. |
| 7166 | */ |
| 7167 | @Override |
| 7168 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7169 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7170 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7171 | |
| 7172 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7173 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7174 | if (phone == null) { |
| 7175 | return null; |
| 7176 | } |
| 7177 | String aid = null; |
| 7178 | try { |
| 7179 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 7180 | .getApplicationByType(appType).getAid(); |
| 7181 | } catch (Exception e) { |
| 7182 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 7183 | } |
| 7184 | return aid; |
| 7185 | } finally { |
| 7186 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7187 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7188 | } |
| 7189 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7190 | /** |
| 7191 | * Return the Electronic Serial Number. |
| 7192 | * |
| 7193 | * @param subId the subscription ID that this request applies to. |
| 7194 | * @return ESN or null if error. |
| 7195 | */ |
| 7196 | @Override |
| 7197 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7198 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7199 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7200 | |
| 7201 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7202 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7203 | if (phone == null) { |
| 7204 | return null; |
| 7205 | } |
| 7206 | String esn = null; |
| 7207 | try { |
| 7208 | esn = phone.getEsn(); |
| 7209 | } catch (Exception e) { |
| 7210 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 7211 | } |
| 7212 | return esn; |
| 7213 | } finally { |
| 7214 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7215 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7216 | } |
| 7217 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7218 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7219 | * Return the Preferred Roaming List Version. |
| 7220 | * |
| 7221 | * @param subId the subscription ID that this request applies to. |
| 7222 | * @return PRLVersion or null if error. |
| 7223 | */ |
| 7224 | @Override |
| 7225 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7226 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7227 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7228 | |
| 7229 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7230 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7231 | if (phone == null) { |
| 7232 | return null; |
| 7233 | } |
| 7234 | String cdmaPrlVersion = null; |
| 7235 | try { |
| 7236 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7237 | } catch (Exception e) { |
| 7238 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7239 | } |
| 7240 | return cdmaPrlVersion; |
| 7241 | } finally { |
| 7242 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7243 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7244 | } |
| 7245 | |
| 7246 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7247 | * Get snapshot of Telephony histograms |
| 7248 | * @return List of Telephony histograms |
| 7249 | * @hide |
| 7250 | */ |
| 7251 | @Override |
| 7252 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7253 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7254 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7255 | |
| 7256 | final long identity = Binder.clearCallingIdentity(); |
| 7257 | try { |
| 7258 | return RIL.getTelephonyRILTimingHistograms(); |
| 7259 | } finally { |
| 7260 | Binder.restoreCallingIdentity(identity); |
| 7261 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7262 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7263 | |
| 7264 | /** |
| 7265 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7266 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7267 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7268 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7269 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7270 | * @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] | 7271 | */ |
| 7272 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7273 | @TelephonyManager.SetCarrierRestrictionResult |
| 7274 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7275 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7276 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7277 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7278 | if (carrierRestrictionRules == null) { |
| 7279 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7280 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7281 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7282 | final long identity = Binder.clearCallingIdentity(); |
| 7283 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7284 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7285 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7286 | } finally { |
| 7287 | Binder.restoreCallingIdentity(identity); |
| 7288 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7289 | } |
| 7290 | |
| 7291 | /** |
| 7292 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7293 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7294 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7295 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7296 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7297 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7298 | */ |
| 7299 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7300 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7301 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7302 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7303 | |
| 7304 | final long identity = Binder.clearCallingIdentity(); |
| 7305 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7306 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7307 | if (response instanceof CarrierRestrictionRules) { |
| 7308 | return (CarrierRestrictionRules) response; |
| 7309 | } |
| 7310 | // Response is an Exception of some kind, |
| 7311 | // which is signalled to the user as a NULL retval |
| 7312 | return null; |
| 7313 | } catch (Exception e) { |
| 7314 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7315 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7316 | } finally { |
| 7317 | Binder.restoreCallingIdentity(identity); |
| 7318 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7319 | } |
| 7320 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7321 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7322 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7323 | * @param subId the subscription ID that this action applies to. |
| 7324 | * @param enabled control enable or disable radio. |
| 7325 | * {@hide} |
| 7326 | */ |
| 7327 | @Override |
| 7328 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7329 | enforceModifyPermission(); |
| 7330 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7331 | |
| 7332 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7333 | if (phone == null) { |
| 7334 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7335 | return; |
| 7336 | } |
| 7337 | try { |
| 7338 | phone.carrierActionSetRadioEnabled(enabled); |
| 7339 | } catch (Exception e) { |
| 7340 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7341 | } finally { |
| 7342 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7343 | } |
| 7344 | } |
| 7345 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7346 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7347 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7348 | * network status based on which carrier apps could apply actions accordingly, |
| 7349 | * enable/disable default url handler for example. |
| 7350 | * |
| 7351 | * @param subId the subscription ID that this action applies to. |
| 7352 | * @param report control start/stop reporting the default network status. |
| 7353 | * {@hide} |
| 7354 | */ |
| 7355 | @Override |
| 7356 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7357 | enforceModifyPermission(); |
| 7358 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7359 | |
| 7360 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7361 | if (phone == null) { |
| 7362 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7363 | return; |
| 7364 | } |
| 7365 | try { |
| 7366 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7367 | } catch (Exception e) { |
| 7368 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7369 | } finally { |
| 7370 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7371 | } |
| 7372 | } |
| 7373 | |
| 7374 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7375 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7376 | * @param subId the subscription ID that this action applies to. |
| 7377 | * {@hide} |
| 7378 | */ |
| 7379 | @Override |
| 7380 | public void carrierActionResetAll(int subId) { |
| 7381 | enforceModifyPermission(); |
| 7382 | final Phone phone = getPhone(subId); |
| 7383 | if (phone == null) { |
| 7384 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7385 | return; |
| 7386 | } |
| 7387 | try { |
| 7388 | phone.carrierActionResetAll(); |
| 7389 | } catch (Exception e) { |
| 7390 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7391 | } |
| 7392 | } |
| 7393 | |
| 7394 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7395 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7396 | * bug report is being generated. |
| 7397 | */ |
| 7398 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7399 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7400 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7401 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7402 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7403 | + Binder.getCallingPid() |
| 7404 | + ", uid=" + Binder.getCallingUid() |
| 7405 | + "without permission " |
| 7406 | + android.Manifest.permission.DUMP); |
| 7407 | return; |
| 7408 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7409 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7410 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7411 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7412 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 7413 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 7414 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 7415 | @NonNull String[] args) { |
| 7416 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 7417 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 7418 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7419 | } |
| 7420 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7421 | /** |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7422 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7423 | * @param subId Subscription index |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7424 | * @param reason the reason the data enable change is taking place |
| 7425 | * @param enabled True if enabling the data, otherwise disabling. |
| 7426 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7427 | */ |
| 7428 | @Override |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame^] | 7429 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7430 | boolean enabled) { |
| 7431 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 7432 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7433 | try { |
| 7434 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame^] | 7435 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7436 | } catch (SecurityException se) { |
| 7437 | enforceModifyPermission(); |
| 7438 | } |
| 7439 | } else { |
| 7440 | enforceModifyPermission(); |
| 7441 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7442 | |
| 7443 | final long identity = Binder.clearCallingIdentity(); |
| 7444 | try { |
| 7445 | Phone phone = getPhone(subId); |
| 7446 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7447 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7448 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7449 | } else { |
| 7450 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 7451 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7452 | } |
| 7453 | } finally { |
| 7454 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7455 | } |
| 7456 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7457 | |
| 7458 | /** |
| 7459 | * Get Client request stats |
| 7460 | * @return List of Client Request Stats |
| 7461 | * @hide |
| 7462 | */ |
| 7463 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7464 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7465 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7466 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7467 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7468 | return null; |
| 7469 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7470 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7471 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7472 | final long identity = Binder.clearCallingIdentity(); |
| 7473 | try { |
| 7474 | if (phone != null) { |
| 7475 | return phone.getClientRequestStats(); |
| 7476 | } |
| 7477 | |
| 7478 | return null; |
| 7479 | } finally { |
| 7480 | Binder.restoreCallingIdentity(identity); |
| 7481 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7482 | } |
| 7483 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7484 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7485 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7486 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7487 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7488 | |
| 7489 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7490 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7491 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7492 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7493 | * @param state State of SIM (power down, power up, pass through) |
| 7494 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7495 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7496 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7497 | * |
| 7498 | **/ |
| 7499 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7500 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7501 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7502 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7503 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7504 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7505 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7506 | final long identity = Binder.clearCallingIdentity(); |
| 7507 | try { |
| 7508 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7509 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7510 | } |
| 7511 | } finally { |
| 7512 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7513 | } |
| 7514 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7515 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7516 | private boolean isUssdApiAllowed(int subId) { |
| 7517 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7518 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7519 | if (configManager == null) { |
| 7520 | return false; |
| 7521 | } |
| 7522 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 7523 | if (pb == null) { |
| 7524 | return false; |
| 7525 | } |
| 7526 | return pb.getBoolean( |
| 7527 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 7528 | } |
| 7529 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7530 | /** |
| 7531 | * Check if phone is in emergency callback mode |
| 7532 | * @return true if phone is in emergency callback mode |
| 7533 | * @param subId sub id |
| 7534 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 7535 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7536 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7537 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7538 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7539 | |
| 7540 | final long identity = Binder.clearCallingIdentity(); |
| 7541 | try { |
| 7542 | if (phone != null) { |
| 7543 | return phone.isInEcm(); |
| 7544 | } else { |
| 7545 | return false; |
| 7546 | } |
| 7547 | } finally { |
| 7548 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7549 | } |
| 7550 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7551 | |
| 7552 | /** |
| 7553 | * Get the current signal strength information for the given subscription. |
| 7554 | * Because this information is not updated when the device is in a low power state |
| 7555 | * it should not be relied-upon to be current. |
| 7556 | * @param subId Subscription index |
| 7557 | * @return the most recent cached signal strength info from the modem |
| 7558 | */ |
| 7559 | @Override |
| 7560 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7561 | final long identity = Binder.clearCallingIdentity(); |
| 7562 | try { |
| 7563 | Phone p = getPhone(subId); |
| 7564 | if (p == null) { |
| 7565 | return null; |
| 7566 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7567 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7568 | return p.getSignalStrength(); |
| 7569 | } finally { |
| 7570 | Binder.restoreCallingIdentity(identity); |
| 7571 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7572 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7573 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7574 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7575 | * Get the current modem radio state for the given slot. |
| 7576 | * @param slotIndex slot index. |
| 7577 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7578 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7579 | * @return the current radio power state from the modem |
| 7580 | */ |
| 7581 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7582 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7583 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7584 | if (phone != null) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7585 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 7586 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7587 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7588 | } |
| 7589 | |
| 7590 | final long identity = Binder.clearCallingIdentity(); |
| 7591 | try { |
| 7592 | return phone.getRadioPowerState(); |
| 7593 | } finally { |
| 7594 | Binder.restoreCallingIdentity(identity); |
| 7595 | } |
| 7596 | } |
| 7597 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7598 | } |
| 7599 | |
| 7600 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7601 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 7602 | * |
| 7603 | * <p>Requires one of the following permissions: |
| 7604 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 7605 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 7606 | * privileges. |
| 7607 | * |
| 7608 | * @param subId subscription id |
| 7609 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 7610 | * {@code false}. |
| 7611 | */ |
| 7612 | @Override |
| 7613 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 11263f3 | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 7614 | try { |
| 7615 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7616 | null); |
| 7617 | } catch (Exception e) { |
| 7618 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 7619 | mApp, subId, "isDataRoamingEnabled"); |
| 7620 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7621 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7622 | boolean isEnabled = false; |
| 7623 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7624 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7625 | Phone phone = getPhone(subId); |
| 7626 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7627 | } finally { |
| 7628 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7629 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7630 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7631 | } |
| 7632 | |
| 7633 | |
| 7634 | /** |
| 7635 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 7636 | * |
| 7637 | * <p> Requires permission: |
| 7638 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 7639 | * privileges. |
| 7640 | * |
| 7641 | * @param subId subscription id |
| 7642 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 7643 | */ |
| 7644 | @Override |
| 7645 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7646 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7647 | mApp, subId, "setDataRoamingEnabled"); |
| 7648 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7649 | final long identity = Binder.clearCallingIdentity(); |
| 7650 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7651 | Phone phone = getPhone(subId); |
| 7652 | if (phone != null) { |
| 7653 | phone.setDataRoamingEnabled(isEnabled); |
| 7654 | } |
| 7655 | } finally { |
| 7656 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7657 | } |
| 7658 | } |
| 7659 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7660 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7661 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 7662 | TelephonyPermissions |
| 7663 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7664 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 7665 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7666 | boolean isAllowed = true; |
| 7667 | final long identity = Binder.clearCallingIdentity(); |
| 7668 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7669 | Phone phone = getPhone(subId); |
| 7670 | if (phone != null) { |
| 7671 | isAllowed = phone.isCspPlmnEnabled(); |
| 7672 | } |
| 7673 | } finally { |
| 7674 | Binder.restoreCallingIdentity(identity); |
| 7675 | } |
| 7676 | return isAllowed; |
| 7677 | } |
| 7678 | |
| 7679 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7680 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | cfdfe3a | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 7681 | // Verify that tha callingPackage belongs to the calling UID |
| 7682 | mApp.getSystemService(AppOpsManager.class) |
| 7683 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 7684 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7685 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7686 | try { |
| 7687 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7688 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7689 | } catch (SecurityException e) { |
| 7690 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 7691 | // has carrier privileges on an active UICC |
| 7692 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 7693 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7694 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7695 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7696 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7697 | |
| 7698 | final long identity = Binder.clearCallingIdentity(); |
| 7699 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7700 | UiccController uiccController = UiccController.getInstance(); |
| 7701 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7702 | if (hasReadPermission) { |
| 7703 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7704 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7705 | |
| 7706 | // Remove private info if the caller doesn't have access |
| 7707 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 7708 | for (UiccCardInfo cardInfo : cardInfos) { |
| 7709 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 7710 | // is available |
| 7711 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 7712 | if (card == null || card.getUiccProfile() == null) { |
| 7713 | // assume no access if the card or profile is unavailable |
| 7714 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7715 | continue; |
| 7716 | } |
| 7717 | UiccProfile profile = card.getUiccProfile(); |
| 7718 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 7719 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7720 | filteredInfos.add(cardInfo); |
| 7721 | } else { |
| 7722 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7723 | } |
| 7724 | } |
| 7725 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7726 | } finally { |
| 7727 | Binder.restoreCallingIdentity(identity); |
| 7728 | } |
| 7729 | } |
| 7730 | |
| 7731 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7732 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7733 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7734 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7735 | final long identity = Binder.clearCallingIdentity(); |
| 7736 | try { |
| 7737 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 7738 | if (slots == null) { |
| 7739 | Rlog.i(LOG_TAG, "slots is null."); |
| 7740 | return null; |
| 7741 | } |
| 7742 | |
| 7743 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 7744 | for (int i = 0; i < slots.length; i++) { |
| 7745 | UiccSlot slot = slots[i]; |
| 7746 | if (slot == null) { |
| 7747 | continue; |
| 7748 | } |
| 7749 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7750 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7751 | UiccCard card = slot.getUiccCard(); |
| 7752 | if (card != null) { |
| 7753 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7754 | } else { |
Jordan Liu | d96b529 | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 7755 | cardId = slot.getEid(); |
| 7756 | if (TextUtils.isEmpty(cardId)) { |
| 7757 | cardId = slot.getIccId(); |
| 7758 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7759 | } |
| 7760 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 7761 | if (cardId != null) { |
| 7762 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 7763 | // if cardId is an EID, it's all digits so this is fine |
| 7764 | cardId = IccUtils.stripTrailingFs(cardId); |
| 7765 | } |
| 7766 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7767 | int cardState = 0; |
| 7768 | switch (slot.getCardState()) { |
| 7769 | case CARDSTATE_ABSENT: |
| 7770 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 7771 | break; |
| 7772 | case CARDSTATE_PRESENT: |
| 7773 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 7774 | break; |
| 7775 | case CARDSTATE_ERROR: |
| 7776 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 7777 | break; |
| 7778 | case CARDSTATE_RESTRICTED: |
| 7779 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 7780 | break; |
| 7781 | default: |
| 7782 | break; |
| 7783 | |
| 7784 | } |
| 7785 | |
| 7786 | infos[i] = new UiccSlotInfo( |
| 7787 | slot.isActive(), |
| 7788 | slot.isEuicc(), |
| 7789 | cardId, |
| 7790 | cardState, |
| 7791 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 7792 | slot.isExtendedApduSupported(), |
| 7793 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7794 | } |
| 7795 | return infos; |
| 7796 | } finally { |
| 7797 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 7798 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7799 | } |
| 7800 | |
| 7801 | @Override |
| 7802 | public boolean switchSlots(int[] physicalSlots) { |
| 7803 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7804 | |
| 7805 | final long identity = Binder.clearCallingIdentity(); |
| 7806 | try { |
| 7807 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 7808 | } finally { |
| 7809 | Binder.restoreCallingIdentity(identity); |
| 7810 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7811 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7812 | |
| 7813 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7814 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7815 | final long identity = Binder.clearCallingIdentity(); |
| 7816 | try { |
| 7817 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 7818 | } finally { |
| 7819 | Binder.restoreCallingIdentity(identity); |
| 7820 | } |
| 7821 | } |
| 7822 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7823 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 7824 | * A test API to reload the UICC profile. |
| 7825 | * |
| 7826 | * <p>Requires that the calling app has permission |
| 7827 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7828 | * @hide |
| 7829 | */ |
| 7830 | @Override |
| 7831 | public void refreshUiccProfile(int subId) { |
| 7832 | enforceModifyPermission(); |
| 7833 | |
| 7834 | final long identity = Binder.clearCallingIdentity(); |
| 7835 | try { |
| 7836 | Phone phone = getPhone(subId); |
| 7837 | if (phone == null) { |
| 7838 | return; |
| 7839 | } |
| 7840 | UiccCard uiccCard = phone.getUiccCard(); |
| 7841 | if (uiccCard == null) { |
| 7842 | return; |
| 7843 | } |
| 7844 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7845 | if (uiccProfile == null) { |
| 7846 | return; |
| 7847 | } |
| 7848 | uiccProfile.refresh(); |
| 7849 | } finally { |
| 7850 | Binder.restoreCallingIdentity(identity); |
| 7851 | } |
| 7852 | } |
| 7853 | |
| 7854 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7855 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 7856 | */ |
| 7857 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7858 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7859 | } |
| 7860 | |
| 7861 | /** |
| 7862 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 7863 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 7864 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 7865 | */ |
| 7866 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 7867 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7868 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | faaa63d | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 7869 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7870 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 7871 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 7872 | return isDataRoamingEnabled; |
| 7873 | } |
| 7874 | |
| 7875 | /** |
| 7876 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 7877 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 7878 | */ |
| 7879 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7880 | List<Integer> list = TelephonyProperties.default_network(); |
| 7881 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 7882 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 7883 | return list.get(phoneId); |
| 7884 | } |
| 7885 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7886 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7887 | |
| 7888 | @Override |
| 7889 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7890 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7891 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7892 | |
| 7893 | final long identity = Binder.clearCallingIdentity(); |
| 7894 | try { |
| 7895 | final Phone phone = getPhone(subId); |
| 7896 | if (phone == null) { |
| 7897 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 7898 | return; |
| 7899 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7900 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 7901 | carrierPrivilegeRules, apn); |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 7902 | if (carrierPrivilegeRules == null) { |
| 7903 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 7904 | } else { |
| 7905 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 7906 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7907 | } finally { |
| 7908 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7909 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7910 | } |
| 7911 | |
| 7912 | @Override |
| 7913 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7914 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7915 | |
| 7916 | final long identity = Binder.clearCallingIdentity(); |
| 7917 | try { |
| 7918 | final Phone phone = getPhone(subId); |
| 7919 | if (phone == null) { |
| 7920 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 7921 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 7922 | } |
| 7923 | return phone.getCarrierIdListVersion(); |
| 7924 | } finally { |
| 7925 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7926 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7927 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7928 | |
| 7929 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7930 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 7931 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7932 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7933 | mApp, subId, callingPackage, callingFeatureId, |
| 7934 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7935 | return -1; |
| 7936 | } |
| 7937 | |
| 7938 | final long identity = Binder.clearCallingIdentity(); |
| 7939 | try { |
| 7940 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 7941 | } finally { |
| 7942 | Binder.restoreCallingIdentity(identity); |
| 7943 | } |
| 7944 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7945 | |
| 7946 | @Override |
| 7947 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 0723870 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 7948 | TelephonyPermissions |
| 7949 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7950 | mApp, subId, "getCdmaRoamingMode"); |
| 7951 | |
| 7952 | final long identity = Binder.clearCallingIdentity(); |
| 7953 | try { |
| 7954 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 7955 | } finally { |
| 7956 | Binder.restoreCallingIdentity(identity); |
| 7957 | } |
| 7958 | } |
| 7959 | |
| 7960 | @Override |
| 7961 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 7962 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7963 | mApp, subId, "setCdmaRoamingMode"); |
| 7964 | |
| 7965 | final long identity = Binder.clearCallingIdentity(); |
| 7966 | try { |
| 7967 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 7968 | } finally { |
| 7969 | Binder.restoreCallingIdentity(identity); |
| 7970 | } |
| 7971 | } |
| 7972 | |
| 7973 | @Override |
| 7974 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 7975 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7976 | mApp, subId, "setCdmaSubscriptionMode"); |
| 7977 | |
| 7978 | final long identity = Binder.clearCallingIdentity(); |
| 7979 | try { |
| 7980 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 7981 | } finally { |
| 7982 | Binder.restoreCallingIdentity(identity); |
| 7983 | } |
| 7984 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 7985 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7986 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7987 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7988 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7989 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7990 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 7991 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7992 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7993 | } |
| 7994 | final long identity = Binder.clearCallingIdentity(); |
| 7995 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7996 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 7997 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7998 | if (phone.getEmergencyNumberTracker() != null |
| 7999 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 8000 | emergencyNumberListInternal.put( |
| 8001 | phone.getSubId(), |
| 8002 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 8003 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8004 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8005 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8006 | } finally { |
| 8007 | Binder.restoreCallingIdentity(identity); |
| 8008 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8009 | } |
| 8010 | |
| 8011 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8012 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8013 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8014 | if (!exactMatch) { |
| 8015 | TelephonyPermissions |
| 8016 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8017 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8018 | } |
| 8019 | final long identity = Binder.clearCallingIdentity(); |
| 8020 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8021 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8022 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8023 | && phone.getEmergencyNumberTracker() |
| 8024 | .isEmergencyNumber(number, exactMatch)) { |
| 8025 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8026 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8027 | } |
| 8028 | return false; |
| 8029 | } finally { |
| 8030 | Binder.restoreCallingIdentity(identity); |
| 8031 | } |
| 8032 | } |
| 8033 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8034 | /** |
| 8035 | * Update emergency number list for test mode. |
| 8036 | */ |
| 8037 | @Override |
| 8038 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 8039 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8040 | "updateEmergencyNumberListTestMode"); |
| 8041 | |
| 8042 | final long identity = Binder.clearCallingIdentity(); |
| 8043 | try { |
| 8044 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8045 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8046 | if (tracker != null) { |
| 8047 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 8048 | } |
| 8049 | } |
| 8050 | } finally { |
| 8051 | Binder.restoreCallingIdentity(identity); |
| 8052 | } |
| 8053 | } |
| 8054 | |
| 8055 | /** |
| 8056 | * Get the full emergency number list for test mode. |
| 8057 | */ |
| 8058 | @Override |
| 8059 | public List<String> getEmergencyNumberListTestMode() { |
| 8060 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8061 | "getEmergencyNumberListTestMode"); |
| 8062 | |
| 8063 | final long identity = Binder.clearCallingIdentity(); |
| 8064 | try { |
| 8065 | Set<String> emergencyNumbers = new HashSet<>(); |
| 8066 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8067 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8068 | if (tracker != null) { |
| 8069 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 8070 | emergencyNumbers.add(num.getNumber()); |
| 8071 | } |
| 8072 | } |
| 8073 | } |
| 8074 | return new ArrayList<>(emergencyNumbers); |
| 8075 | } finally { |
| 8076 | Binder.restoreCallingIdentity(identity); |
| 8077 | } |
| 8078 | } |
| 8079 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8080 | @Override |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8081 | public int getEmergencyNumberDbVersion(int subId) { |
| 8082 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 8083 | |
| 8084 | final long identity = Binder.clearCallingIdentity(); |
| 8085 | try { |
| 8086 | final Phone phone = getPhone(subId); |
| 8087 | if (phone == null) { |
| 8088 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 8089 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 8090 | } |
| 8091 | return phone.getEmergencyNumberDbVersion(); |
| 8092 | } finally { |
| 8093 | Binder.restoreCallingIdentity(identity); |
| 8094 | } |
| 8095 | } |
| 8096 | |
| 8097 | @Override |
| 8098 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 8099 | enforceModifyPermission(); |
| 8100 | |
| 8101 | final long identity = Binder.clearCallingIdentity(); |
| 8102 | try { |
| 8103 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8104 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8105 | if (tracker != null) { |
| 8106 | tracker.updateOtaEmergencyNumberDatabase(); |
| 8107 | } |
| 8108 | } |
| 8109 | } finally { |
| 8110 | Binder.restoreCallingIdentity(identity); |
| 8111 | } |
| 8112 | } |
| 8113 | |
| 8114 | @Override |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8115 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8116 | enforceActiveEmergencySessionPermission(); |
| 8117 | |
| 8118 | final long identity = Binder.clearCallingIdentity(); |
| 8119 | try { |
| 8120 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8121 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8122 | if (tracker != null) { |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8123 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 8124 | } |
| 8125 | } |
| 8126 | } finally { |
| 8127 | Binder.restoreCallingIdentity(identity); |
| 8128 | } |
| 8129 | } |
| 8130 | |
| 8131 | @Override |
| 8132 | public void resetOtaEmergencyNumberDbFilePath() { |
| 8133 | enforceActiveEmergencySessionPermission(); |
| 8134 | |
| 8135 | final long identity = Binder.clearCallingIdentity(); |
| 8136 | try { |
| 8137 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8138 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8139 | if (tracker != null) { |
| 8140 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8141 | } |
| 8142 | } |
| 8143 | } finally { |
| 8144 | Binder.restoreCallingIdentity(identity); |
| 8145 | } |
| 8146 | } |
| 8147 | |
| 8148 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8149 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 8150 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 8151 | Phone phone = getPhone(subId); |
| 8152 | if (phone == null) { |
| 8153 | return null; |
| 8154 | } |
| 8155 | final long identity = Binder.clearCallingIdentity(); |
| 8156 | try { |
| 8157 | UiccProfile profile = UiccController.getInstance() |
| 8158 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 8159 | if (profile != null) { |
| 8160 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 8161 | } |
| 8162 | } finally { |
| 8163 | Binder.restoreCallingIdentity(identity); |
| 8164 | } |
| 8165 | return null; |
| 8166 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 8167 | |
| 8168 | /** |
| 8169 | * Enable or disable a modem stack. |
| 8170 | */ |
| 8171 | @Override |
| 8172 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 8173 | enforceModifyPermission(); |
| 8174 | |
| 8175 | final long identity = Binder.clearCallingIdentity(); |
| 8176 | try { |
| 8177 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8178 | if (phone == null) { |
| 8179 | return false; |
| 8180 | } else { |
| 8181 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 8182 | } |
| 8183 | } finally { |
| 8184 | Binder.restoreCallingIdentity(identity); |
| 8185 | } |
| 8186 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8187 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8188 | /** |
| 8189 | * Whether a modem stack is enabled or not. |
| 8190 | */ |
| 8191 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8192 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 8193 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8194 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8195 | if (phone == null) return false; |
| 8196 | |
| 8197 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8198 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 8199 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8200 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8201 | } |
| 8202 | |
| 8203 | final long identity = Binder.clearCallingIdentity(); |
| 8204 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8205 | try { |
| 8206 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 8207 | } catch (NoSuchElementException ex) { |
| 8208 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 8209 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8210 | } finally { |
| 8211 | Binder.restoreCallingIdentity(identity); |
| 8212 | } |
| 8213 | } |
| 8214 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8215 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8216 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8217 | enforceModifyPermission(); |
| 8218 | |
| 8219 | final long identity = Binder.clearCallingIdentity(); |
| 8220 | try { |
| 8221 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8222 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8223 | .commit(); |
| 8224 | } finally { |
| 8225 | Binder.restoreCallingIdentity(identity); |
| 8226 | } |
| 8227 | } |
| 8228 | |
| 8229 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8230 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8231 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8232 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8233 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8234 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8235 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8236 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8237 | |
| 8238 | final long identity = Binder.clearCallingIdentity(); |
| 8239 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8240 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8241 | } finally { |
| 8242 | Binder.restoreCallingIdentity(identity); |
| 8243 | } |
| 8244 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8245 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8246 | @TelephonyManager.IsMultiSimSupportedResult |
| 8247 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8248 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8249 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8250 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8251 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8252 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8253 | } |
| 8254 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8255 | // supported by the modem, indicate that it is restricted. |
| 8256 | PhoneCapability staticCapability = |
| 8257 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8258 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8259 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8260 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8261 | } |
Sarah Chin | 09f38ee | 2020-02-25 00:13:10 +0000 | [diff] [blame] | 8262 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8263 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8264 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8265 | } |
| 8266 | // Check if support of multiple SIMs is restricted by carrier |
| 8267 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8268 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8269 | } |
| 8270 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8271 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8272 | } |
| 8273 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8274 | /** |
| 8275 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8276 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8277 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8278 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8279 | * @param numOfSims number of active sims we want to switch to |
| 8280 | */ |
| 8281 | @Override |
| 8282 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8283 | if (numOfSims == 1) { |
| 8284 | enforceModifyPermission(); |
| 8285 | } else { |
| 8286 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8287 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8288 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8289 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8290 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8291 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8292 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8293 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8294 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8295 | return; |
| 8296 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8297 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8298 | } finally { |
| 8299 | Binder.restoreCallingIdentity(identity); |
| 8300 | } |
| 8301 | } |
| 8302 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8303 | @Override |
| 8304 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8305 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8306 | Phone phone = getPhone(subId); |
| 8307 | if (phone == null) { |
| 8308 | return false; |
| 8309 | } |
| 8310 | final long identity = Binder.clearCallingIdentity(); |
| 8311 | try { |
| 8312 | UiccCard uiccCard = phone.getUiccCard(); |
| 8313 | if (uiccCard == null) { |
| 8314 | return false; |
| 8315 | } |
| 8316 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8317 | if (uiccProfile == null) { |
| 8318 | return false; |
| 8319 | } |
| 8320 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8321 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8322 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8323 | } |
| 8324 | return false; |
| 8325 | } finally { |
| 8326 | Binder.restoreCallingIdentity(identity); |
| 8327 | } |
| 8328 | } |
| 8329 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8330 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8331 | * Get whether making changes to modem configurations will trigger reboot. |
| 8332 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8333 | */ |
| 8334 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8335 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8336 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8337 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8338 | mApp, subId, callingPackage, callingFeatureId, |
| 8339 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8340 | return false; |
| 8341 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8342 | final long identity = Binder.clearCallingIdentity(); |
| 8343 | try { |
| 8344 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8345 | } finally { |
| 8346 | Binder.restoreCallingIdentity(identity); |
| 8347 | } |
| 8348 | } |
| 8349 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8350 | private void updateModemStateMetrics() { |
| 8351 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8352 | // TODO: check the state for each modem if the api is ready. |
| 8353 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8354 | } |
| 8355 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8356 | @Override |
| 8357 | public int[] getSlotsMapping() { |
| 8358 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8359 | |
| 8360 | final long identity = Binder.clearCallingIdentity(); |
| 8361 | try { |
| 8362 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8363 | // All logical slots should have a mapping to a physical slot. |
| 8364 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8365 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8366 | for (int i = 0; i < slotInfos.length; i++) { |
| 8367 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8368 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8369 | } |
| 8370 | } |
| 8371 | return logicalSlotsMapping; |
| 8372 | } finally { |
| 8373 | Binder.restoreCallingIdentity(identity); |
| 8374 | } |
| 8375 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8376 | |
| 8377 | /** |
| 8378 | * Get the IRadio HAL Version |
| 8379 | */ |
| 8380 | @Override |
| 8381 | public int getRadioHalVersion() { |
| 8382 | Phone phone = getDefaultPhone(); |
| 8383 | if (phone == null) return -1; |
| 8384 | HalVersion hv = phone.getHalVersion(); |
| 8385 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8386 | return hv.major * 100 + hv.minor; |
| 8387 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8388 | |
| 8389 | /** |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8390 | * Get the current calling package name. |
| 8391 | * @return the current calling package name |
| 8392 | */ |
| 8393 | @Override |
| 8394 | public String getCurrentPackageName() { |
| 8395 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8396 | } |
| 8397 | |
| 8398 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8399 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8400 | * corresponding network requests on a subId. |
| 8401 | * |
| 8402 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8403 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8404 | * 2) APN is un-metered for this subscription, or |
| 8405 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | b48cf45 | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 8406 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8407 | * |
| 8408 | * @return whether data is allowed for a apn type. |
| 8409 | * |
| 8410 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8411 | */ |
| 8412 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8413 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | f250974 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8414 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8415 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8416 | |
| 8417 | // Now that all security checks passes, perform the operation as ourselves. |
| 8418 | final long identity = Binder.clearCallingIdentity(); |
| 8419 | try { |
| 8420 | Phone phone = getPhone(subId); |
| 8421 | if (phone == null) return false; |
| 8422 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8423 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8424 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8425 | } finally { |
| 8426 | Binder.restoreCallingIdentity(identity); |
| 8427 | } |
| 8428 | } |
| 8429 | |
| 8430 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8431 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8432 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8433 | |
| 8434 | // Now that all security checks passes, perform the operation as ourselves. |
| 8435 | final long identity = Binder.clearCallingIdentity(); |
| 8436 | try { |
| 8437 | Phone phone = getPhone(subId); |
| 8438 | if (phone == null) return true; // By default return true. |
| 8439 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8440 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8441 | } finally { |
| 8442 | Binder.restoreCallingIdentity(identity); |
| 8443 | } |
| 8444 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8445 | |
| 8446 | @Override |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 8447 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 8448 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 8449 | enforceModifyPermission(); |
| 8450 | long token = Binder.clearCallingIdentity(); |
| 8451 | try { |
| 8452 | Phone phone = getPhone(subscriptionId); |
| 8453 | if (phone == null) { |
| 8454 | try { |
| 8455 | if (resultCallback != null) { |
| 8456 | resultCallback.accept(false); |
| 8457 | } |
| 8458 | } catch (RemoteException e) { |
| 8459 | // ignore |
| 8460 | } |
| 8461 | return; |
| 8462 | } |
| 8463 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 8464 | Pair.create(specifiers, (x) -> { |
| 8465 | try { |
| 8466 | if (resultCallback != null) { |
| 8467 | resultCallback.accept(x); |
| 8468 | } |
| 8469 | } catch (RemoteException e) { |
| 8470 | // ignore |
| 8471 | } |
| 8472 | }); |
| 8473 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 8474 | } finally { |
| 8475 | Binder.restoreCallingIdentity(token); |
| 8476 | } |
| 8477 | } |
| 8478 | |
| 8479 | @Override |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8480 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 8481 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8482 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 8483 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 8484 | if (iccRecords == null) { |
| 8485 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 8486 | return false; |
| 8487 | } |
| 8488 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 8489 | } |
| 8490 | |
| 8491 | @Override |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8492 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 8493 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8494 | if (callingPackage == null) { |
| 8495 | callingPackage = getCurrentPackageName(); |
| 8496 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8497 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 8498 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8499 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 8500 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8501 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 8502 | } |
| 8503 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 8504 | Intent intent = new Intent(); |
| 8505 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 8506 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 8507 | // Bring up choose default SMS subscription dialog right now |
| 8508 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 8509 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 8510 | mApp.startActivity(intent); |
| 8511 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8512 | |
| 8513 | @Override |
| 8514 | public String getMmsUAProfUrl(int subId) { |
| 8515 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8516 | final long identity = Binder.clearCallingIdentity(); |
| 8517 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 8518 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 8519 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 8520 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 8521 | return carrierUAProfUrl; |
| 8522 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8523 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8524 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 8525 | } finally { |
| 8526 | Binder.restoreCallingIdentity(identity); |
| 8527 | } |
| 8528 | } |
| 8529 | |
| 8530 | @Override |
| 8531 | public String getMmsUserAgent(int subId) { |
| 8532 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8533 | final long identity = Binder.clearCallingIdentity(); |
| 8534 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 8535 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 8536 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 8537 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 8538 | return carrierUserAgent; |
| 8539 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8540 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8541 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 8542 | } finally { |
| 8543 | Binder.restoreCallingIdentity(identity); |
| 8544 | } |
| 8545 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8546 | |
| 8547 | @Override |
Hall Liu | c041a55 | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 8548 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 8549 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
| 8550 | |
| 8551 | final long identity = Binder.clearCallingIdentity(); |
| 8552 | try { |
| 8553 | Phone phone = getPhone(subscriptionId); |
| 8554 | if (phone == null) return false; |
| 8555 | |
| 8556 | switch (policy) { |
| 8557 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 8558 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 8559 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 8560 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 8561 | default: |
| 8562 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 8563 | } |
| 8564 | } finally { |
| 8565 | Binder.restoreCallingIdentity(identity); |
| 8566 | } |
| 8567 | } |
| 8568 | |
| 8569 | @Override |
| 8570 | public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy, |
| 8571 | boolean enabled) { |
| 8572 | enforceModifyPermission(); |
| 8573 | |
| 8574 | final long identity = Binder.clearCallingIdentity(); |
| 8575 | try { |
| 8576 | Phone phone = getPhone(subscriptionId); |
| 8577 | if (phone == null) return; |
| 8578 | |
| 8579 | switch (policy) { |
| 8580 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 8581 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 8582 | break; |
| 8583 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 8584 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 8585 | break; |
| 8586 | default: |
| 8587 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 8588 | } |
| 8589 | } finally { |
| 8590 | Binder.restoreCallingIdentity(identity); |
| 8591 | } |
| 8592 | } |
| 8593 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8594 | /** |
Hall Liu | b48cf45 | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 8595 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8596 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 8597 | * otherwise. |
| 8598 | */ |
| 8599 | @Override |
| 8600 | public void setCepEnabled(boolean isCepEnabled) { |
| 8601 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 8602 | |
| 8603 | final long identity = Binder.clearCallingIdentity(); |
| 8604 | try { |
| 8605 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 8606 | for (Phone phone : PhoneFactory.getPhones()) { |
| 8607 | Phone defaultPhone = phone.getImsPhone(); |
| 8608 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 8609 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 8610 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 8611 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 8612 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 8613 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 8614 | + imsPhone.getMsisdn()); |
| 8615 | } |
| 8616 | } |
| 8617 | } finally { |
| 8618 | Binder.restoreCallingIdentity(identity); |
| 8619 | } |
| 8620 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 8621 | |
| 8622 | /** |
| 8623 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 8624 | * |
| 8625 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 8626 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 8627 | * before being read. |
| 8628 | */ |
| 8629 | @Override |
| 8630 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 8631 | isCompressed) { |
| 8632 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8633 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
| 8634 | try { |
| 8635 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 8636 | if (configBinder == null) { |
| 8637 | Rlog.e(LOG_TAG, "null result for getImsConfig"); |
| 8638 | } else { |
| 8639 | configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed); |
| 8640 | } |
| 8641 | } catch (RemoteException e) { |
| 8642 | Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage()); |
| 8643 | } |
| 8644 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8645 | |
| 8646 | @Override |
| 8647 | public boolean isIccLockEnabled(int subId) { |
| 8648 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 8649 | |
| 8650 | // Now that all security checks passes, perform the operation as ourselves. |
| 8651 | final long identity = Binder.clearCallingIdentity(); |
| 8652 | try { |
| 8653 | Phone phone = getPhone(subId); |
| 8654 | if (phone != null && phone.getIccCard() != null) { |
| 8655 | return phone.getIccCard().getIccLockEnabled(); |
| 8656 | } else { |
| 8657 | return false; |
| 8658 | } |
| 8659 | } finally { |
| 8660 | Binder.restoreCallingIdentity(identity); |
| 8661 | } |
| 8662 | } |
| 8663 | |
| 8664 | /** |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8665 | * Set the ICC pin lock enabled or disabled. |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8666 | * |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8667 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 8668 | * three cases: |
| 8669 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 8670 | * successfully. |
| 8671 | * - Positive number and zero for remaining password attempts. |
| 8672 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8673 | * |
| 8674 | */ |
| 8675 | @Override |
| 8676 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 8677 | enforceModifyPermission(); |
| 8678 | |
| 8679 | Phone phone = getPhone(subId); |
| 8680 | if (phone == null) { |
| 8681 | return 0; |
| 8682 | } |
| 8683 | // Now that all security checks passes, perform the operation as ourselves. |
| 8684 | final long identity = Binder.clearCallingIdentity(); |
| 8685 | try { |
| 8686 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 8687 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 8688 | return attemptsRemaining; |
| 8689 | |
| 8690 | } catch (Exception e) { |
| 8691 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 8692 | } finally { |
| 8693 | Binder.restoreCallingIdentity(identity); |
| 8694 | } |
| 8695 | return 0; |
| 8696 | } |
| 8697 | |
| 8698 | /** |
| 8699 | * Change the ICC password used in ICC pin lock. |
| 8700 | * |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8701 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 8702 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 8703 | * - Positive number and zero for remaining password attempts. |
| 8704 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8705 | * |
| 8706 | */ |
| 8707 | @Override |
| 8708 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 8709 | enforceModifyPermission(); |
| 8710 | |
| 8711 | Phone phone = getPhone(subId); |
| 8712 | if (phone == null) { |
| 8713 | return 0; |
| 8714 | } |
| 8715 | // Now that all security checks passes, perform the operation as ourselves. |
| 8716 | final long identity = Binder.clearCallingIdentity(); |
| 8717 | try { |
| 8718 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 8719 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 8720 | return attemptsRemaining; |
| 8721 | |
| 8722 | } catch (Exception e) { |
| 8723 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 8724 | } finally { |
| 8725 | Binder.restoreCallingIdentity(identity); |
| 8726 | } |
| 8727 | return 0; |
| 8728 | } |
Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 8729 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 8730 | /** |
| 8731 | * Request for receiving user activity notification |
| 8732 | */ |
| 8733 | @Override |
| 8734 | public void requestUserActivityNotification() { |
| 8735 | if (!mNotifyUserActivity.get() |
| 8736 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 8737 | mNotifyUserActivity.set(true); |
| 8738 | } |
| 8739 | } |
| 8740 | |
| 8741 | /** |
| 8742 | * Called when userActivity is signalled in the power manager. |
| 8743 | * This is safe to call from any thread, with any window manager locks held or not. |
| 8744 | */ |
| 8745 | @Override |
| 8746 | public void userActivity() { |
| 8747 | // *************************************** |
| 8748 | // * Inherited from PhoneWindowManager * |
| 8749 | // *************************************** |
| 8750 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 8751 | // WITH ITS LOCKS HELD. |
| 8752 | // |
| 8753 | // This code must be VERY careful about the locks |
| 8754 | // it acquires. |
| 8755 | // In fact, the current code acquires way too many, |
| 8756 | // and probably has lurking deadlocks. |
| 8757 | |
| 8758 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 8759 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 8760 | } |
| 8761 | |
| 8762 | if (mNotifyUserActivity.getAndSet(false)) { |
| 8763 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 8764 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 8765 | } |
| 8766 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 8767 | |
Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 8768 | @Override |
| 8769 | public boolean canConnectTo5GInDsdsMode() { |
| 8770 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 8771 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 8772 | |
| 8773 | @Override |
| 8774 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 8775 | String callingFeatureId) { |
| 8776 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 8777 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 8778 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8779 | } |
| 8780 | |
| 8781 | Phone phone = getPhone(subId); |
| 8782 | if (phone == null) { |
| 8783 | throw new RuntimeException("phone is not available"); |
| 8784 | } |
| 8785 | // Now that all security checks passes, perform the operation as ourselves. |
| 8786 | final long identity = Binder.clearCallingIdentity(); |
| 8787 | try { |
| 8788 | return phone.getEquivalentHomePlmns(); |
| 8789 | } finally { |
| 8790 | Binder.restoreCallingIdentity(identity); |
| 8791 | } |
| 8792 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 8793 | } |