Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.phone; |
| 18 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 19 | import static android.content.pm.PackageManager.PERMISSION_GRANTED; |
| 20 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 21 | import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 22 | import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY; |
| 23 | |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 24 | import android.Manifest.permission; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 25 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 26 | import android.annotation.Nullable; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 27 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 28 | import android.app.PendingIntent; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 29 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 30 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 31 | import android.content.Context; |
| 32 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 33 | import android.content.SharedPreferences; |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 34 | import android.content.pm.ApplicationInfo; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 35 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 36 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 37 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 38 | import android.net.Uri; |
| 39 | import android.os.AsyncResult; |
| 40 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 41 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 42 | import android.os.Bundle; |
| 43 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 44 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.os.Looper; |
| 46 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 47 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 48 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 49 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 50 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 51 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 52 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 53 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 54 | import android.os.ServiceSpecificException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 55 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 56 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 57 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 58 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 59 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 60 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 61 | import android.provider.Telephony; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 62 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 63 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 64 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 65 | import android.telecom.TelecomManager; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 66 | import android.telephony.Annotation.ApnType; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 67 | import android.telephony.CallForwardingInfo; |
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 | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 70 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 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 | a34a6c2 | 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.IImsMmTelFeature; |
| 108 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 109 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 110 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 111 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 112 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 113 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 114 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 115 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 116 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 117 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 118 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 119 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 120 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 121 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 122 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 123 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 124 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 127 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 128 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 130 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 131 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 132 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 133 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 134 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 137 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 139 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 145 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 155 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 156 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 158 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 160 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 162 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 163 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 166 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 168 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 170 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 172 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 173 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 174 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 175 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 176 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 177 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 178 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 179 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 180 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 181 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 182 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 183 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 184 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 185 | import java.io.FileDescriptor; |
| 186 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 187 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 188 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 189 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 190 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 191 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 192 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 193 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 194 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 195 | import java.util.Set; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 196 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 197 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 198 | |
| 199 | /** |
| 200 | * Implementation of the ITelephony interface. |
| 201 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 202 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 203 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 204 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 205 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 206 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 207 | |
| 208 | // Message codes used with mMainThreadHandler |
| 209 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 210 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 211 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 212 | private static final int CMD_OPEN_CHANNEL = 9; |
| 213 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 214 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 215 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 216 | private static final int CMD_NV_READ_ITEM = 13; |
| 217 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 218 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 219 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 220 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 221 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 222 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 223 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 224 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 225 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 226 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 227 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 228 | private static final int CMD_SEND_ENVELOPE = 25; |
| 229 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 230 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 231 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 232 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 233 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 234 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 235 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 236 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 237 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 238 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 239 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 240 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 241 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 242 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 243 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 244 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 245 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 246 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 247 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 248 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 249 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 250 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 251 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 252 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 253 | private static final int CMD_SWITCH_SLOTS = 50; |
| 254 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 255 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 256 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 257 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 258 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 259 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 260 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 261 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 262 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 263 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 264 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 265 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 266 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 267 | private static final int CMD_MODEM_REBOOT = 64; |
| 268 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 269 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 270 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 271 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 272 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 273 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 274 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 275 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 276 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 277 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 278 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 279 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 280 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 281 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 282 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 283 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 284 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 285 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 286 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 287 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 288 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 289 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 290 | private static final int CMD_GET_CALL_WAITING = 87; |
| 291 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 292 | private static final int CMD_SET_CALL_WAITING = 89; |
| 293 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 294 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 295 | // Parameters of select command. |
| 296 | private static final int SELECT_COMMAND = 0xA4; |
| 297 | private static final int SELECT_P1 = 0x04; |
| 298 | private static final int SELECT_P2 = 0; |
| 299 | private static final int SELECT_P3 = 0x10; |
| 300 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 301 | /** The singleton instance. */ |
| 302 | private static PhoneInterfaceManager sInstance; |
| 303 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 304 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 305 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 306 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 307 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 308 | private AppOpsManager mAppOps; |
| 309 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 310 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 311 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 312 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 313 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 314 | /** User Activity */ |
| 315 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 316 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 317 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 318 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 319 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 320 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 321 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 322 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 323 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 324 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 325 | // String to store multi SIM allowed |
| 326 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 327 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 328 | // The AID of ISD-R. |
| 329 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 330 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 331 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 332 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 333 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 334 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 335 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 336 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 337 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 338 | */ |
| 339 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 340 | "reset_network_erase_modem_config_enabled"; |
| 341 | |
| 342 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 343 | * A request object to use for transmitting data to an ICC. |
| 344 | */ |
| 345 | private static final class IccAPDUArgument { |
| 346 | public int channel, cla, command, p1, p2, p3; |
| 347 | public String data; |
| 348 | |
| 349 | public IccAPDUArgument(int channel, int cla, int command, |
| 350 | int p1, int p2, int p3, String data) { |
| 351 | this.channel = channel; |
| 352 | this.cla = cla; |
| 353 | this.command = command; |
| 354 | this.p1 = p1; |
| 355 | this.p2 = p2; |
| 356 | this.p3 = p3; |
| 357 | this.data = data; |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 362 | * A request object to use for transmitting data to an ICC. |
| 363 | */ |
| 364 | private static final class ManualNetworkSelectionArgument { |
| 365 | public OperatorInfo operatorInfo; |
| 366 | public boolean persistSelection; |
| 367 | |
| 368 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 369 | this.operatorInfo = operatorInfo; |
| 370 | this.persistSelection = persistSelection; |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 375 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 376 | * request after sending. The main thread will notify the request when it is complete. |
| 377 | */ |
| 378 | private static final class MainThreadRequest { |
| 379 | /** The argument to use for the request */ |
| 380 | public Object argument; |
| 381 | /** The result of the request that is run on the main thread */ |
| 382 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 383 | // The subscriber id that this request applies to. Defaults to |
| 384 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 385 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 386 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 387 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 388 | public Phone phone; |
| 389 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 390 | public WorkSource workSource; |
| 391 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 392 | public MainThreadRequest(Object argument) { |
| 393 | this.argument = argument; |
| 394 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 395 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 396 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 397 | this.argument = argument; |
| 398 | if (phone != null) { |
| 399 | this.phone = phone; |
| 400 | } |
| 401 | this.workSource = workSource; |
| 402 | } |
| 403 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 404 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 405 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 406 | if (subId != null) { |
| 407 | this.subId = subId; |
| 408 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 409 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 410 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 411 | } |
| 412 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 413 | private static final class IncomingThirdPartyCallArgs { |
| 414 | public final ComponentName component; |
| 415 | public final String callId; |
| 416 | public final String callerDisplayName; |
| 417 | |
| 418 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 419 | String callerDisplayName) { |
| 420 | this.component = component; |
| 421 | this.callId = callId; |
| 422 | this.callerDisplayName = callerDisplayName; |
| 423 | } |
| 424 | } |
| 425 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 426 | /** |
| 427 | * A handler that processes messages on the main thread in the phone process. Since many |
| 428 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 429 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 430 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 431 | * on, which will be notified when the operation completes and will contain the result of the |
| 432 | * request. |
| 433 | * |
| 434 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 435 | * note that request.result must be set to something non-null for the calling thread to |
| 436 | * unblock. |
| 437 | */ |
| 438 | private final class MainThreadHandler extends Handler { |
| 439 | @Override |
| 440 | public void handleMessage(Message msg) { |
| 441 | MainThreadRequest request; |
| 442 | Message onCompleted; |
| 443 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 444 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 445 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 446 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 447 | |
| 448 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 449 | case CMD_HANDLE_USSD_REQUEST: { |
| 450 | request = (MainThreadRequest) msg.obj; |
| 451 | final Phone phone = getPhoneFromRequest(request); |
| 452 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 453 | String ussdRequest = ussdObject.first; |
| 454 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 455 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 456 | if (!isUssdApiAllowed(request.subId)) { |
| 457 | // Carrier does not support use of this API, return failure. |
| 458 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 459 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 460 | Bundle returnData = new Bundle(); |
| 461 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 462 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 463 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 464 | request.result = true; |
| 465 | notifyRequester(request); |
| 466 | return; |
| 467 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 468 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 469 | try { |
| 470 | request.result = phone != null |
| 471 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 472 | } catch (CallStateException cse) { |
| 473 | request.result = false; |
| 474 | } |
| 475 | // Wake up the requesting thread |
| 476 | notifyRequester(request); |
| 477 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 478 | } |
| 479 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 480 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 481 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 482 | final Phone phone = getPhoneFromRequest(request); |
| 483 | request.result = phone != null ? |
| 484 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 485 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 486 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 487 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 488 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 489 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 490 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 491 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 492 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 493 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 494 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 495 | if (uiccCard == null) { |
| 496 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 497 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 498 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 499 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 500 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 501 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 502 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 503 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 504 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 505 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 506 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 507 | break; |
| 508 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 509 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 510 | ar = (AsyncResult) msg.obj; |
| 511 | request = (MainThreadRequest) ar.userObj; |
| 512 | if (ar.exception == null && ar.result != null) { |
| 513 | request.result = ar.result; |
| 514 | } else { |
| 515 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 516 | if (ar.result == null) { |
| 517 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 518 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 519 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 520 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 521 | } else { |
| 522 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 523 | } |
| 524 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 525 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 526 | break; |
| 527 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 528 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 529 | request = (MainThreadRequest) msg.obj; |
| 530 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 531 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 532 | if (uiccCard == null) { |
| 533 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 534 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 535 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 536 | } else { |
| 537 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 538 | request); |
| 539 | uiccCard.iccTransmitApduBasicChannel( |
| 540 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 541 | iccArgument.p3, iccArgument.data, onCompleted); |
| 542 | } |
| 543 | break; |
| 544 | |
| 545 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 546 | ar = (AsyncResult) msg.obj; |
| 547 | request = (MainThreadRequest) ar.userObj; |
| 548 | if (ar.exception == null && ar.result != null) { |
| 549 | request.result = ar.result; |
| 550 | } else { |
| 551 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 552 | if (ar.result == null) { |
| 553 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 554 | } else if (ar.exception instanceof CommandException) { |
| 555 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 556 | ar.exception); |
| 557 | } else { |
| 558 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 559 | } |
| 560 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 561 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 562 | break; |
| 563 | |
| 564 | case CMD_EXCHANGE_SIM_IO: |
| 565 | request = (MainThreadRequest) msg.obj; |
| 566 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 567 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 568 | if (uiccCard == null) { |
| 569 | loge("iccExchangeSimIO: No UICC"); |
| 570 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 571 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 572 | } else { |
| 573 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 574 | request); |
| 575 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 576 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 577 | iccArgument.data, onCompleted); |
| 578 | } |
| 579 | break; |
| 580 | |
| 581 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 582 | ar = (AsyncResult) msg.obj; |
| 583 | request = (MainThreadRequest) ar.userObj; |
| 584 | if (ar.exception == null && ar.result != null) { |
| 585 | request.result = ar.result; |
| 586 | } else { |
| 587 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 588 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 589 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 590 | break; |
| 591 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 592 | case CMD_SEND_ENVELOPE: |
| 593 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 594 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 595 | if (uiccCard == null) { |
| 596 | loge("sendEnvelopeWithStatus: No UICC"); |
| 597 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 598 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 599 | } else { |
| 600 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 601 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 602 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 603 | break; |
| 604 | |
| 605 | case EVENT_SEND_ENVELOPE_DONE: |
| 606 | ar = (AsyncResult) msg.obj; |
| 607 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 608 | if (ar.exception == null && ar.result != null) { |
| 609 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 610 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 611 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 612 | if (ar.result == null) { |
| 613 | loge("sendEnvelopeWithStatus: Empty response"); |
| 614 | } else if (ar.exception instanceof CommandException) { |
| 615 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 616 | ar.exception); |
| 617 | } else { |
| 618 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 619 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 620 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 621 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 622 | break; |
| 623 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 624 | case CMD_OPEN_CHANNEL: |
| 625 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 626 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 627 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 628 | if (uiccCard == null) { |
| 629 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 630 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 631 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 632 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 633 | } else { |
| 634 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 635 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 636 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 637 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 638 | break; |
| 639 | |
| 640 | case EVENT_OPEN_CHANNEL_DONE: |
| 641 | ar = (AsyncResult) msg.obj; |
| 642 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 643 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 644 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 645 | int[] result = (int[]) ar.result; |
| 646 | int channelId = result[0]; |
| 647 | byte[] selectResponse = null; |
| 648 | if (result.length > 1) { |
| 649 | selectResponse = new byte[result.length - 1]; |
| 650 | for (int i = 1; i < result.length; ++i) { |
| 651 | selectResponse[i - 1] = (byte) result[i]; |
| 652 | } |
| 653 | } |
| 654 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 655 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 656 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 657 | if (ar.result == null) { |
| 658 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 659 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 660 | if (ar.exception != null) { |
| 661 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 662 | } |
| 663 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 664 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 665 | if (ar.exception instanceof CommandException) { |
| 666 | CommandException.Error error = |
| 667 | ((CommandException) (ar.exception)).getCommandError(); |
| 668 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 669 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 670 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 671 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 672 | } |
| 673 | } |
| 674 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 675 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 676 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 677 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 678 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 679 | break; |
| 680 | |
| 681 | case CMD_CLOSE_CHANNEL: |
| 682 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 683 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 684 | if (uiccCard == null) { |
| 685 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 686 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 687 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 688 | } else { |
| 689 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 690 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 691 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 692 | break; |
| 693 | |
| 694 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 695 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 696 | break; |
| 697 | |
| 698 | case CMD_NV_READ_ITEM: |
| 699 | request = (MainThreadRequest) msg.obj; |
| 700 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 701 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 702 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 703 | break; |
| 704 | |
| 705 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 706 | ar = (AsyncResult) msg.obj; |
| 707 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 708 | if (ar.exception == null && ar.result != null) { |
| 709 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 710 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 711 | request.result = ""; |
| 712 | if (ar.result == null) { |
| 713 | loge("nvReadItem: Empty response"); |
| 714 | } else if (ar.exception instanceof CommandException) { |
| 715 | loge("nvReadItem: CommandException: " + |
| 716 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 717 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 718 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 719 | } |
| 720 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 721 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 722 | break; |
| 723 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 724 | case CMD_NV_WRITE_ITEM: |
| 725 | request = (MainThreadRequest) msg.obj; |
| 726 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 727 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 728 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 729 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 730 | break; |
| 731 | |
| 732 | case EVENT_NV_WRITE_ITEM_DONE: |
| 733 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 734 | break; |
| 735 | |
| 736 | case CMD_NV_WRITE_CDMA_PRL: |
| 737 | request = (MainThreadRequest) msg.obj; |
| 738 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 739 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 740 | break; |
| 741 | |
| 742 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 743 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 744 | break; |
| 745 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 746 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 747 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 748 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 749 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 750 | break; |
| 751 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 752 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 753 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 754 | break; |
| 755 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 756 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 757 | request = (MainThreadRequest) msg.obj; |
| 758 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 759 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 760 | break; |
| 761 | |
| 762 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 763 | ar = (AsyncResult) msg.obj; |
| 764 | request = (MainThreadRequest) ar.userObj; |
| 765 | if (ar.exception == null && ar.result != null) { |
| 766 | request.result = ar.result; // Integer |
| 767 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 768 | // request.result must be set to something non-null |
| 769 | // for the calling thread to unblock |
| 770 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 771 | if (ar.result == null) { |
| 772 | loge("getPreferredNetworkType: Empty response"); |
| 773 | } else if (ar.exception instanceof CommandException) { |
| 774 | loge("getPreferredNetworkType: CommandException: " + |
| 775 | ar.exception); |
| 776 | } else { |
| 777 | loge("getPreferredNetworkType: Unknown exception"); |
| 778 | } |
| 779 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 780 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 781 | break; |
| 782 | |
| 783 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 784 | request = (MainThreadRequest) msg.obj; |
| 785 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 786 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 787 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 788 | break; |
| 789 | |
| 790 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 791 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 792 | break; |
| 793 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 794 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 795 | request = (MainThreadRequest)msg.obj; |
| 796 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 797 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 798 | break; |
| 799 | |
| 800 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 801 | ar = (AsyncResult)msg.obj; |
| 802 | request = (MainThreadRequest)ar.userObj; |
| 803 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 804 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 805 | break; |
| 806 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 807 | case CMD_SET_VOICEMAIL_NUMBER: |
| 808 | request = (MainThreadRequest) msg.obj; |
| 809 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 810 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 811 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 812 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 813 | break; |
| 814 | |
| 815 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 816 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 817 | break; |
| 818 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 819 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 820 | request = (MainThreadRequest) msg.obj; |
| 821 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 822 | request); |
| 823 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 824 | break; |
| 825 | |
| 826 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 827 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 828 | break; |
| 829 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 830 | case CMD_PERFORM_NETWORK_SCAN: |
| 831 | request = (MainThreadRequest) msg.obj; |
| 832 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 833 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 834 | break; |
| 835 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 836 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 837 | request = (MainThreadRequest) msg.obj; |
| 838 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 839 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 840 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 841 | request.argument; |
| 842 | int callForwardingReason = args.first; |
| 843 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 844 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 845 | } |
| 846 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 847 | ar = (AsyncResult) msg.obj; |
| 848 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 849 | TelephonyManager.CallForwardingInfoCallback callback = |
| 850 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 851 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 852 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 853 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 854 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 855 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 856 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 857 | // any service for voice call. |
| 858 | if ((callForwardInfo.serviceClass |
| 859 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 860 | callForwardingInfo = new CallForwardingInfo(true, |
| 861 | callForwardInfo.reason, |
| 862 | callForwardInfo.number, |
| 863 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 864 | break; |
| 865 | } |
| 866 | } |
| 867 | // Didn't find a call forward info for voice call. |
| 868 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 869 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 870 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 871 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 872 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 873 | } else { |
| 874 | if (ar.result == null) { |
| 875 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 876 | } |
| 877 | if (ar.exception != null) { |
| 878 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 879 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 880 | int errorCode = CallForwardingInfo.ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 881 | if (ar.exception instanceof CommandException) { |
| 882 | CommandException.Error error = |
| 883 | ((CommandException) (ar.exception)).getCommandError(); |
| 884 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 885 | errorCode = CallForwardingInfo.ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 886 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 887 | errorCode = CallForwardingInfo.ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 888 | } |
| 889 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 890 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 891 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 892 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 893 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 894 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 895 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 896 | request = (MainThreadRequest) msg.obj; |
| 897 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 898 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 899 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 900 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 901 | request.argument).first; |
| 902 | request.phone.setCallForwardingOption( |
| 903 | callForwardingInfoToSet.isEnabled() |
| 904 | ? CommandsInterface.CF_ACTION_ENABLE |
| 905 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 906 | callForwardingInfoToSet.getReason(), |
| 907 | callForwardingInfoToSet.getNumber(), |
| 908 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 909 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 910 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 911 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 912 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 913 | ar = (AsyncResult) msg.obj; |
| 914 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 915 | Consumer<Integer> callback = |
| 916 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 917 | request.argument).second; |
| 918 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 919 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 920 | int errorCode = CallForwardingInfo.ERROR_UNKNOWN; |
| 921 | if (ar.exception instanceof CommandException) { |
| 922 | CommandException.Error error = |
| 923 | ((CommandException) (ar.exception)).getCommandError(); |
| 924 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 925 | errorCode = CallForwardingInfo.ERROR_FDN_CHECK_FAILURE; |
| 926 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 927 | errorCode = CallForwardingInfo.ERROR_NOT_SUPPORTED; |
| 928 | } |
| 929 | } |
| 930 | callback.accept(errorCode); |
| 931 | } else { |
| 932 | callback.accept(CallForwardingInfo.SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 933 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 934 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 935 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 936 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 937 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 938 | request = (MainThreadRequest) msg.obj; |
| 939 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 940 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 941 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 942 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 943 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 944 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 945 | ar = (AsyncResult) msg.obj; |
| 946 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 947 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 948 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 949 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 950 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 951 | // Service Class is a bit mask per 3gpp 27.007. |
| 952 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 953 | if (callForwardResults.length > 1 |
| 954 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 955 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 956 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 957 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 958 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 959 | } else { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 960 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 961 | } |
| 962 | } else { |
| 963 | if (ar.result == null) { |
| 964 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 965 | } |
| 966 | if (ar.exception != null) { |
| 967 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 968 | } |
| 969 | if (ar.exception instanceof CommandException) { |
| 970 | CommandException.Error error = |
| 971 | ((CommandException) (ar.exception)).getCommandError(); |
| 972 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 973 | callForwardingStatus = |
| 974 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 975 | } |
| 976 | } |
| 977 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 978 | callback.accept(callForwardingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 979 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 980 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 981 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 982 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 983 | request = (MainThreadRequest) msg.obj; |
| 984 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 985 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 986 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 987 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 988 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 989 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 990 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 991 | ar = (AsyncResult) msg.obj; |
| 992 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 993 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 994 | Consumer<Integer> callback = |
| 995 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 996 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 997 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 998 | if (ar.exception instanceof CommandException) { |
| 999 | CommandException.Error error = |
| 1000 | ((CommandException) (ar.exception)).getCommandError(); |
| 1001 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1002 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1003 | } else { |
| 1004 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1005 | } |
| 1006 | } else { |
| 1007 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1008 | } |
| 1009 | } else { |
| 1010 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1011 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1012 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1013 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1014 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1015 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1016 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1017 | ar = (AsyncResult) msg.obj; |
| 1018 | request = (MainThreadRequest) ar.userObj; |
| 1019 | CellNetworkScanResult cellScanResult; |
| 1020 | if (ar.exception == null && ar.result != null) { |
| 1021 | cellScanResult = new CellNetworkScanResult( |
| 1022 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1023 | (List<OperatorInfo>) ar.result); |
| 1024 | } else { |
| 1025 | if (ar.result == null) { |
| 1026 | loge("getCellNetworkScanResults: Empty response"); |
| 1027 | } |
| 1028 | if (ar.exception != null) { |
| 1029 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1030 | } |
| 1031 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1032 | if (ar.exception instanceof CommandException) { |
| 1033 | CommandException.Error error = |
| 1034 | ((CommandException) (ar.exception)).getCommandError(); |
| 1035 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1036 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1037 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1038 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1039 | } |
| 1040 | } |
| 1041 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1042 | } |
| 1043 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1044 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1045 | break; |
| 1046 | |
| 1047 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1048 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1049 | ManualNetworkSelectionArgument selArg = |
| 1050 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1051 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1052 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1053 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1054 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1055 | break; |
| 1056 | |
| 1057 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1058 | ar = (AsyncResult) msg.obj; |
| 1059 | request = (MainThreadRequest) ar.userObj; |
| 1060 | if (ar.exception == null) { |
| 1061 | request.result = true; |
| 1062 | } else { |
| 1063 | request.result = false; |
| 1064 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1065 | } |
| 1066 | notifyRequester(request); |
| 1067 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1068 | break; |
| 1069 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1070 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1071 | request = (MainThreadRequest) msg.obj; |
| 1072 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1073 | if (defaultPhone != null) { |
| 1074 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1075 | } else { |
| 1076 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1077 | Bundle bundle = new Bundle(); |
| 1078 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
| 1079 | new ModemActivityInfo(0, 0, 0, new int[0], 0)); |
| 1080 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1081 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1082 | break; |
| 1083 | |
| 1084 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 1085 | ar = (AsyncResult) msg.obj; |
| 1086 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1087 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1088 | |
| 1089 | ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1090 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1091 | // Update the last modem activity info and the result of the request. |
| 1092 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1093 | if (isModemActivityInfoValid(info)) { |
| 1094 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 1095 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1096 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1097 | .getTransmitTimeMillis(); |
| 1098 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1099 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1100 | } |
| 1101 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 1102 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1103 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1104 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1105 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1106 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1107 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1108 | info.getReceiveTimeMillis() |
| 1109 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1110 | } |
| 1111 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 1112 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1113 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1114 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1115 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1116 | } else { |
| 1117 | if (ar.result == null) { |
| 1118 | loge("queryModemActivityInfo: Empty response"); |
| 1119 | } else if (ar.exception instanceof CommandException) { |
| 1120 | loge("queryModemActivityInfo: CommandException: " + |
| 1121 | ar.exception); |
| 1122 | } else { |
| 1123 | loge("queryModemActivityInfo: Unknown exception"); |
| 1124 | } |
| 1125 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1126 | Bundle bundle = new Bundle(); |
| 1127 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1128 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1129 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1130 | break; |
| 1131 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1132 | case CMD_SET_ALLOWED_CARRIERS: |
| 1133 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1134 | CarrierRestrictionRules argument = |
| 1135 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1136 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1137 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1138 | break; |
| 1139 | |
| 1140 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1141 | ar = (AsyncResult) msg.obj; |
| 1142 | request = (MainThreadRequest) ar.userObj; |
| 1143 | if (ar.exception == null && ar.result != null) { |
| 1144 | request.result = ar.result; |
| 1145 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1146 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1147 | if (ar.exception instanceof CommandException) { |
| 1148 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1149 | CommandException.Error error = |
| 1150 | ((CommandException) (ar.exception)).getCommandError(); |
| 1151 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1152 | request.result = |
| 1153 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1154 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1155 | } else { |
| 1156 | loge("setAllowedCarriers: Unknown exception"); |
| 1157 | } |
| 1158 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1159 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1160 | break; |
| 1161 | |
| 1162 | case CMD_GET_ALLOWED_CARRIERS: |
| 1163 | request = (MainThreadRequest) msg.obj; |
| 1164 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1165 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1166 | break; |
| 1167 | |
| 1168 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1169 | ar = (AsyncResult) msg.obj; |
| 1170 | request = (MainThreadRequest) ar.userObj; |
| 1171 | if (ar.exception == null && ar.result != null) { |
| 1172 | request.result = ar.result; |
| 1173 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1174 | request.result = new IllegalStateException( |
| 1175 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1176 | if (ar.result == null) { |
| 1177 | loge("getAllowedCarriers: Empty response"); |
| 1178 | } else if (ar.exception instanceof CommandException) { |
| 1179 | loge("getAllowedCarriers: CommandException: " + |
| 1180 | ar.exception); |
| 1181 | } else { |
| 1182 | loge("getAllowedCarriers: Unknown exception"); |
| 1183 | } |
| 1184 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1185 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1186 | break; |
| 1187 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1188 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1189 | ar = (AsyncResult) msg.obj; |
| 1190 | request = (MainThreadRequest) ar.userObj; |
| 1191 | if (ar.exception == null && ar.result != null) { |
| 1192 | request.result = ar.result; |
| 1193 | } else { |
| 1194 | request.result = new IllegalArgumentException( |
| 1195 | "Failed to retrieve Forbidden Plmns"); |
| 1196 | if (ar.result == null) { |
| 1197 | loge("getForbiddenPlmns: Empty response"); |
| 1198 | } else { |
| 1199 | loge("getForbiddenPlmns: Unknown exception"); |
| 1200 | } |
| 1201 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1202 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1203 | break; |
| 1204 | |
| 1205 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1206 | request = (MainThreadRequest) msg.obj; |
| 1207 | uiccCard = getUiccCardFromRequest(request); |
| 1208 | if (uiccCard == null) { |
| 1209 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1210 | request.result = new IllegalArgumentException( |
| 1211 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1212 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1213 | break; |
| 1214 | } |
| 1215 | Integer appType = (Integer) request.argument; |
| 1216 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1217 | if (uiccApp == null) { |
| 1218 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1219 | + appType); |
| 1220 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1221 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1222 | break; |
| 1223 | } else { |
| 1224 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1225 | + " specified type -- " + appType); |
| 1226 | } |
| 1227 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1228 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1229 | onCompleted); |
| 1230 | break; |
| 1231 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1232 | case CMD_SWITCH_SLOTS: |
| 1233 | request = (MainThreadRequest) msg.obj; |
| 1234 | int[] physicalSlots = (int[]) request.argument; |
| 1235 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1236 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1237 | break; |
| 1238 | |
| 1239 | case EVENT_SWITCH_SLOTS_DONE: |
| 1240 | ar = (AsyncResult) msg.obj; |
| 1241 | request = (MainThreadRequest) ar.userObj; |
| 1242 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1243 | notifyRequester(request); |
| 1244 | break; |
| 1245 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1246 | request = (MainThreadRequest) msg.obj; |
| 1247 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1248 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1249 | break; |
| 1250 | |
| 1251 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1252 | ar = (AsyncResult) msg.obj; |
| 1253 | request = (MainThreadRequest) ar.userObj; |
| 1254 | if (ar.exception != null) { |
| 1255 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1256 | } else { |
| 1257 | int mode = ((int[]) ar.result)[0]; |
| 1258 | if (mode == 0) { |
| 1259 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1260 | } else { |
| 1261 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1262 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1263 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1264 | notifyRequester(request); |
| 1265 | break; |
| 1266 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1267 | request = (MainThreadRequest) msg.obj; |
| 1268 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1269 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1270 | break; |
| 1271 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1272 | ar = (AsyncResult) msg.obj; |
| 1273 | request = (MainThreadRequest) ar.userObj; |
| 1274 | if (ar.exception != null) { |
| 1275 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1276 | } else { |
| 1277 | request.result = ((int[]) ar.result)[0]; |
| 1278 | } |
| 1279 | notifyRequester(request); |
| 1280 | break; |
| 1281 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1282 | request = (MainThreadRequest) msg.obj; |
| 1283 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1284 | int mode = (int) request.argument; |
| 1285 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1286 | break; |
| 1287 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1288 | ar = (AsyncResult) msg.obj; |
| 1289 | request = (MainThreadRequest) ar.userObj; |
| 1290 | request.result = ar.exception == null; |
| 1291 | notifyRequester(request); |
| 1292 | break; |
| 1293 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1294 | request = (MainThreadRequest) msg.obj; |
| 1295 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1296 | int subscriptionMode = (int) request.argument; |
| 1297 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1298 | break; |
| 1299 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1300 | ar = (AsyncResult) msg.obj; |
| 1301 | request = (MainThreadRequest) ar.userObj; |
| 1302 | request.result = ar.exception == null; |
| 1303 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1304 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1305 | case CMD_GET_ALL_CELL_INFO: |
| 1306 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1307 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1308 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1309 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1310 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1311 | ar = (AsyncResult) msg.obj; |
| 1312 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1313 | // If a timeout occurs, the response will be null |
| 1314 | request.result = (ar.exception == null && ar.result != null) |
| 1315 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1316 | synchronized (request) { |
| 1317 | request.notifyAll(); |
| 1318 | } |
| 1319 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1320 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1321 | request = (MainThreadRequest) msg.obj; |
| 1322 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1323 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1324 | break; |
| 1325 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1326 | ar = (AsyncResult) msg.obj; |
| 1327 | request = (MainThreadRequest) ar.userObj; |
| 1328 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1329 | try { |
| 1330 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1331 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1332 | cb.onError( |
| 1333 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1334 | ar.exception.getClass().getName(), |
| 1335 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1336 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1337 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1338 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1339 | } else { |
| 1340 | // use the result as returned |
| 1341 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1342 | } |
| 1343 | } catch (RemoteException re) { |
| 1344 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1345 | } |
| 1346 | break; |
| 1347 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1348 | request = (MainThreadRequest) msg.obj; |
| 1349 | WorkSource ws = (WorkSource) request.argument; |
| 1350 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1351 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1352 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1353 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1354 | ar = (AsyncResult) msg.obj; |
| 1355 | request = (MainThreadRequest) ar.userObj; |
| 1356 | if (ar.exception == null) { |
| 1357 | request.result = ar.result; |
| 1358 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1359 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1360 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1361 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1362 | } |
| 1363 | |
| 1364 | synchronized (request) { |
| 1365 | request.notifyAll(); |
| 1366 | } |
| 1367 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1368 | case CMD_MODEM_REBOOT: |
| 1369 | request = (MainThreadRequest) msg.obj; |
| 1370 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1371 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1372 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1373 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1374 | handleNullReturnEvent(msg, "rebootModem"); |
| 1375 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1376 | case CMD_REQUEST_ENABLE_MODEM: |
| 1377 | request = (MainThreadRequest) msg.obj; |
| 1378 | boolean enable = (boolean) request.argument; |
| 1379 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1380 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1381 | PhoneConfigurationManager.getInstance() |
| 1382 | .enablePhone(request.phone, enable, onCompleted); |
| 1383 | break; |
| 1384 | case EVENT_ENABLE_MODEM_DONE: |
| 1385 | ar = (AsyncResult) msg.obj; |
| 1386 | request = (MainThreadRequest) ar.userObj; |
| 1387 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1388 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1389 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1390 | if ((boolean) request.result) { |
| 1391 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1392 | updateModemStateMetrics(); |
| 1393 | } else { |
| 1394 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1395 | + ar.exception); |
| 1396 | } |
| 1397 | notifyRequester(request); |
| 1398 | break; |
| 1399 | case CMD_GET_MODEM_STATUS: |
| 1400 | request = (MainThreadRequest) msg.obj; |
| 1401 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1402 | PhoneConfigurationManager.getInstance() |
| 1403 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1404 | break; |
| 1405 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1406 | ar = (AsyncResult) msg.obj; |
| 1407 | request = (MainThreadRequest) ar.userObj; |
| 1408 | int id = request.phone.getPhoneId(); |
| 1409 | if (ar.exception == null && ar.result != null) { |
| 1410 | request.result = ar.result; |
| 1411 | //update the cache as modem status has changed |
| 1412 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1413 | (boolean) request.result); |
| 1414 | } else { |
| 1415 | // Return true if modem status cannot be retrieved. For most cases, |
| 1416 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1417 | // and disable modem are not supported. Modem is always on. |
| 1418 | // TODO: this should be fixed in R to support a third |
| 1419 | // status UNKNOWN b/131631629 |
| 1420 | request.result = true; |
| 1421 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1422 | + ar.exception); |
| 1423 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1424 | notifyRequester(request); |
| 1425 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1426 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1427 | request = (MainThreadRequest) msg.obj; |
| 1428 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1429 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1430 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1431 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1432 | break; |
| 1433 | } |
| 1434 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1435 | ar = (AsyncResult) msg.obj; |
| 1436 | request = (MainThreadRequest) ar.userObj; |
| 1437 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1438 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1439 | args.second.accept(ar.exception == null); |
| 1440 | notifyRequester(request); |
| 1441 | break; |
| 1442 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1443 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1444 | ar = (AsyncResult) msg.obj; |
| 1445 | request = (MainThreadRequest) ar.userObj; |
| 1446 | if (ar.exception == null && ar.result != null) { |
| 1447 | request.result = ar.result; |
| 1448 | } else { |
| 1449 | request.result = -1; |
| 1450 | loge("Failed to set Forbidden Plmns"); |
| 1451 | if (ar.result == null) { |
| 1452 | loge("setForbidenPlmns: Empty response"); |
| 1453 | } else if (ar.exception != null) { |
| 1454 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1455 | request.result = -1; |
| 1456 | } else { |
| 1457 | loge("setForbiddenPlmns: Unknown exception"); |
| 1458 | } |
| 1459 | } |
| 1460 | notifyRequester(request); |
| 1461 | break; |
| 1462 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1463 | request = (MainThreadRequest) msg.obj; |
| 1464 | uiccCard = getUiccCardFromRequest(request); |
| 1465 | if (uiccCard == null) { |
| 1466 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1467 | request.result = -1; |
| 1468 | notifyRequester(request); |
| 1469 | break; |
| 1470 | } |
| 1471 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1472 | (Pair<Integer, List<String>>) request.argument; |
| 1473 | appType = setFplmnsArgs.first; |
| 1474 | List<String> fplmns = setFplmnsArgs.second; |
| 1475 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1476 | if (uiccApp == null) { |
| 1477 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1478 | request.result = -1; |
| 1479 | loge("Failed to get UICC App"); |
| 1480 | notifyRequester(request); |
| 1481 | } else { |
| 1482 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1483 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1484 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1485 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1486 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1487 | case CMD_ERASE_MODEM_CONFIG: |
| 1488 | request = (MainThreadRequest) msg.obj; |
| 1489 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1490 | defaultPhone.eraseModemConfig(onCompleted); |
| 1491 | break; |
| 1492 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1493 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1494 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1495 | |
| 1496 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1497 | request = (MainThreadRequest) msg.obj; |
| 1498 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1499 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1500 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1501 | changed.first, changed.second, onCompleted); |
| 1502 | break; |
| 1503 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1504 | ar = (AsyncResult) msg.obj; |
| 1505 | request = (MainThreadRequest) ar.userObj; |
| 1506 | if (ar.exception == null) { |
| 1507 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1508 | } else { |
| 1509 | request.result = msg.arg1; |
| 1510 | } |
| 1511 | notifyRequester(request); |
| 1512 | break; |
| 1513 | |
| 1514 | case CMD_SET_ICC_LOCK_ENABLED: |
| 1515 | request = (MainThreadRequest) msg.obj; |
| 1516 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1517 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1518 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1519 | enabled.first, enabled.second, onCompleted); |
| 1520 | break; |
| 1521 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1522 | ar = (AsyncResult) msg.obj; |
| 1523 | request = (MainThreadRequest) ar.userObj; |
| 1524 | if (ar.exception == null) { |
| 1525 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1526 | } else { |
| 1527 | request.result = msg.arg1; |
| 1528 | } |
| 1529 | notifyRequester(request); |
| 1530 | break; |
| 1531 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1532 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1533 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1534 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1535 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1536 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1537 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1538 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1539 | default: |
| 1540 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1541 | break; |
| 1542 | } |
| 1543 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1544 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1545 | private void notifyRequester(MainThreadRequest request) { |
| 1546 | synchronized (request) { |
| 1547 | request.notifyAll(); |
| 1548 | } |
| 1549 | } |
| 1550 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1551 | private void handleNullReturnEvent(Message msg, String command) { |
| 1552 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1553 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1554 | if (ar.exception == null) { |
| 1555 | request.result = true; |
| 1556 | } else { |
| 1557 | request.result = false; |
| 1558 | if (ar.exception instanceof CommandException) { |
| 1559 | loge(command + ": CommandException: " + ar.exception); |
| 1560 | } else { |
| 1561 | loge(command + ": Unknown exception"); |
| 1562 | } |
| 1563 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1564 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1565 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1566 | } |
| 1567 | |
| 1568 | /** |
| 1569 | * Posts the specified command to be executed on the main thread, |
| 1570 | * waits for the request to complete, and returns the result. |
| 1571 | * @see #sendRequestAsync |
| 1572 | */ |
| 1573 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1574 | return sendRequest( |
| 1575 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1576 | } |
| 1577 | |
| 1578 | /** |
| 1579 | * Posts the specified command to be executed on the main thread, |
| 1580 | * waits for the request to complete, and returns the result. |
| 1581 | * @see #sendRequestAsync |
| 1582 | */ |
| 1583 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1584 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1585 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1586 | } |
| 1587 | |
| 1588 | /** |
| 1589 | * Posts the specified command to be executed on the main thread, |
| 1590 | * waits for the request to complete, and returns the result. |
| 1591 | * @see #sendRequestAsync |
| 1592 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1593 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1594 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1595 | } |
| 1596 | |
| 1597 | /** |
| 1598 | * Posts the specified command to be executed on the main thread, |
| 1599 | * waits for the request to complete, and returns the result. |
| 1600 | * @see #sendRequestAsync |
| 1601 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1602 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1603 | return sendRequest(command, argument, subId, null, workSource); |
| 1604 | } |
| 1605 | |
| 1606 | /** |
| 1607 | * Posts the specified command to be executed on the main thread, |
| 1608 | * waits for the request to complete, and returns the result. |
| 1609 | * @see #sendRequestAsync |
| 1610 | */ |
| 1611 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1612 | return sendRequest( |
| 1613 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1614 | } |
| 1615 | |
| 1616 | /** |
| 1617 | * Posts the specified command to be executed on the main thread, |
| 1618 | * waits for the request to complete, and returns the result. |
| 1619 | * @see #sendRequestAsync |
| 1620 | */ |
| 1621 | private Object sendRequest( |
| 1622 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1623 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1624 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1625 | } |
| 1626 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1627 | MainThreadRequest request = null; |
| 1628 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1629 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1630 | } else if (phone != null) { |
| 1631 | request = new MainThreadRequest(argument, phone, workSource); |
| 1632 | } else { |
| 1633 | request = new MainThreadRequest(argument, subId, workSource); |
| 1634 | } |
| 1635 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1636 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1637 | msg.sendToTarget(); |
| 1638 | |
| 1639 | // Wait for the request to complete |
| 1640 | synchronized (request) { |
| 1641 | while (request.result == null) { |
| 1642 | try { |
| 1643 | request.wait(); |
| 1644 | } catch (InterruptedException e) { |
| 1645 | // Do nothing, go back and wait until the request is complete |
| 1646 | } |
| 1647 | } |
| 1648 | } |
| 1649 | return request.result; |
| 1650 | } |
| 1651 | |
| 1652 | /** |
| 1653 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1654 | * Posts the specified command to be executed on the main thread, and |
| 1655 | * returns immediately. |
| 1656 | * @see #sendRequest |
| 1657 | */ |
| 1658 | private void sendRequestAsync(int command) { |
| 1659 | mMainThreadHandler.sendEmptyMessage(command); |
| 1660 | } |
| 1661 | |
| 1662 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1663 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1664 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1665 | */ |
| 1666 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1667 | sendRequestAsync(command, argument, null, null); |
| 1668 | } |
| 1669 | |
| 1670 | /** |
| 1671 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1672 | * @see {@link #sendRequest(int,Object)} |
| 1673 | */ |
| 1674 | private void sendRequestAsync( |
| 1675 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1676 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1677 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1678 | msg.sendToTarget(); |
| 1679 | } |
| 1680 | |
| 1681 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1682 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1683 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1684 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1685 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1686 | synchronized (PhoneInterfaceManager.class) { |
| 1687 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1688 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1689 | } else { |
| 1690 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1691 | } |
| 1692 | return sInstance; |
| 1693 | } |
| 1694 | } |
| 1695 | |
| 1696 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 1697 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1698 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1699 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1700 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1701 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1702 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1703 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1704 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1705 | mTelephonySharedPreferences = |
| 1706 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1707 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1708 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 1709 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1710 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1711 | publish(); |
| 1712 | } |
| 1713 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1714 | private Phone getDefaultPhone() { |
| 1715 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1716 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1717 | } |
| 1718 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1719 | private void publish() { |
| 1720 | if (DBG) log("publish: " + this); |
| 1721 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 1722 | TelephonyFrameworkInitializer |
| 1723 | .getTelephonyServiceManager() |
| 1724 | .getTelephonyServiceRegisterer() |
| 1725 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1726 | } |
| 1727 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1728 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1729 | if (request.phone != null) { |
| 1730 | return request.phone; |
| 1731 | } else { |
| 1732 | return getPhoneFromSubId(request.subId); |
| 1733 | } |
| 1734 | } |
| 1735 | |
| 1736 | private Phone getPhoneFromSubId(int subId) { |
| 1737 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1738 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1739 | } |
| 1740 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1741 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1742 | Phone phone = getPhoneFromRequest(request); |
| 1743 | return phone == null ? null : |
| 1744 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1745 | } |
| 1746 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1747 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1748 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1749 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1750 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1751 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1752 | private void sendEraseModemConfig(Phone phone) { |
| 1753 | if (phone != null) { |
| 1754 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 1755 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 1756 | final long identity = Binder.clearCallingIdentity(); |
| 1757 | try { |
| 1758 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 1759 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 1760 | } finally { |
| 1761 | Binder.restoreCallingIdentity(identity); |
| 1762 | } |
| 1763 | } |
| 1764 | } |
| 1765 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 1766 | private boolean isImsAvailableOnDevice() { |
| 1767 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 1768 | if (pm == null) { |
| 1769 | // For some reason package manger is not available.. This will fail internally anyway, |
| 1770 | // so do not throw error and allow. |
| 1771 | return true; |
| 1772 | } |
| 1773 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 1774 | } |
| 1775 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1776 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1777 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1778 | } |
| 1779 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1780 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1781 | if (DBG) log("dial: " + number); |
| 1782 | // No permission check needed here: This is just a wrapper around the |
| 1783 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1784 | // the UI before it does anything. |
| 1785 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1786 | final long identity = Binder.clearCallingIdentity(); |
| 1787 | try { |
| 1788 | String url = createTelUrl(number); |
| 1789 | if (url == null) { |
| 1790 | return; |
| 1791 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1792 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1793 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1794 | PhoneConstants.State state = mCM.getState(subId); |
| 1795 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1796 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1797 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1798 | mApp.startActivity(intent); |
| 1799 | } |
| 1800 | } finally { |
| 1801 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1802 | } |
| 1803 | } |
| 1804 | |
| 1805 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1806 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1807 | } |
| 1808 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1809 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1810 | if (DBG) log("call: " + number); |
| 1811 | |
| 1812 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1813 | // need to do a permission check since we're calling startActivity() |
| 1814 | // from the context of the phone app. |
| 1815 | enforceCallPermission(); |
| 1816 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 1817 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1818 | != AppOpsManager.MODE_ALLOWED) { |
| 1819 | return; |
| 1820 | } |
| 1821 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1822 | final long identity = Binder.clearCallingIdentity(); |
| 1823 | try { |
| 1824 | String url = createTelUrl(number); |
| 1825 | if (url == null) { |
| 1826 | return; |
| 1827 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1828 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1829 | boolean isValid = false; |
| 1830 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1831 | if (slist != null) { |
| 1832 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1833 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1834 | isValid = true; |
| 1835 | break; |
| 1836 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1837 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1838 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1839 | if (!isValid) { |
| 1840 | return; |
| 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 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1844 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1845 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1846 | mApp.startActivity(intent); |
| 1847 | } finally { |
| 1848 | Binder.restoreCallingIdentity(identity); |
| 1849 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1850 | } |
| 1851 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1852 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1853 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1854 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1855 | } |
| 1856 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1857 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1858 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1859 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1860 | } |
| 1861 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1862 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1863 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1864 | |
| 1865 | final long identity = Binder.clearCallingIdentity(); |
| 1866 | try { |
| 1867 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1868 | checkSimPin.start(); |
| 1869 | return checkSimPin.unlockSim(null, pin); |
| 1870 | } finally { |
| 1871 | Binder.restoreCallingIdentity(identity); |
| 1872 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1873 | } |
| 1874 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1875 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1876 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1877 | |
| 1878 | final long identity = Binder.clearCallingIdentity(); |
| 1879 | try { |
| 1880 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1881 | checkSimPuk.start(); |
| 1882 | return checkSimPuk.unlockSim(puk, pin); |
| 1883 | } finally { |
| 1884 | Binder.restoreCallingIdentity(identity); |
| 1885 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1886 | } |
| 1887 | |
| 1888 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1889 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1890 | * a synchronous one. |
| 1891 | */ |
| 1892 | private static class UnlockSim extends Thread { |
| 1893 | |
| 1894 | private final IccCard mSimCard; |
| 1895 | |
| 1896 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1897 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1898 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1899 | |
| 1900 | // For replies from SimCard interface |
| 1901 | private Handler mHandler; |
| 1902 | |
| 1903 | // For async handler to identify request type |
| 1904 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1905 | |
| 1906 | public UnlockSim(IccCard simCard) { |
| 1907 | mSimCard = simCard; |
| 1908 | } |
| 1909 | |
| 1910 | @Override |
| 1911 | public void run() { |
| 1912 | Looper.prepare(); |
| 1913 | synchronized (UnlockSim.this) { |
| 1914 | mHandler = new Handler() { |
| 1915 | @Override |
| 1916 | public void handleMessage(Message msg) { |
| 1917 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1918 | switch (msg.what) { |
| 1919 | case SUPPLY_PIN_COMPLETE: |
| 1920 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1921 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1922 | mRetryCount = msg.arg1; |
| 1923 | if (ar.exception != null) { |
| 1924 | if (ar.exception instanceof CommandException && |
| 1925 | ((CommandException)(ar.exception)).getCommandError() |
| 1926 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1927 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 1928 | } //When UiccCardApp dispose,handle message and return exception |
| 1929 | else if (ar.exception instanceof CommandException && |
| 1930 | ((CommandException) (ar.exception)).getCommandError() |
| 1931 | == CommandException.Error.ABORTED) { |
| 1932 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1933 | } else { |
| 1934 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1935 | } |
| 1936 | } else { |
| 1937 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1938 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1939 | mDone = true; |
| 1940 | UnlockSim.this.notifyAll(); |
| 1941 | } |
| 1942 | break; |
| 1943 | } |
| 1944 | } |
| 1945 | }; |
| 1946 | UnlockSim.this.notifyAll(); |
| 1947 | } |
| 1948 | Looper.loop(); |
| 1949 | } |
| 1950 | |
| 1951 | /* |
| 1952 | * Use PIN or PUK to unlock SIM card |
| 1953 | * |
| 1954 | * If PUK is null, unlock SIM card with PIN |
| 1955 | * |
| 1956 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1957 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1958 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1959 | |
| 1960 | while (mHandler == null) { |
| 1961 | try { |
| 1962 | wait(); |
| 1963 | } catch (InterruptedException e) { |
| 1964 | Thread.currentThread().interrupt(); |
| 1965 | } |
| 1966 | } |
| 1967 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1968 | |
| 1969 | if (puk == null) { |
| 1970 | mSimCard.supplyPin(pin, callback); |
| 1971 | } else { |
| 1972 | mSimCard.supplyPuk(puk, pin, callback); |
| 1973 | } |
| 1974 | |
| 1975 | while (!mDone) { |
| 1976 | try { |
| 1977 | Log.d(LOG_TAG, "wait for done"); |
| 1978 | wait(); |
| 1979 | } catch (InterruptedException e) { |
| 1980 | // Restore the interrupted status |
| 1981 | Thread.currentThread().interrupt(); |
| 1982 | } |
| 1983 | } |
| 1984 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1985 | int[] resultArray = new int[2]; |
| 1986 | resultArray[0] = mResult; |
| 1987 | resultArray[1] = mRetryCount; |
| 1988 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1989 | } |
| 1990 | } |
| 1991 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 1992 | /** |
| 1993 | * This method has been removed due to privacy and stability concerns. |
| 1994 | */ |
| 1995 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1996 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 1997 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 1998 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1999 | } |
| 2000 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2001 | @Override |
| 2002 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2003 | mApp.getSystemService(AppOpsManager.class) |
| 2004 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2005 | |
| 2006 | final int targetSdk = getTargetSdk(callingPackage); |
| 2007 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2008 | // Callers targeting S have no business invoking this method. |
| 2009 | return; |
| 2010 | } |
| 2011 | |
| 2012 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2013 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2014 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2015 | .setCallingPackage(callingPackage) |
| 2016 | .setCallingFeatureId(null) |
| 2017 | .setCallingPid(Binder.getCallingPid()) |
| 2018 | .setCallingUid(Binder.getCallingUid()) |
| 2019 | .setMethod("updateServiceLocation") |
| 2020 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2021 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2022 | .build()); |
| 2023 | // Apps that lack location permission have no business calling this method; |
| 2024 | // however, because no permission was declared in the public API, denials must |
| 2025 | // all be "soft". |
| 2026 | switch (locationResult) { |
| 2027 | case DENIED_HARD: /* fall through */ |
| 2028 | case DENIED_SOFT: |
| 2029 | return; |
| 2030 | } |
| 2031 | |
| 2032 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2033 | final long identity = Binder.clearCallingIdentity(); |
| 2034 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2035 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2036 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2037 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2038 | } |
| 2039 | } finally { |
| 2040 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2041 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2042 | } |
| 2043 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2044 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2045 | @Override |
| 2046 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2047 | return isRadioOnWithFeature(callingPackage, null); |
| 2048 | } |
| 2049 | |
| 2050 | |
| 2051 | @Override |
| 2052 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2053 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2054 | callingFeatureId); |
| 2055 | } |
| 2056 | |
| 2057 | @Deprecated |
| 2058 | @Override |
| 2059 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2060 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2061 | } |
| 2062 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2063 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2064 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2065 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2066 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2067 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2068 | return false; |
| 2069 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2070 | |
| 2071 | final long identity = Binder.clearCallingIdentity(); |
| 2072 | try { |
| 2073 | return isRadioOnForSubscriber(subId); |
| 2074 | } finally { |
| 2075 | Binder.restoreCallingIdentity(identity); |
| 2076 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2077 | } |
| 2078 | |
| 2079 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2080 | final long identity = Binder.clearCallingIdentity(); |
| 2081 | try { |
| 2082 | final Phone phone = getPhone(subId); |
| 2083 | if (phone != null) { |
| 2084 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2085 | } else { |
| 2086 | return false; |
| 2087 | } |
| 2088 | } finally { |
| 2089 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2090 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2091 | } |
| 2092 | |
| 2093 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2094 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2095 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2096 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2097 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2098 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2099 | |
| 2100 | final long identity = Binder.clearCallingIdentity(); |
| 2101 | try { |
| 2102 | final Phone phone = getPhone(subId); |
| 2103 | if (phone != null) { |
| 2104 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2105 | } |
| 2106 | } finally { |
| 2107 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2108 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2109 | } |
| 2110 | |
| 2111 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2112 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2113 | } |
| 2114 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2115 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2116 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2117 | |
| 2118 | final long identity = Binder.clearCallingIdentity(); |
| 2119 | try { |
| 2120 | final Phone phone = getPhone(subId); |
| 2121 | if (phone == null) { |
| 2122 | return false; |
| 2123 | } |
| 2124 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2125 | toggleRadioOnOffForSubscriber(subId); |
| 2126 | } |
| 2127 | return true; |
| 2128 | } finally { |
| 2129 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2130 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2131 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2132 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2133 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2134 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2135 | /* |
| 2136 | * If any of the Radios are available, it will need to be |
| 2137 | * shutdown. So return true if any Radio is available. |
| 2138 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2139 | final long identity = Binder.clearCallingIdentity(); |
| 2140 | try { |
| 2141 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2142 | Phone phone = PhoneFactory.getPhone(i); |
| 2143 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2144 | } |
| 2145 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2146 | return false; |
| 2147 | } finally { |
| 2148 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2149 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2150 | } |
| 2151 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2152 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2153 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2154 | enforceModifyPermission(); |
| 2155 | |
| 2156 | final long identity = Binder.clearCallingIdentity(); |
| 2157 | try { |
| 2158 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2159 | logv("Shutting down Phone " + i); |
| 2160 | shutdownRadioUsingPhoneId(i); |
| 2161 | } |
| 2162 | } finally { |
| 2163 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2164 | } |
| 2165 | } |
| 2166 | |
| 2167 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2168 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2169 | if (phone != null && phone.isRadioAvailable()) { |
| 2170 | phone.shutdownRadio(); |
| 2171 | } |
| 2172 | } |
| 2173 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2174 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2175 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2176 | |
| 2177 | final long identity = Binder.clearCallingIdentity(); |
| 2178 | try { |
| 2179 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2180 | if (defaultPhone != null) { |
| 2181 | defaultPhone.setRadioPower(turnOn); |
| 2182 | return true; |
| 2183 | } else { |
| 2184 | loge("There's no default phone."); |
| 2185 | return false; |
| 2186 | } |
| 2187 | } finally { |
| 2188 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2189 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2190 | } |
| 2191 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2192 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2193 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2194 | |
| 2195 | final long identity = Binder.clearCallingIdentity(); |
| 2196 | try { |
| 2197 | final Phone phone = getPhone(subId); |
| 2198 | if (phone != null) { |
| 2199 | phone.setRadioPower(turnOn); |
| 2200 | return true; |
| 2201 | } else { |
| 2202 | return false; |
| 2203 | } |
| 2204 | } finally { |
| 2205 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2206 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2207 | } |
| 2208 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2209 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2210 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2211 | public boolean enableDataConnectivity() { |
| 2212 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2213 | |
| 2214 | final long identity = Binder.clearCallingIdentity(); |
| 2215 | try { |
| 2216 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2217 | final Phone phone = getPhone(subId); |
| 2218 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2219 | phone.getDataEnabledSettings().setDataEnabled( |
| 2220 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2221 | return true; |
| 2222 | } else { |
| 2223 | return false; |
| 2224 | } |
| 2225 | } finally { |
| 2226 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2227 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2228 | } |
| 2229 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2230 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2231 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2232 | public boolean disableDataConnectivity() { |
| 2233 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2234 | |
| 2235 | final long identity = Binder.clearCallingIdentity(); |
| 2236 | try { |
| 2237 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2238 | final Phone phone = getPhone(subId); |
| 2239 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2240 | phone.getDataEnabledSettings().setDataEnabled( |
| 2241 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2242 | return true; |
| 2243 | } else { |
| 2244 | return false; |
| 2245 | } |
| 2246 | } finally { |
| 2247 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2248 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2249 | } |
| 2250 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2251 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2252 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2253 | final long identity = Binder.clearCallingIdentity(); |
| 2254 | try { |
| 2255 | final Phone phone = getPhone(subId); |
| 2256 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2257 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2258 | } else { |
| 2259 | return false; |
| 2260 | } |
| 2261 | } finally { |
| 2262 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2263 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2264 | } |
| 2265 | |
| 2266 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2267 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2268 | } |
| 2269 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2270 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2271 | enforceCallPermission(); |
| 2272 | |
| 2273 | final long identity = Binder.clearCallingIdentity(); |
| 2274 | try { |
| 2275 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2276 | return; |
| 2277 | } |
| 2278 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2279 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2280 | } finally { |
| 2281 | Binder.restoreCallingIdentity(identity); |
| 2282 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2283 | }; |
| 2284 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2285 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2286 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2287 | |
| 2288 | final long identity = Binder.clearCallingIdentity(); |
| 2289 | try { |
| 2290 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2291 | return false; |
| 2292 | } |
| 2293 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2294 | } finally { |
| 2295 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2296 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2297 | } |
| 2298 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2299 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2300 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2301 | } |
| 2302 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2303 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2304 | final long identity = Binder.clearCallingIdentity(); |
| 2305 | try { |
| 2306 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2307 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2308 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2309 | } finally { |
| 2310 | Binder.restoreCallingIdentity(identity); |
| 2311 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2312 | } |
| 2313 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2314 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2315 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2316 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2317 | } |
| 2318 | |
| 2319 | @Override |
| 2320 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2321 | final long identity = Binder.clearCallingIdentity(); |
| 2322 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2323 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2324 | if (phone != null) { |
| 2325 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2326 | } else { |
| 2327 | return PhoneConstantConversions.convertDataState( |
| 2328 | PhoneConstants.DataState.DISCONNECTED); |
| 2329 | } |
| 2330 | } finally { |
| 2331 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2332 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2333 | } |
| 2334 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2335 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2336 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2337 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2338 | } |
| 2339 | |
| 2340 | @Override |
| 2341 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2342 | final long identity = Binder.clearCallingIdentity(); |
| 2343 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2344 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2345 | if (phone != null) { |
| 2346 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2347 | } else { |
| 2348 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2349 | } |
| 2350 | } finally { |
| 2351 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2352 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2353 | } |
| 2354 | |
| 2355 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2356 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2357 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2358 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2359 | |
| 2360 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2361 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2362 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2363 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2364 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2365 | .setCallingPid(Binder.getCallingPid()) |
| 2366 | .setCallingUid(Binder.getCallingUid()) |
| 2367 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2368 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2369 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2370 | .build()); |
| 2371 | switch (locationResult) { |
| 2372 | case DENIED_HARD: |
| 2373 | throw new SecurityException("Not allowed to access cell location"); |
| 2374 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2375 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2376 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2377 | } |
| 2378 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2379 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2380 | final long identity = Binder.clearCallingIdentity(); |
| 2381 | try { |
| 2382 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2383 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2384 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2385 | } finally { |
| 2386 | Binder.restoreCallingIdentity(identity); |
| 2387 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2388 | } |
| 2389 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2390 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2391 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2392 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2393 | // registered cell info, so return a NULL country instead. |
| 2394 | final long identity = Binder.clearCallingIdentity(); |
| 2395 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2396 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2397 | // Get default phone in this case. |
| 2398 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2399 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2400 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2401 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2402 | if (phone == null) return ""; |
| 2403 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2404 | if (sst == null) return ""; |
| 2405 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2406 | if (lt == null) return ""; |
| 2407 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry(); |
| 2408 | EmergencyNumberTracker ent = phone.getEmergencyNumberTracker(); |
| 2409 | return (ent == null) ? "" : ent.getEmergencyCountryIso(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2410 | } finally { |
| 2411 | Binder.restoreCallingIdentity(identity); |
| 2412 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2413 | } |
| 2414 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2415 | /** |
| 2416 | * This method was removed due to potential issues caused by performing partial |
| 2417 | * updates of service state, and lack of a credible use case. |
| 2418 | * |
| 2419 | * This has the ability to break the telephony implementation by disabling notification of |
| 2420 | * changes in device connectivity. DO NOT USE THIS! |
| 2421 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2422 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2423 | public void enableLocationUpdates() { |
| 2424 | mApp.enforceCallingOrSelfPermission( |
| 2425 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2426 | } |
| 2427 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2428 | /** |
| 2429 | * This method was removed due to potential issues caused by performing partial |
| 2430 | * updates of service state, and lack of a credible use case. |
| 2431 | * |
| 2432 | * This has the ability to break the telephony implementation by disabling notification of |
| 2433 | * changes in device connectivity. DO NOT USE THIS! |
| 2434 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2435 | @Override |
| 2436 | public void disableLocationUpdates() { |
| 2437 | mApp.enforceCallingOrSelfPermission( |
| 2438 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2439 | } |
| 2440 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2441 | /** |
| 2442 | * Returns the target SDK version number for a given package name. |
| 2443 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2444 | * This call MUST be invoked before clearing the calling UID. |
| 2445 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2446 | * @return target SDK if the package is found or INT_MAX. |
| 2447 | */ |
| 2448 | private int getTargetSdk(String packageName) { |
| 2449 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2450 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 0150f0e | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2451 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2452 | if (ai != null) return ai.targetSdkVersion; |
| 2453 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2454 | loge("Failed to get package info for pkg=" |
| 2455 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2456 | } |
| 2457 | return Integer.MAX_VALUE; |
| 2458 | } |
| 2459 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2460 | @Override |
| 2461 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2462 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2463 | String callingFeatureId) { |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2464 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2465 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2466 | throw new SecurityException( |
| 2467 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2468 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2469 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2470 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2471 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2472 | return null; |
| 2473 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2474 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2475 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2476 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2477 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2478 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2479 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2480 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2481 | for (CellInfo ci : info) { |
| 2482 | if (ci instanceof CellInfoGsm) { |
| 2483 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2484 | } else if (ci instanceof CellInfoWcdma) { |
| 2485 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2486 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2487 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2488 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2489 | } |
| 2490 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2491 | private List<CellInfo> getCachedCellInfo() { |
| 2492 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2493 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2494 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2495 | if (info != null) cellInfos.addAll(info); |
| 2496 | } |
| 2497 | return cellInfos; |
| 2498 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2499 | |
| 2500 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2501 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2502 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2503 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2504 | |
| 2505 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2506 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2507 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2508 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2509 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2510 | .setCallingPid(Binder.getCallingPid()) |
| 2511 | .setCallingUid(Binder.getCallingUid()) |
| 2512 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2513 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2514 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2515 | .build()); |
| 2516 | switch (locationResult) { |
| 2517 | case DENIED_HARD: |
| 2518 | throw new SecurityException("Not allowed to access cell info"); |
| 2519 | case DENIED_SOFT: |
| 2520 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2521 | } |
| 2522 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2523 | final int targetSdk = getTargetSdk(callingPackage); |
| 2524 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2525 | return getCachedCellInfo(); |
| 2526 | } |
| 2527 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2528 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2529 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2530 | final long identity = Binder.clearCallingIdentity(); |
| 2531 | try { |
| 2532 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2533 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2534 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2535 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2536 | if (info != null) cellInfos.addAll(info); |
| 2537 | } |
| 2538 | return cellInfos; |
| 2539 | } finally { |
| 2540 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2541 | } |
| 2542 | } |
| 2543 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2544 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2545 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2546 | String callingFeatureId) { |
| 2547 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2548 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2549 | } |
| 2550 | |
| 2551 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2552 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2553 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2554 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2555 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2556 | } |
| 2557 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2558 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2559 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2560 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2561 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2562 | |
| 2563 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2564 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2565 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2566 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2567 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2568 | .setCallingPid(Binder.getCallingPid()) |
| 2569 | .setCallingUid(Binder.getCallingUid()) |
| 2570 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2571 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2572 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2573 | .build()); |
| 2574 | switch (locationResult) { |
| 2575 | case DENIED_HARD: |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2576 | if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) { |
| 2577 | // Safetynet logging for b/154934934 |
| 2578 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2579 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2580 | throw new SecurityException("Not allowed to access cell info"); |
| 2581 | case DENIED_SOFT: |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2582 | if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) { |
| 2583 | // Safetynet logging for b/154934934 |
| 2584 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2585 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2586 | try { |
| 2587 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2588 | } catch (RemoteException re) { |
| 2589 | // Drop without consequences |
| 2590 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2591 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2592 | } |
| 2593 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2594 | |
| 2595 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2596 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2597 | |
| 2598 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2599 | } |
| 2600 | |
| 2601 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2602 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2603 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2604 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2605 | |
| 2606 | final long identity = Binder.clearCallingIdentity(); |
| 2607 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2608 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2609 | } finally { |
| 2610 | Binder.restoreCallingIdentity(identity); |
| 2611 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2612 | } |
| 2613 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2614 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2615 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2616 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2617 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2618 | return null; |
| 2619 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2620 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2621 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2622 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2623 | return null; |
| 2624 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2625 | |
| 2626 | final long identity = Binder.clearCallingIdentity(); |
| 2627 | try { |
| 2628 | return phone.getImei(); |
| 2629 | } finally { |
| 2630 | Binder.restoreCallingIdentity(identity); |
| 2631 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2632 | } |
| 2633 | |
| 2634 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2635 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2636 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2637 | String tac = null; |
| 2638 | if (phone != null) { |
| 2639 | String imei = phone.getImei(); |
| 2640 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2641 | } |
| 2642 | return tac; |
| 2643 | } |
| 2644 | |
| 2645 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2646 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2647 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2648 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2649 | return null; |
| 2650 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2651 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2652 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2653 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2654 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2655 | return null; |
| 2656 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2657 | |
| 2658 | final long identity = Binder.clearCallingIdentity(); |
| 2659 | try { |
| 2660 | return phone.getMeid(); |
| 2661 | } finally { |
| 2662 | Binder.restoreCallingIdentity(identity); |
| 2663 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2664 | } |
| 2665 | |
| 2666 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2667 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2668 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2669 | String manufacturerCode = null; |
| 2670 | if (phone != null) { |
| 2671 | String meid = phone.getMeid(); |
| 2672 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2673 | } |
| 2674 | return manufacturerCode; |
| 2675 | } |
| 2676 | |
| 2677 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2678 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2679 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2680 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2681 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2682 | return null; |
| 2683 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2684 | int subId = phone.getSubId(); |
| 2685 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2686 | mApp, subId, callingPackage, callingFeatureId, |
| 2687 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2688 | return null; |
| 2689 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2690 | |
| 2691 | final long identity = Binder.clearCallingIdentity(); |
| 2692 | try { |
| 2693 | return phone.getDeviceSvn(); |
| 2694 | } finally { |
| 2695 | Binder.restoreCallingIdentity(identity); |
| 2696 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2697 | } |
| 2698 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2699 | @Override |
| 2700 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2701 | final long identity = Binder.clearCallingIdentity(); |
| 2702 | try { |
| 2703 | final Phone phone = getPhone(subId); |
| 2704 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2705 | } finally { |
| 2706 | Binder.restoreCallingIdentity(identity); |
| 2707 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2708 | } |
| 2709 | |
| 2710 | @Override |
| 2711 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2712 | final long identity = Binder.clearCallingIdentity(); |
| 2713 | try { |
| 2714 | final Phone phone = getPhone(subId); |
| 2715 | return phone == null ? null : phone.getCarrierName(); |
| 2716 | } finally { |
| 2717 | Binder.restoreCallingIdentity(identity); |
| 2718 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2719 | } |
| 2720 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2721 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2722 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2723 | final long identity = Binder.clearCallingIdentity(); |
| 2724 | try { |
| 2725 | final Phone phone = getPhone(subId); |
| 2726 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2727 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2728 | } finally { |
| 2729 | Binder.restoreCallingIdentity(identity); |
| 2730 | } |
| 2731 | } |
| 2732 | |
| 2733 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2734 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2735 | final long identity = Binder.clearCallingIdentity(); |
| 2736 | try { |
| 2737 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2738 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2739 | } finally { |
| 2740 | Binder.restoreCallingIdentity(identity); |
| 2741 | } |
| 2742 | } |
| 2743 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2744 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2745 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2746 | if (!isSubscriptionMccMnc) { |
| 2747 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2748 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2749 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2750 | if (phone == null) { |
| 2751 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2752 | } |
| 2753 | final long identity = Binder.clearCallingIdentity(); |
| 2754 | try { |
| 2755 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2756 | } finally { |
| 2757 | Binder.restoreCallingIdentity(identity); |
| 2758 | } |
| 2759 | } |
| 2760 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2761 | // |
| 2762 | // Internal helper methods. |
| 2763 | // |
| 2764 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2765 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2766 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2767 | * |
| 2768 | * @throws SecurityException if the caller does not have the required permission |
| 2769 | */ |
| 2770 | private void enforceModifyPermission() { |
| 2771 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2772 | } |
| 2773 | |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 2774 | /** |
| 2775 | * Make sure the caller is system. |
| 2776 | * |
| 2777 | * @throws SecurityException if the caller is not system. |
| 2778 | */ |
| 2779 | private void enforceSystemCaller() { |
| 2780 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 2781 | throw new SecurityException("Caller must be system"); |
| 2782 | } |
| 2783 | } |
| 2784 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 2785 | private void enforceActiveEmergencySessionPermission() { |
| 2786 | mApp.enforceCallingOrSelfPermission( |
| 2787 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 2788 | } |
| 2789 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2790 | /** |
| 2791 | * Make sure the caller has the CALL_PHONE permission. |
| 2792 | * |
| 2793 | * @throws SecurityException if the caller does not have the required permission |
| 2794 | */ |
| 2795 | private void enforceCallPermission() { |
| 2796 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2797 | } |
| 2798 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 2799 | private void enforceSettingsPermission() { |
| 2800 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2801 | } |
| 2802 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2803 | private String createTelUrl(String number) { |
| 2804 | if (TextUtils.isEmpty(number)) { |
| 2805 | return null; |
| 2806 | } |
| 2807 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2808 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2809 | } |
| 2810 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2811 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2812 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2813 | } |
| 2814 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2815 | private static void logv(String msg) { |
| 2816 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2817 | } |
| 2818 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2819 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2820 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2821 | } |
| 2822 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2823 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2824 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2825 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2826 | } |
| 2827 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2828 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2829 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2830 | final long identity = Binder.clearCallingIdentity(); |
| 2831 | try { |
| 2832 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2833 | if (phone == null) { |
| 2834 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2835 | } else { |
| 2836 | return phone.getPhoneType(); |
| 2837 | } |
| 2838 | } finally { |
| 2839 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2840 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2841 | } |
| 2842 | |
| 2843 | /** |
| 2844 | * Returns the CDMA ERI icon index to display |
| 2845 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2846 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2847 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 2848 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 2849 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2850 | } |
| 2851 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2852 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2853 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 2854 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2855 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2856 | mApp, subId, callingPackage, callingFeatureId, |
| 2857 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2858 | return -1; |
| 2859 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2860 | |
| 2861 | final long identity = Binder.clearCallingIdentity(); |
| 2862 | try { |
| 2863 | final Phone phone = getPhone(subId); |
| 2864 | if (phone != null) { |
| 2865 | return phone.getCdmaEriIconIndex(); |
| 2866 | } else { |
| 2867 | return -1; |
| 2868 | } |
| 2869 | } finally { |
| 2870 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2871 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2872 | } |
| 2873 | |
| 2874 | /** |
| 2875 | * Returns the CDMA ERI icon mode, |
| 2876 | * 0 - ON |
| 2877 | * 1 - FLASHING |
| 2878 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2879 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2880 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 2881 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 2882 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2883 | } |
| 2884 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2885 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2886 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 2887 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2888 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2889 | mApp, subId, callingPackage, callingFeatureId, |
| 2890 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2891 | return -1; |
| 2892 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2893 | |
| 2894 | final long identity = Binder.clearCallingIdentity(); |
| 2895 | try { |
| 2896 | final Phone phone = getPhone(subId); |
| 2897 | if (phone != null) { |
| 2898 | return phone.getCdmaEriIconMode(); |
| 2899 | } else { |
| 2900 | return -1; |
| 2901 | } |
| 2902 | } finally { |
| 2903 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2904 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2905 | } |
| 2906 | |
| 2907 | /** |
| 2908 | * Returns the CDMA ERI text, |
| 2909 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2910 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2911 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 2912 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 2913 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2914 | } |
| 2915 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2916 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2917 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 2918 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2919 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2920 | mApp, subId, callingPackage, callingFeatureId, |
| 2921 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2922 | return null; |
| 2923 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2924 | |
| 2925 | final long identity = Binder.clearCallingIdentity(); |
| 2926 | try { |
| 2927 | final Phone phone = getPhone(subId); |
| 2928 | if (phone != null) { |
| 2929 | return phone.getCdmaEriText(); |
| 2930 | } else { |
| 2931 | return null; |
| 2932 | } |
| 2933 | } finally { |
| 2934 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2935 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2936 | } |
| 2937 | |
| 2938 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2939 | * Returns the CDMA MDN. |
| 2940 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2941 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2942 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2943 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2944 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2945 | |
| 2946 | final long identity = Binder.clearCallingIdentity(); |
| 2947 | try { |
| 2948 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2949 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2950 | return phone.getLine1Number(); |
| 2951 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2952 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2953 | return null; |
| 2954 | } |
| 2955 | } finally { |
| 2956 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2957 | } |
| 2958 | } |
| 2959 | |
| 2960 | /** |
| 2961 | * Returns the CDMA MIN. |
| 2962 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2963 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2964 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2965 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2966 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2967 | |
| 2968 | final long identity = Binder.clearCallingIdentity(); |
| 2969 | try { |
| 2970 | final Phone phone = getPhone(subId); |
| 2971 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2972 | return phone.getCdmaMin(); |
| 2973 | } else { |
| 2974 | return null; |
| 2975 | } |
| 2976 | } finally { |
| 2977 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2978 | } |
| 2979 | } |
| 2980 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2981 | @Override |
| 2982 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2983 | INumberVerificationCallback callback, String callingPackage) { |
| 2984 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2985 | != PERMISSION_GRANTED) { |
| 2986 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2987 | } |
| 2988 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2989 | |
| 2990 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2991 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2992 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2993 | } |
| 2994 | |
| 2995 | if (range == null) { |
| 2996 | throw new NullPointerException("Range must be non-null"); |
| 2997 | } |
| 2998 | |
| 2999 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3000 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3001 | |
| 3002 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3003 | } |
| 3004 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3005 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3006 | * Returns true if CDMA provisioning needs to run. |
| 3007 | */ |
| 3008 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3009 | final long identity = Binder.clearCallingIdentity(); |
| 3010 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3011 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3012 | } finally { |
| 3013 | Binder.restoreCallingIdentity(identity); |
| 3014 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3015 | } |
| 3016 | |
| 3017 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3018 | * Sets the voice mail number of a given subId. |
| 3019 | */ |
| 3020 | @Override |
| 3021 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3022 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3023 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3024 | |
| 3025 | final long identity = Binder.clearCallingIdentity(); |
| 3026 | try { |
| 3027 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3028 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3029 | return success; |
| 3030 | } finally { |
| 3031 | Binder.restoreCallingIdentity(identity); |
| 3032 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3033 | } |
| 3034 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3035 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3036 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3037 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3038 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3039 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3040 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3041 | throw new SecurityException("caller must be system dialer"); |
| 3042 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3043 | |
| 3044 | final long identity = Binder.clearCallingIdentity(); |
| 3045 | try { |
| 3046 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3047 | if (phoneAccountHandle == null) { |
| 3048 | return null; |
| 3049 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3050 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3051 | } finally { |
| 3052 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3053 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3054 | } |
| 3055 | |
| 3056 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3057 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3058 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3059 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3060 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3061 | mApp, subId, callingPackage, callingFeatureId, |
| 3062 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3063 | return null; |
| 3064 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3065 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3066 | final long identity = Binder.clearCallingIdentity(); |
| 3067 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3068 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3069 | } finally { |
| 3070 | Binder.restoreCallingIdentity(identity); |
| 3071 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3072 | } |
| 3073 | |
| 3074 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3075 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3076 | VisualVoicemailSmsFilterSettings settings) { |
| 3077 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3078 | |
| 3079 | final long identity = Binder.clearCallingIdentity(); |
| 3080 | try { |
| 3081 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3082 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3083 | } finally { |
| 3084 | Binder.restoreCallingIdentity(identity); |
| 3085 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3086 | } |
| 3087 | |
| 3088 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3089 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3090 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3091 | |
| 3092 | final long identity = Binder.clearCallingIdentity(); |
| 3093 | try { |
| 3094 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3095 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3096 | } finally { |
| 3097 | Binder.restoreCallingIdentity(identity); |
| 3098 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3099 | } |
| 3100 | |
| 3101 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3102 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3103 | String callingPackage, int subId) { |
| 3104 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3105 | |
| 3106 | final long identity = Binder.clearCallingIdentity(); |
| 3107 | try { |
| 3108 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3109 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3110 | } finally { |
| 3111 | Binder.restoreCallingIdentity(identity); |
| 3112 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3113 | } |
| 3114 | |
| 3115 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3116 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3117 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3118 | |
| 3119 | final long identity = Binder.clearCallingIdentity(); |
| 3120 | try { |
| 3121 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3122 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3123 | } finally { |
| 3124 | Binder.restoreCallingIdentity(identity); |
| 3125 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3126 | } |
| 3127 | |
| 3128 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3129 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3130 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3131 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3132 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3133 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3134 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3135 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3136 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3137 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3138 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3139 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3140 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3141 | * Sets the voice activation state of a given subId. |
| 3142 | */ |
| 3143 | @Override |
| 3144 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3145 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3146 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3147 | |
| 3148 | final long identity = Binder.clearCallingIdentity(); |
| 3149 | try { |
| 3150 | final Phone phone = getPhone(subId); |
| 3151 | if (phone != null) { |
| 3152 | phone.setVoiceActivationState(activationState); |
| 3153 | } else { |
| 3154 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3155 | } |
| 3156 | } finally { |
| 3157 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3158 | } |
| 3159 | } |
| 3160 | |
| 3161 | /** |
| 3162 | * Sets the data activation state of a given subId. |
| 3163 | */ |
| 3164 | @Override |
| 3165 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3166 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3167 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3168 | |
| 3169 | final long identity = Binder.clearCallingIdentity(); |
| 3170 | try { |
| 3171 | final Phone phone = getPhone(subId); |
| 3172 | if (phone != null) { |
| 3173 | phone.setDataActivationState(activationState); |
| 3174 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3175 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3176 | } |
| 3177 | } finally { |
| 3178 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3179 | } |
| 3180 | } |
| 3181 | |
| 3182 | /** |
| 3183 | * Returns the voice activation state of a given subId. |
| 3184 | */ |
| 3185 | @Override |
| 3186 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3187 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3188 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3189 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3190 | final long identity = Binder.clearCallingIdentity(); |
| 3191 | try { |
| 3192 | if (phone != null) { |
| 3193 | return phone.getVoiceActivationState(); |
| 3194 | } else { |
| 3195 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3196 | } |
| 3197 | } finally { |
| 3198 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3199 | } |
| 3200 | } |
| 3201 | |
| 3202 | /** |
| 3203 | * Returns the data activation state of a given subId. |
| 3204 | */ |
| 3205 | @Override |
| 3206 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3207 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3208 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3209 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3210 | final long identity = Binder.clearCallingIdentity(); |
| 3211 | try { |
| 3212 | if (phone != null) { |
| 3213 | return phone.getDataActivationState(); |
| 3214 | } else { |
| 3215 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3216 | } |
| 3217 | } finally { |
| 3218 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3219 | } |
| 3220 | } |
| 3221 | |
| 3222 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3223 | * Returns the unread count of voicemails for a subId |
| 3224 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3225 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3226 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3227 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3228 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3229 | mApp, subId, callingPackage, callingFeatureId, |
| 3230 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3231 | return 0; |
| 3232 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3233 | final long identity = Binder.clearCallingIdentity(); |
| 3234 | try { |
| 3235 | final Phone phone = getPhone(subId); |
| 3236 | if (phone != null) { |
| 3237 | return phone.getVoiceMessageCount(); |
| 3238 | } else { |
| 3239 | return 0; |
| 3240 | } |
| 3241 | } finally { |
| 3242 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3243 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3244 | } |
| 3245 | |
| 3246 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3247 | * returns true, if the device is in a state where both voice and data |
| 3248 | * are supported simultaneously. This can change based on location or network condition. |
| 3249 | */ |
| 3250 | @Override |
| 3251 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3252 | final long identity = Binder.clearCallingIdentity(); |
| 3253 | try { |
| 3254 | final Phone phone = getPhone(subId); |
| 3255 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3256 | } finally { |
| 3257 | Binder.restoreCallingIdentity(identity); |
| 3258 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3259 | } |
| 3260 | |
| 3261 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3262 | * Send the dialer code if called from the current default dialer or the caller has |
| 3263 | * carrier privilege. |
| 3264 | * @param inputCode The dialer code to send |
| 3265 | */ |
| 3266 | @Override |
| 3267 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3268 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3269 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3270 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3271 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3272 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3273 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3274 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3275 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3276 | |
| 3277 | final long identity = Binder.clearCallingIdentity(); |
| 3278 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3279 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3280 | } finally { |
| 3281 | Binder.restoreCallingIdentity(identity); |
| 3282 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3283 | } |
| 3284 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3285 | @Override |
| 3286 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3287 | TelephonyPermissions |
| 3288 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3289 | mApp, subId, "getNetworkSelectionMode"); |
| 3290 | final long identity = Binder.clearCallingIdentity(); |
| 3291 | try { |
| 3292 | if (!isActiveSubscription(subId)) { |
| 3293 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3294 | } |
| 3295 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3296 | } finally { |
| 3297 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3298 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3299 | } |
| 3300 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3301 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3302 | public boolean isInEmergencySmsMode() { |
| 3303 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3304 | final long identity = Binder.clearCallingIdentity(); |
| 3305 | try { |
| 3306 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3307 | if (phone.isInEmergencySmsMode()) { |
| 3308 | return true; |
| 3309 | } |
| 3310 | } |
| 3311 | } finally { |
| 3312 | Binder.restoreCallingIdentity(identity); |
| 3313 | } |
| 3314 | return false; |
| 3315 | } |
| 3316 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3317 | /** |
| 3318 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3319 | * @param subId The subscription to use to check the configuration. |
| 3320 | * @param c The callback that will be used to send the result. |
| 3321 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3322 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3323 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3324 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3325 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3326 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3327 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3328 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3329 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3330 | "IMS not available on device."); |
| 3331 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3332 | final long token = Binder.clearCallingIdentity(); |
| 3333 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3334 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3335 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3336 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3337 | } catch (ImsException e) { |
| 3338 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3339 | } finally { |
| 3340 | Binder.restoreCallingIdentity(token); |
| 3341 | } |
| 3342 | } |
| 3343 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3344 | /** |
| 3345 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3346 | * @param subId The subscription to use to check the configuration. |
| 3347 | * @param c The callback that will be used to send the result. |
| 3348 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3349 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3350 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3351 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3352 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3353 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3354 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3355 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3356 | final long token = Binder.clearCallingIdentity(); |
| 3357 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3358 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3359 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3360 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3361 | } catch (ImsException e) { |
| 3362 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3363 | + "is inactive, ignoring unregister."); |
| 3364 | // If the subscription is no longer active, just return, since the callback |
| 3365 | // will already have been removed internally. |
| 3366 | } finally { |
| 3367 | Binder.restoreCallingIdentity(token); |
| 3368 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3369 | } |
| 3370 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3371 | /** |
| 3372 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3373 | */ |
| 3374 | @Override |
| 3375 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3376 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3377 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3378 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3379 | "IMS not available on device."); |
| 3380 | } |
| 3381 | final long token = Binder.clearCallingIdentity(); |
| 3382 | try { |
| 3383 | Phone phone = getPhone(subId); |
| 3384 | if (phone == null) { |
| 3385 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3386 | + subId + "'"); |
| 3387 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3388 | } |
| 3389 | phone.getImsRegistrationState(regState -> { |
| 3390 | try { |
| 3391 | consumer.accept((regState == null) |
| 3392 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3393 | } catch (RemoteException e) { |
| 3394 | // Ignore if the remote process is no longer available to call back. |
| 3395 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3396 | } |
| 3397 | }); |
| 3398 | } finally { |
| 3399 | Binder.restoreCallingIdentity(token); |
| 3400 | } |
| 3401 | } |
| 3402 | |
| 3403 | /** |
| 3404 | * Get the transport type for the IMS service registration state. |
| 3405 | */ |
| 3406 | @Override |
| 3407 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3408 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3409 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3410 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3411 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3412 | "IMS not available on device."); |
| 3413 | } |
| 3414 | final long token = Binder.clearCallingIdentity(); |
| 3415 | try { |
| 3416 | Phone phone = getPhone(subId); |
| 3417 | if (phone == null) { |
| 3418 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3419 | + subId + "'"); |
| 3420 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3421 | } |
| 3422 | phone.getImsRegistrationTech(regTech -> { |
| 3423 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3424 | int regTechConverted = (regTech == null) |
| 3425 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3426 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3427 | regTechConverted); |
| 3428 | try { |
| 3429 | consumer.accept(regTechConverted); |
| 3430 | } catch (RemoteException e) { |
| 3431 | // Ignore if the remote process is no longer available to call back. |
| 3432 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3433 | } |
| 3434 | }); |
| 3435 | } finally { |
| 3436 | Binder.restoreCallingIdentity(token); |
| 3437 | } |
| 3438 | } |
| 3439 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3440 | /** |
| 3441 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3442 | * @param subId The subscription to use to check the configuration. |
| 3443 | * @param c The callback that will be used to send the result. |
| 3444 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3445 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3446 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3447 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3448 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3449 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3450 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3451 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3452 | "IMS not available on device."); |
| 3453 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3454 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3455 | final long token = Binder.clearCallingIdentity(); |
| 3456 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3457 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3458 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3459 | } catch (ImsException e) { |
| 3460 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3461 | } finally { |
| 3462 | Binder.restoreCallingIdentity(token); |
| 3463 | } |
| 3464 | } |
| 3465 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3466 | /** |
| 3467 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3468 | * @param subId The subscription to use to check the configuration. |
| 3469 | * @param c The callback that will be used to send the result. |
| 3470 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3471 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3472 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3473 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3474 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3475 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3476 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3477 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3478 | |
| 3479 | final long token = Binder.clearCallingIdentity(); |
| 3480 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3481 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3482 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3483 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3484 | } catch (ImsException e) { |
| 3485 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3486 | + "is inactive, ignoring unregister."); |
| 3487 | // If the subscription is no longer active, just return, since the callback |
| 3488 | // will already have been removed internally. |
| 3489 | } finally { |
| 3490 | Binder.restoreCallingIdentity(token); |
| 3491 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3492 | } |
| 3493 | |
| 3494 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3495 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3496 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3497 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3498 | final long token = Binder.clearCallingIdentity(); |
| 3499 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3500 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3501 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3502 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3503 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3504 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3505 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3506 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3507 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3508 | } finally { |
| 3509 | Binder.restoreCallingIdentity(token); |
| 3510 | } |
| 3511 | } |
| 3512 | |
| 3513 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3514 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3515 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3516 | final long token = Binder.clearCallingIdentity(); |
| 3517 | try { |
| 3518 | Phone phone = getPhone(subId); |
| 3519 | if (phone == null) return false; |
| 3520 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3521 | } catch (com.android.ims.ImsException e) { |
| 3522 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3523 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3524 | } finally { |
| 3525 | Binder.restoreCallingIdentity(token); |
| 3526 | } |
| 3527 | } |
| 3528 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3529 | /** |
| 3530 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3531 | * subscription. |
| 3532 | * @param subId The subscription to use to check the configuration. |
| 3533 | * @param callback The callback that will be used to send the result. |
| 3534 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3535 | * @param transportType The transport type of the MmTelFeature capability. |
| 3536 | */ |
| 3537 | @Override |
| 3538 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3539 | int transportType) { |
| 3540 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3541 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3542 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3543 | "IMS not available on device."); |
| 3544 | } |
| 3545 | final long token = Binder.clearCallingIdentity(); |
| 3546 | try { |
| 3547 | int slotId = getSlotIndex(subId); |
| 3548 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3549 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3550 | + subId + "'"); |
| 3551 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3552 | } |
| 3553 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3554 | transportType, aBoolean -> { |
| 3555 | try { |
| 3556 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3557 | } catch (RemoteException e) { |
| 3558 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3559 | + "running. Ignore"); |
| 3560 | } |
| 3561 | }); |
| 3562 | } finally { |
| 3563 | Binder.restoreCallingIdentity(token); |
| 3564 | } |
| 3565 | } |
| 3566 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3567 | /** |
| 3568 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3569 | * @param subId The subscription to use to check the configuration. |
| 3570 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3571 | @Override |
| 3572 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3573 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3574 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3575 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3576 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3577 | final long token = Binder.clearCallingIdentity(); |
| 3578 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3579 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3580 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3581 | } catch (ImsException e) { |
| 3582 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3583 | } finally { |
| 3584 | Binder.restoreCallingIdentity(token); |
| 3585 | } |
| 3586 | } |
| 3587 | |
| 3588 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3589 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3590 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3591 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3592 | final long identity = Binder.clearCallingIdentity(); |
| 3593 | try { |
| 3594 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3595 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3596 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3597 | } catch (ImsException e) { |
| 3598 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3599 | } finally { |
| 3600 | Binder.restoreCallingIdentity(identity); |
| 3601 | } |
| 3602 | } |
| 3603 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3604 | /** |
| 3605 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3606 | * @param subId The subscription to use to check the configuration. |
| 3607 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3608 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3609 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3610 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3611 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3612 | final long identity = Binder.clearCallingIdentity(); |
| 3613 | try { |
| 3614 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3615 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3616 | } catch (ImsException e) { |
| 3617 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3618 | } finally { |
| 3619 | Binder.restoreCallingIdentity(identity); |
| 3620 | } |
| 3621 | } |
| 3622 | |
| 3623 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3624 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3625 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3626 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3627 | final long identity = Binder.clearCallingIdentity(); |
| 3628 | try { |
| 3629 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3630 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3631 | } catch (ImsException e) { |
| 3632 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3633 | } finally { |
| 3634 | Binder.restoreCallingIdentity(identity); |
| 3635 | } |
| 3636 | } |
| 3637 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3638 | /** |
| 3639 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3640 | * @param subId The subscription to use to check the configuration. |
| 3641 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3642 | @Override |
| 3643 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3644 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3645 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3646 | final long identity = Binder.clearCallingIdentity(); |
| 3647 | try { |
| 3648 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3649 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3650 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3651 | } catch (ImsException e) { |
| 3652 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3653 | } finally { |
| 3654 | Binder.restoreCallingIdentity(identity); |
| 3655 | } |
| 3656 | } |
| 3657 | |
| 3658 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3659 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3660 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3661 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3662 | final long identity = Binder.clearCallingIdentity(); |
| 3663 | try { |
| 3664 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3665 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3666 | } catch (ImsException e) { |
| 3667 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3668 | } finally { |
| 3669 | Binder.restoreCallingIdentity(identity); |
| 3670 | } |
| 3671 | } |
| 3672 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3673 | /** |
| 3674 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3675 | * @param subId The subscription to use to check the configuration. |
| 3676 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3677 | @Override |
| 3678 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3679 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3680 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3681 | final long identity = Binder.clearCallingIdentity(); |
| 3682 | try { |
| 3683 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3684 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3685 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3686 | } catch (ImsException e) { |
| 3687 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3688 | } finally { |
| 3689 | Binder.restoreCallingIdentity(identity); |
| 3690 | } |
| 3691 | } |
| 3692 | |
| 3693 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3694 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3695 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3696 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3697 | final long identity = Binder.clearCallingIdentity(); |
| 3698 | try { |
| 3699 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3700 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3701 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3702 | } catch (ImsException e) { |
| 3703 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3704 | } finally { |
| 3705 | Binder.restoreCallingIdentity(identity); |
| 3706 | } |
| 3707 | } |
| 3708 | |
| 3709 | @Override |
| 3710 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3711 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3712 | "setVoWiFiNonPersistent"); |
| 3713 | final long identity = Binder.clearCallingIdentity(); |
| 3714 | try { |
| 3715 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3716 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3717 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3718 | } catch (ImsException e) { |
| 3719 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3720 | } finally { |
| 3721 | Binder.restoreCallingIdentity(identity); |
| 3722 | } |
| 3723 | } |
| 3724 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3725 | /** |
| 3726 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3727 | * @param subId The subscription to use to check the configuration. |
| 3728 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3729 | @Override |
| 3730 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3731 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3732 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3733 | final long identity = Binder.clearCallingIdentity(); |
| 3734 | try { |
| 3735 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3736 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3737 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3738 | } catch (ImsException e) { |
| 3739 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3740 | } finally { |
| 3741 | Binder.restoreCallingIdentity(identity); |
| 3742 | } |
| 3743 | } |
| 3744 | |
| 3745 | @Override |
| 3746 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3747 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3748 | "setVoWiFiModeSetting"); |
| 3749 | final long identity = Binder.clearCallingIdentity(); |
| 3750 | try { |
| 3751 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3752 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3753 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3754 | } catch (ImsException e) { |
| 3755 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3756 | } finally { |
| 3757 | Binder.restoreCallingIdentity(identity); |
| 3758 | } |
| 3759 | } |
| 3760 | |
| 3761 | @Override |
| 3762 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3763 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3764 | final long identity = Binder.clearCallingIdentity(); |
| 3765 | try { |
| 3766 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3767 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3768 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3769 | } catch (ImsException e) { |
| 3770 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3771 | } finally { |
| 3772 | Binder.restoreCallingIdentity(identity); |
| 3773 | } |
| 3774 | } |
| 3775 | |
| 3776 | @Override |
| 3777 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3778 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3779 | "setVoWiFiRoamingModeSetting"); |
| 3780 | final long identity = Binder.clearCallingIdentity(); |
| 3781 | try { |
| 3782 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3783 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3784 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3785 | } catch (ImsException e) { |
| 3786 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3787 | } finally { |
| 3788 | Binder.restoreCallingIdentity(identity); |
| 3789 | } |
| 3790 | } |
| 3791 | |
| 3792 | @Override |
| 3793 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3794 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3795 | "setRttCapabilityEnabled"); |
| 3796 | final long identity = Binder.clearCallingIdentity(); |
| 3797 | try { |
| 3798 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3799 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3800 | } catch (ImsException e) { |
| 3801 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3802 | } finally { |
| 3803 | Binder.restoreCallingIdentity(identity); |
| 3804 | } |
| 3805 | } |
| 3806 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3807 | /** |
| 3808 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3809 | * @param subId The subscription to use to check the configuration. |
| 3810 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3811 | @Override |
| 3812 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3813 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3814 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3815 | final long identity = Binder.clearCallingIdentity(); |
| 3816 | try { |
| 3817 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3818 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3819 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3820 | } catch (ImsException e) { |
| 3821 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3822 | } finally { |
| 3823 | Binder.restoreCallingIdentity(identity); |
| 3824 | } |
| 3825 | } |
| 3826 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3827 | @Override |
| 3828 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3829 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3830 | final long identity = Binder.clearCallingIdentity(); |
| 3831 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 3832 | if (!isImsAvailableOnDevice()) { |
| 3833 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3834 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 3835 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3836 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3837 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3838 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3839 | } catch (ImsException e) { |
| 3840 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3841 | } finally { |
| 3842 | Binder.restoreCallingIdentity(identity); |
| 3843 | } |
| 3844 | } |
| 3845 | |
| 3846 | @Override |
| 3847 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3848 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3849 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3850 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3851 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3852 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3853 | try { |
| 3854 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3855 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3856 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3857 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3858 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3859 | + "is inactive, ignoring unregister."); |
| 3860 | // If the subscription is no longer active, just return, since the callback will already |
| 3861 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3862 | } finally { |
| 3863 | Binder.restoreCallingIdentity(identity); |
| 3864 | } |
| 3865 | } |
| 3866 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3867 | |
| 3868 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 3869 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3870 | message); |
| 3871 | } |
| 3872 | |
| 3873 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 3874 | boolean isMmtelCapability) { |
| 3875 | Phone phone = getPhone(subId); |
| 3876 | if (phone == null) { |
| 3877 | loge("phone instance null for subid " + subId); |
| 3878 | return false; |
| 3879 | } |
| 3880 | if (isMmtelCapability) { |
| 3881 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3882 | return false; |
| 3883 | } |
| 3884 | } else { |
| 3885 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3886 | return false; |
| 3887 | } |
| 3888 | } |
| 3889 | return true; |
| 3890 | } |
| 3891 | |
| 3892 | @Override |
| 3893 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 3894 | boolean isProvisioned) { |
| 3895 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 3896 | |
| 3897 | final long identity = Binder.clearCallingIdentity(); |
| 3898 | try { |
| 3899 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3900 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3901 | return; |
| 3902 | } |
| 3903 | |
| 3904 | // this capability requires provisioning, route to the correct API. |
| 3905 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3906 | switch (capability) { |
| 3907 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3908 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3909 | ims.setEabProvisioned(isProvisioned); |
| 3910 | break; |
| 3911 | default: { |
| 3912 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3913 | + "rcs capability '" + capability + "', which does not require " |
| 3914 | + "provisioning."); |
| 3915 | } |
| 3916 | } |
| 3917 | } finally { |
| 3918 | Binder.restoreCallingIdentity(identity); |
| 3919 | } |
| 3920 | |
| 3921 | } |
| 3922 | |
| 3923 | |
| 3924 | @Override |
| 3925 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 3926 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 3927 | final long identity = Binder.clearCallingIdentity(); |
| 3928 | try { |
| 3929 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3930 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3931 | return true; |
| 3932 | } |
| 3933 | |
| 3934 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3935 | switch (capability) { |
| 3936 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3937 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3938 | return ims.isEabProvisionedOnDevice(); |
| 3939 | |
| 3940 | default: { |
| 3941 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 3942 | + "capability '" + capability + "', which does not require " |
| 3943 | + "provisioning."); |
| 3944 | } |
| 3945 | } |
| 3946 | |
| 3947 | } finally { |
| 3948 | Binder.restoreCallingIdentity(identity); |
| 3949 | } |
| 3950 | } |
| 3951 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3952 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3953 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3954 | boolean isProvisioned) { |
| 3955 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3956 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3957 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3958 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3959 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3960 | final long identity = Binder.clearCallingIdentity(); |
| 3961 | try { |
| 3962 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3963 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3964 | return; |
| 3965 | } |
| 3966 | |
| 3967 | // this capability requires provisioning, route to the correct API. |
| 3968 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3969 | switch (capability) { |
| 3970 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3971 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3972 | ims.setVolteProvisioned(isProvisioned); |
| 3973 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3974 | ims.setWfcProvisioned(isProvisioned); |
| 3975 | } |
| 3976 | break; |
| 3977 | } |
| 3978 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3979 | // There is currently no difference in VT provisioning type. |
| 3980 | ims.setVtProvisioned(isProvisioned); |
| 3981 | break; |
| 3982 | } |
| 3983 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3984 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3985 | // change the capability of the feature instead if needed. |
| 3986 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3987 | == isProvisioned) { |
| 3988 | // No change in provisioning. |
| 3989 | return; |
| 3990 | } |
| 3991 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3992 | try { |
| 3993 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3994 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3995 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3996 | + ", Exception" + e.getMessage()); |
| 3997 | } |
| 3998 | break; |
| 3999 | } |
| 4000 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4001 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4002 | + "MmTel capability '" + capability + "', which does not require " |
| 4003 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4004 | } |
| 4005 | } |
| 4006 | |
| 4007 | } finally { |
| 4008 | Binder.restoreCallingIdentity(identity); |
| 4009 | } |
| 4010 | } |
| 4011 | |
| 4012 | @Override |
| 4013 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4014 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4015 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4016 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4017 | } |
| 4018 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4019 | final long identity = Binder.clearCallingIdentity(); |
| 4020 | try { |
| 4021 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4022 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4023 | return true; |
| 4024 | } |
| 4025 | |
| 4026 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4027 | switch (capability) { |
| 4028 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4029 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4030 | return ims.isVolteProvisionedOnDevice(); |
| 4031 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4032 | return ims.isWfcProvisionedOnDevice(); |
| 4033 | } |
| 4034 | // This should never happen, since we are checking tech above to make sure it |
| 4035 | // is either LTE or IWLAN. |
| 4036 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4037 | + "capability."); |
| 4038 | } |
| 4039 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4040 | // There is currently no difference in VT provisioning type. |
| 4041 | return ims.isVtProvisionedOnDevice(); |
| 4042 | } |
| 4043 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4044 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4045 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4046 | } |
| 4047 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4048 | throw new IllegalArgumentException( |
| 4049 | "Tried to get provisioning for MmTel capability '" + capability |
| 4050 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4051 | } |
| 4052 | } |
| 4053 | |
| 4054 | } finally { |
| 4055 | Binder.restoreCallingIdentity(identity); |
| 4056 | } |
| 4057 | } |
| 4058 | |
| 4059 | @Override |
| 4060 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4061 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4062 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4063 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4064 | } |
| 4065 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4066 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4067 | return (provisionedBits & capability) > 0; |
| 4068 | } |
| 4069 | |
| 4070 | @Override |
| 4071 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4072 | boolean isProvisioned) { |
| 4073 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4074 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4075 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4076 | } |
| 4077 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4078 | "setProvisioningStatusForCapability"); |
| 4079 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4080 | // If the current provisioning status for capability already matches isProvisioned, |
| 4081 | // do nothing. |
| 4082 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4083 | return; |
| 4084 | } |
| 4085 | if (isProvisioned) { |
| 4086 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4087 | } else { |
| 4088 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4089 | } |
| 4090 | } |
| 4091 | |
| 4092 | /** |
| 4093 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4094 | * technology. The bitfield should mirror the bitfield defined by |
| 4095 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4096 | */ |
| 4097 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4098 | String key = getMmTelProvisioningKey(subId, tech); |
| 4099 | // Default is no capabilities are provisioned. |
| 4100 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4101 | } |
| 4102 | |
| 4103 | /** |
| 4104 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4105 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4106 | * technology specified. |
| 4107 | * |
| 4108 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4109 | */ |
| 4110 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4111 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4112 | String key = getMmTelProvisioningKey(subId, tech); |
| 4113 | editor.putInt(key, newField); |
| 4114 | editor.commit(); |
| 4115 | } |
| 4116 | |
| 4117 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4118 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4119 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4120 | } |
| 4121 | |
| 4122 | /** |
| 4123 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4124 | * carrier associated with the subscription id. |
| 4125 | */ |
| 4126 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4127 | int capability) { |
| 4128 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4129 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4130 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4131 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4132 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4133 | false); |
| 4134 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4135 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4136 | |
| 4137 | // First check to make sure that the capability requires provisioning. |
| 4138 | switch (capability) { |
| 4139 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4140 | // intentional fallthrough |
| 4141 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4142 | if (requireVoiceVtProvisioning) { |
| 4143 | // Voice and Video requires provisioning |
| 4144 | return true; |
| 4145 | } |
| 4146 | break; |
| 4147 | } |
| 4148 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4149 | if (requireUtProvisioning) { |
| 4150 | // UT requires provisioning |
| 4151 | return true; |
| 4152 | } |
| 4153 | break; |
| 4154 | } |
| 4155 | } |
| 4156 | return false; |
| 4157 | } |
| 4158 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4159 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4160 | int capability) { |
| 4161 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4162 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4163 | |
| 4164 | boolean requireRcsProvisioning = c.getBoolean( |
| 4165 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4166 | |
| 4167 | // First check to make sure that the capability requires provisioning. |
| 4168 | switch (capability) { |
| 4169 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4170 | // intentional fallthrough |
| 4171 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4172 | if (requireRcsProvisioning) { |
| 4173 | // OPTION or PRESENCE requires provisioning |
| 4174 | return true; |
| 4175 | } |
| 4176 | break; |
| 4177 | } |
| 4178 | } |
| 4179 | return false; |
| 4180 | } |
| 4181 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4182 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4183 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4184 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4185 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4186 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4187 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4188 | final long identity = Binder.clearCallingIdentity(); |
| 4189 | try { |
| 4190 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4191 | int slotId = getSlotIndex(subId); |
| 4192 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4193 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4194 | + subId + "' for key:" + key); |
| 4195 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4196 | } |
| 4197 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4198 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4199 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4200 | + subId + "' for key:" + key); |
| 4201 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4202 | } finally { |
| 4203 | Binder.restoreCallingIdentity(identity); |
| 4204 | } |
| 4205 | } |
| 4206 | |
| 4207 | @Override |
| 4208 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4209 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4210 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4211 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4212 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4213 | final long identity = Binder.clearCallingIdentity(); |
| 4214 | try { |
| 4215 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4216 | int slotId = getSlotIndex(subId); |
| 4217 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4218 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4219 | + subId + "' for key:" + key); |
| 4220 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4221 | } |
| 4222 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4223 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4224 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4225 | + subId + "' for key:" + key); |
| 4226 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4227 | } finally { |
| 4228 | Binder.restoreCallingIdentity(identity); |
| 4229 | } |
| 4230 | } |
| 4231 | |
| 4232 | @Override |
| 4233 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4234 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4235 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4236 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4237 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4238 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4239 | final long identity = Binder.clearCallingIdentity(); |
| 4240 | try { |
| 4241 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4242 | int slotId = getSlotIndex(subId); |
| 4243 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4244 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4245 | + subId + "' for key:" + key); |
| 4246 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4247 | } |
| 4248 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4249 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4250 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4251 | + "' for key:" + key); |
| 4252 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4253 | } finally { |
| 4254 | Binder.restoreCallingIdentity(identity); |
| 4255 | } |
| 4256 | } |
| 4257 | |
| 4258 | @Override |
| 4259 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4260 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4261 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4262 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4263 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4264 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4265 | final long identity = Binder.clearCallingIdentity(); |
| 4266 | try { |
| 4267 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4268 | int slotId = getSlotIndex(subId); |
| 4269 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4270 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4271 | + subId + "' for key:" + key); |
| 4272 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4273 | } |
| 4274 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4275 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4276 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4277 | + "' for key:" + key); |
| 4278 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4279 | } finally { |
| 4280 | Binder.restoreCallingIdentity(identity); |
| 4281 | } |
| 4282 | } |
| 4283 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4284 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4285 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4286 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4287 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4288 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4289 | } |
| 4290 | return slotId; |
| 4291 | } |
| 4292 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4293 | private int getSlotIndex(int subId) { |
| 4294 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4295 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4296 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4297 | } |
| 4298 | return slotId; |
| 4299 | } |
| 4300 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4301 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4302 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4303 | */ |
| 4304 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4305 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4306 | String callingFeatureId) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4307 | final int targetSdk = getTargetSdk(callingPackage); |
| 4308 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4309 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4310 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4311 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4312 | mApp, subId, callingPackage, callingFeatureId, |
| 4313 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4314 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4315 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4316 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4317 | final long identity = Binder.clearCallingIdentity(); |
| 4318 | try { |
| 4319 | final Phone phone = getPhone(subId); |
| 4320 | if (phone != null) { |
| 4321 | return phone.getServiceState().getDataNetworkType(); |
| 4322 | } else { |
| 4323 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4324 | } |
| 4325 | } finally { |
| 4326 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4327 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4328 | } |
| 4329 | |
| 4330 | /** |
| 4331 | * Returns the data network type |
| 4332 | */ |
| 4333 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4334 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4335 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4336 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4337 | } |
| 4338 | |
| 4339 | /** |
| 4340 | * Returns the data network type for a subId |
| 4341 | */ |
| 4342 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4343 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4344 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4345 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4346 | mApp, subId, callingPackage, callingFeatureId, |
| 4347 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4348 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4349 | } |
| 4350 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4351 | final long identity = Binder.clearCallingIdentity(); |
| 4352 | try { |
| 4353 | final Phone phone = getPhone(subId); |
| 4354 | if (phone != null) { |
| 4355 | return phone.getServiceState().getDataNetworkType(); |
| 4356 | } else { |
| 4357 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4358 | } |
| 4359 | } finally { |
| 4360 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4361 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4362 | } |
| 4363 | |
| 4364 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4365 | * Returns the Voice network type for a subId |
| 4366 | */ |
| 4367 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4368 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4369 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4370 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4371 | mApp, subId, callingPackage, callingFeatureId, |
| 4372 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4373 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4374 | } |
| 4375 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4376 | final long identity = Binder.clearCallingIdentity(); |
| 4377 | try { |
| 4378 | final Phone phone = getPhone(subId); |
| 4379 | if (phone != null) { |
| 4380 | return phone.getServiceState().getVoiceNetworkType(); |
| 4381 | } else { |
| 4382 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4383 | } |
| 4384 | } finally { |
| 4385 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4386 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4387 | } |
| 4388 | |
| 4389 | /** |
| 4390 | * @return true if a ICC card is present |
| 4391 | */ |
| 4392 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4393 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4394 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4395 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4396 | } |
| 4397 | |
| 4398 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4399 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4400 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4401 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4402 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4403 | final long identity = Binder.clearCallingIdentity(); |
| 4404 | try { |
| 4405 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4406 | if (phone != null) { |
| 4407 | return phone.getIccCard().hasIccCard(); |
| 4408 | } else { |
| 4409 | return false; |
| 4410 | } |
| 4411 | } finally { |
| 4412 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4413 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4414 | } |
| 4415 | |
| 4416 | /** |
| 4417 | * Return if the current radio is LTE on CDMA. This |
| 4418 | * is a tri-state return value as for a period of time |
| 4419 | * the mode may be unknown. |
| 4420 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4421 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4422 | * @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] | 4423 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4424 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4425 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4426 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4427 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4428 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4429 | } |
| 4430 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4431 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4432 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4433 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4434 | try { |
| 4435 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4436 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4437 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4438 | } |
| 4439 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4440 | final long identity = Binder.clearCallingIdentity(); |
| 4441 | try { |
| 4442 | final Phone phone = getPhone(subId); |
| 4443 | if (phone == null) { |
| 4444 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4445 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 4446 | return TelephonyProperties.lte_on_cdma_device() |
| 4447 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4448 | } |
| 4449 | } finally { |
| 4450 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4451 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4452 | } |
| 4453 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4454 | /** |
| 4455 | * {@hide} |
| 4456 | * Returns Default subId, 0 in the case of single standby. |
| 4457 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4458 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4459 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4460 | } |
| 4461 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4462 | private int getSlotForDefaultSubscription() { |
| 4463 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4464 | } |
| 4465 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4466 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4467 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4468 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4469 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4470 | private boolean isActiveSubscription(int subId) { |
| 4471 | return mSubscriptionController.isActiveSubId(subId); |
| 4472 | } |
| 4473 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4474 | /** |
| 4475 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4476 | */ |
| 4477 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4478 | final long identity = Binder.clearCallingIdentity(); |
| 4479 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4480 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4481 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4482 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4483 | } finally { |
| 4484 | Binder.restoreCallingIdentity(identity); |
| 4485 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4486 | } |
| 4487 | |
| 4488 | /** |
| 4489 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4490 | */ |
| 4491 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4492 | final long identity = Binder.clearCallingIdentity(); |
| 4493 | try { |
| 4494 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4495 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4496 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4497 | } finally { |
| 4498 | Binder.restoreCallingIdentity(identity); |
| 4499 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4500 | } |
| 4501 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4502 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4503 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4504 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4505 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4506 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4507 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4508 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4509 | if (phoneId == -1) { |
| 4510 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4511 | + " does not correspond to an active phone"); |
| 4512 | } |
| 4513 | return PhoneFactory.getPhone(phoneId); |
| 4514 | } |
| 4515 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4516 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4517 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4518 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4519 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4520 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4521 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4522 | if (DBG) { |
| 4523 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4524 | } |
| 4525 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4526 | p2); |
| 4527 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4528 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4529 | |
| 4530 | @Override |
| 4531 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4532 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4533 | enforceModifyPermission(); |
| 4534 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4535 | if (DBG) { |
| 4536 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4537 | } |
| 4538 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4539 | callingPackage, aid, p2); |
| 4540 | } |
| 4541 | |
| 4542 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4543 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4544 | final long identity = Binder.clearCallingIdentity(); |
| 4545 | try { |
| 4546 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4547 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4548 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4549 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4550 | if (bestComponent == null |
| 4551 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4552 | loge("The calling package is not allowed to access ISD-R."); |
| 4553 | throw new SecurityException( |
| 4554 | "The calling package is not allowed to access ISD-R."); |
| 4555 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4556 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4557 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4558 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4559 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4560 | null /* workSource */); |
| 4561 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4562 | return response; |
| 4563 | } finally { |
| 4564 | Binder.restoreCallingIdentity(identity); |
| 4565 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4566 | } |
| 4567 | |
| 4568 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4569 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4570 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4571 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4572 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4573 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4574 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4575 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4576 | @Override |
| 4577 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4578 | enforceModifyPermission(); |
| 4579 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4580 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4581 | channel); |
| 4582 | } |
| 4583 | |
| 4584 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4585 | final long identity = Binder.clearCallingIdentity(); |
| 4586 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4587 | if (channel < 0) { |
| 4588 | return false; |
| 4589 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4590 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4591 | null /* workSource */); |
| 4592 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4593 | return success; |
| 4594 | } finally { |
| 4595 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4596 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4597 | } |
| 4598 | |
| 4599 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4600 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4601 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4602 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4603 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4604 | if (DBG) { |
| 4605 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4606 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4607 | + p3 + " data=" + data); |
| 4608 | } |
| 4609 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4610 | command, p1, p2, p3, data); |
| 4611 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4612 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4613 | @Override |
| 4614 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4615 | int command, int p1, int p2, int p3, String data) { |
| 4616 | enforceModifyPermission(); |
| 4617 | if (DBG) { |
| 4618 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4619 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4620 | + p3 + " data=" + data); |
| 4621 | } |
| 4622 | return iccTransmitApduLogicalChannelWithPermission( |
| 4623 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4624 | data); |
| 4625 | } |
| 4626 | |
| 4627 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4628 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4629 | final long identity = Binder.clearCallingIdentity(); |
| 4630 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4631 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4632 | return ""; |
| 4633 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4634 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4635 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4636 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4637 | null /* workSource */); |
| 4638 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4639 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4640 | // Append the returned status code to the end of the response payload. |
| 4641 | String s = Integer.toHexString( |
| 4642 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4643 | if (response.payload != null) { |
| 4644 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4645 | } |
| 4646 | return s; |
| 4647 | } finally { |
| 4648 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4649 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4650 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4651 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4652 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4653 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4654 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4655 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4656 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4657 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4658 | if (DBG) { |
| 4659 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4660 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4661 | } |
| 4662 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4663 | cla, command, p1, p2, p3, data); |
| 4664 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4665 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4666 | @Override |
| 4667 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4668 | int command, int p1, int p2, int p3, String data) { |
| 4669 | enforceModifyPermission(); |
| 4670 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4671 | if (DBG) { |
| 4672 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4673 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4674 | + " data=" + data); |
| 4675 | } |
| 4676 | |
| 4677 | return iccTransmitApduBasicChannelWithPermission( |
| 4678 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4679 | p2, p3, data); |
| 4680 | } |
| 4681 | |
| 4682 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4683 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4684 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4685 | final long identity = Binder.clearCallingIdentity(); |
| 4686 | try { |
| 4687 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4688 | && TextUtils.equals(ISDR_AID, data)) { |
| 4689 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4690 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4691 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4692 | if (bestComponent == null |
| 4693 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4694 | loge("The calling package is not allowed to select ISD-R."); |
| 4695 | throw new SecurityException( |
| 4696 | "The calling package is not allowed to select ISD-R."); |
| 4697 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4698 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4699 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4700 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4701 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4702 | null /* workSource */); |
| 4703 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4704 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4705 | // Append the returned status code to the end of the response payload. |
| 4706 | String s = Integer.toHexString( |
| 4707 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4708 | if (response.payload != null) { |
| 4709 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4710 | } |
| 4711 | return s; |
| 4712 | } finally { |
| 4713 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4714 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4715 | } |
| 4716 | |
| 4717 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4718 | 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] | 4719 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4720 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4721 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4722 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4723 | final long identity = Binder.clearCallingIdentity(); |
| 4724 | try { |
| 4725 | if (DBG) { |
| 4726 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4727 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4728 | } |
| 4729 | |
| 4730 | IccIoResult response = |
| 4731 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4732 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4733 | subId); |
| 4734 | |
| 4735 | if (DBG) { |
| 4736 | log("Exchange SIM_IO [R]" + response); |
| 4737 | } |
| 4738 | |
| 4739 | byte[] result = null; |
| 4740 | int length = 2; |
| 4741 | if (response.payload != null) { |
| 4742 | length = 2 + response.payload.length; |
| 4743 | result = new byte[length]; |
| 4744 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4745 | } else { |
| 4746 | result = new byte[length]; |
| 4747 | } |
| 4748 | |
| 4749 | result[length - 1] = (byte) response.sw2; |
| 4750 | result[length - 2] = (byte) response.sw1; |
| 4751 | return result; |
| 4752 | } finally { |
| 4753 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4754 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4755 | } |
| 4756 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4757 | /** |
| 4758 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4759 | * on a particular subscription |
| 4760 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4761 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 4762 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4763 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4764 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4765 | return null; |
| 4766 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4767 | |
| 4768 | final long identity = Binder.clearCallingIdentity(); |
| 4769 | try { |
| 4770 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4771 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4772 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4773 | return null; |
| 4774 | } |
| 4775 | Object response = sendRequest( |
| 4776 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4777 | if (response instanceof String[]) { |
| 4778 | return (String[]) response; |
| 4779 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4780 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4781 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4782 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4783 | } finally { |
| 4784 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4785 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4786 | } |
| 4787 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4788 | /** |
| 4789 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 4790 | * subscription. |
| 4791 | * |
| 4792 | * @param subId the id of the subscription. |
| 4793 | * @param appType the uicc app type, must be USIM or SIM. |
| 4794 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 4795 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4796 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4797 | * @return number of fplmns that is successfully written to the SIM. |
| 4798 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4799 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 4800 | String callingFeatureId) { |
| 4801 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 4802 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4803 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 4804 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 4805 | } |
| 4806 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 4807 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4808 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 4809 | } |
| 4810 | if (fplmns == null) { |
| 4811 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 4812 | } |
| 4813 | for (String fplmn : fplmns) { |
| 4814 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 4815 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 4816 | } |
| 4817 | } |
| 4818 | final long identity = Binder.clearCallingIdentity(); |
| 4819 | try { |
| 4820 | Object response = sendRequest( |
| 4821 | CMD_SET_FORBIDDEN_PLMNS, |
| 4822 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 4823 | subId); |
| 4824 | return (int) response; |
| 4825 | } finally { |
| 4826 | Binder.restoreCallingIdentity(identity); |
| 4827 | } |
| 4828 | } |
| 4829 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4830 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4831 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4832 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4833 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4834 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4835 | final long identity = Binder.clearCallingIdentity(); |
| 4836 | try { |
| 4837 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4838 | if (response.payload == null) { |
| 4839 | return ""; |
| 4840 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4841 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4842 | // Append the returned status code to the end of the response payload. |
| 4843 | String s = Integer.toHexString( |
| 4844 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4845 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4846 | return s; |
| 4847 | } finally { |
| 4848 | Binder.restoreCallingIdentity(identity); |
| 4849 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4850 | } |
| 4851 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4852 | /** |
| 4853 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4854 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4855 | * |
| 4856 | * @param itemID the ID of the item to read |
| 4857 | * @return the NV item as a String, or null on error. |
| 4858 | */ |
| 4859 | @Override |
| 4860 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4861 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4862 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4863 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4864 | |
| 4865 | final long identity = Binder.clearCallingIdentity(); |
| 4866 | try { |
| 4867 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4868 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4869 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4870 | return value; |
| 4871 | } finally { |
| 4872 | Binder.restoreCallingIdentity(identity); |
| 4873 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4874 | } |
| 4875 | |
| 4876 | /** |
| 4877 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4878 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4879 | * |
| 4880 | * @param itemID the ID of the item to read |
| 4881 | * @param itemValue the value to write, as a String |
| 4882 | * @return true on success; false on any failure |
| 4883 | */ |
| 4884 | @Override |
| 4885 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4886 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4887 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4888 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4889 | |
| 4890 | final long identity = Binder.clearCallingIdentity(); |
| 4891 | try { |
| 4892 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4893 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4894 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4895 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4896 | return success; |
| 4897 | } finally { |
| 4898 | Binder.restoreCallingIdentity(identity); |
| 4899 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4900 | } |
| 4901 | |
| 4902 | /** |
| 4903 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4904 | * Used for device configuration by some CDMA operators. |
| 4905 | * |
| 4906 | * @param preferredRoamingList byte array containing the new PRL |
| 4907 | * @return true on success; false on any failure |
| 4908 | */ |
| 4909 | @Override |
| 4910 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4911 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4912 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4913 | |
| 4914 | final long identity = Binder.clearCallingIdentity(); |
| 4915 | try { |
| 4916 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4917 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4918 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4919 | return success; |
| 4920 | } finally { |
| 4921 | Binder.restoreCallingIdentity(identity); |
| 4922 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4923 | } |
| 4924 | |
| 4925 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4926 | * 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] | 4927 | * Used for device configuration by some CDMA operators. |
| 4928 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4929 | * @param slotIndex - device slot. |
| 4930 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4931 | * @return true on success; false on any failure |
| 4932 | */ |
| 4933 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4934 | public boolean resetModemConfig(int slotIndex) { |
| 4935 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4936 | if (phone != null) { |
| 4937 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4938 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4939 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4940 | final long identity = Binder.clearCallingIdentity(); |
| 4941 | try { |
| 4942 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4943 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4944 | return success; |
| 4945 | } finally { |
| 4946 | Binder.restoreCallingIdentity(identity); |
| 4947 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4948 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4949 | return false; |
| 4950 | } |
| 4951 | |
| 4952 | /** |
| 4953 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4954 | * |
| 4955 | * @param slotIndex - device slot. |
| 4956 | * |
| 4957 | * @return true on success; false on any failure |
| 4958 | */ |
| 4959 | @Override |
| 4960 | public boolean rebootModem(int slotIndex) { |
| 4961 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4962 | if (phone != null) { |
| 4963 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4964 | mApp, phone.getSubId(), "rebootModem"); |
| 4965 | |
| 4966 | final long identity = Binder.clearCallingIdentity(); |
| 4967 | try { |
| 4968 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4969 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4970 | return success; |
| 4971 | } finally { |
| 4972 | Binder.restoreCallingIdentity(identity); |
| 4973 | } |
| 4974 | } |
| 4975 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4976 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4977 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4978 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 4979 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4980 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4981 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4982 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4983 | return new String[0]; |
| 4984 | } |
| 4985 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4986 | final long identity = Binder.clearCallingIdentity(); |
| 4987 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4988 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4989 | } finally { |
| 4990 | Binder.restoreCallingIdentity(identity); |
| 4991 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4992 | } |
| 4993 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4994 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 4995 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 4996 | * {@link #disableIms(int)}. |
| 4997 | * @param slotIndex device slot. |
| 4998 | */ |
| 4999 | public void resetIms(int slotIndex) { |
| 5000 | enforceModifyPermission(); |
| 5001 | |
| 5002 | final long identity = Binder.clearCallingIdentity(); |
| 5003 | try { |
| 5004 | if (mImsResolver == null) { |
| 5005 | // may happen if the does not support IMS. |
| 5006 | return; |
| 5007 | } |
| 5008 | mImsResolver.disableIms(slotIndex); |
| 5009 | mImsResolver.enableIms(slotIndex); |
| 5010 | } finally { |
| 5011 | Binder.restoreCallingIdentity(identity); |
| 5012 | } |
| 5013 | } |
| 5014 | |
| 5015 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5016 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5017 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5018 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5019 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5020 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5021 | |
| 5022 | final long identity = Binder.clearCallingIdentity(); |
| 5023 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5024 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5025 | // may happen if the device does not support IMS. |
| 5026 | return; |
| 5027 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5028 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5029 | } finally { |
| 5030 | Binder.restoreCallingIdentity(identity); |
| 5031 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5032 | } |
| 5033 | |
| 5034 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5035 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5036 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5037 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5038 | public void disableIms(int slotId) { |
| 5039 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5040 | |
| 5041 | final long identity = Binder.clearCallingIdentity(); |
| 5042 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5043 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5044 | // may happen if the device does not support IMS. |
| 5045 | return; |
| 5046 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5047 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5048 | } finally { |
| 5049 | Binder.restoreCallingIdentity(identity); |
| 5050 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5051 | } |
| 5052 | |
| 5053 | /** |
| 5054 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 5055 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 5056 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 5057 | */ |
| 5058 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5059 | IImsServiceFeatureCallback callback) { |
| 5060 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5061 | |
| 5062 | final long identity = Binder.clearCallingIdentity(); |
| 5063 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5064 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5065 | // may happen if the device does not support IMS. |
| 5066 | return null; |
| 5067 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5068 | return mImsResolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5069 | } finally { |
| 5070 | Binder.restoreCallingIdentity(identity); |
| 5071 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5072 | } |
| 5073 | |
| 5074 | /** |
| 5075 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 5076 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 5077 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 5078 | * listener for feature updates. |
| 5079 | */ |
| 5080 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 5081 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5082 | |
| 5083 | final long identity = Binder.clearCallingIdentity(); |
| 5084 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5085 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5086 | // may happen if the device does not support IMS. |
| 5087 | return null; |
| 5088 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5089 | return mImsResolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5090 | } finally { |
| 5091 | Binder.restoreCallingIdentity(identity); |
| 5092 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5093 | } |
| 5094 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5095 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5096 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5097 | */ |
| 5098 | public void unregisterImsFeatureCallback(int slotId, int featureType, |
| 5099 | IImsServiceFeatureCallback callback) { |
| 5100 | enforceModifyPermission(); |
| 5101 | |
| 5102 | final long identity = Binder.clearCallingIdentity(); |
| 5103 | try { |
| 5104 | if (mImsResolver == null) return; |
| 5105 | mImsResolver.unregisterImsFeatureCallback(slotId, featureType, callback); |
| 5106 | } finally { |
| 5107 | Binder.restoreCallingIdentity(identity); |
| 5108 | } |
| 5109 | } |
| 5110 | |
| 5111 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5112 | * Returns the {@link IImsRegistration} 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 | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5114 | */ |
| 5115 | public IImsRegistration getImsRegistration(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 | 24c2999 | 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 | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5124 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5125 | } finally { |
| 5126 | Binder.restoreCallingIdentity(identity); |
| 5127 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5128 | } |
| 5129 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5130 | /** |
| 5131 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5132 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5133 | */ |
| 5134 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5135 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5136 | |
| 5137 | final long identity = Binder.clearCallingIdentity(); |
| 5138 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5139 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5140 | // may happen if the device does not support IMS. |
| 5141 | return null; |
| 5142 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5143 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5144 | } finally { |
| 5145 | Binder.restoreCallingIdentity(identity); |
| 5146 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5147 | } |
| 5148 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5149 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5150 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5151 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5152 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5153 | * @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] | 5154 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5155 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5156 | * @param packageName The name of the package that the current configuration will be replaced |
| 5157 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5158 | * @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] | 5159 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5160 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5161 | int[] featureTypes, String packageName) { |
| 5162 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5163 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5164 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5165 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5166 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5167 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5168 | final long identity = Binder.clearCallingIdentity(); |
| 5169 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5170 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5171 | // may happen if the device does not support IMS. |
| 5172 | return false; |
| 5173 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5174 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5175 | for (int featureType : featureTypes) { |
| 5176 | featureConfig.put(featureType, packageName); |
| 5177 | } |
| 5178 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5179 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5180 | } finally { |
| 5181 | Binder.restoreCallingIdentity(identity); |
| 5182 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5183 | } |
| 5184 | |
| 5185 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5186 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5187 | * |
| 5188 | * @param slotId The slot that the ImsService is associated with. |
| 5189 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5190 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5191 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5192 | * @return the package name of the ImsService configuration. |
| 5193 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5194 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5195 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5196 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5197 | TelephonyPermissions |
| 5198 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5199 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5200 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5201 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5202 | final long identity = Binder.clearCallingIdentity(); |
| 5203 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5204 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5205 | // may happen if the device does not support IMS. |
| 5206 | return ""; |
| 5207 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5208 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5209 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5210 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5211 | } finally { |
| 5212 | Binder.restoreCallingIdentity(identity); |
| 5213 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5214 | } |
| 5215 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5216 | /** |
| 5217 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5218 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5219 | * @param callback A callback with an integer containing the |
| 5220 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5221 | */ |
| 5222 | @Override |
| 5223 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5224 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5225 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5226 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5227 | "IMS not available on device."); |
| 5228 | } |
| 5229 | final long token = Binder.clearCallingIdentity(); |
| 5230 | try { |
| 5231 | int slotId = getSlotIndex(subId); |
| 5232 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5233 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5234 | + subId + "'"); |
| 5235 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5236 | } |
| 5237 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5238 | try { |
| 5239 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5240 | } catch (RemoteException e) { |
| 5241 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5242 | + "Ignore"); |
| 5243 | } |
| 5244 | }); |
| 5245 | } finally { |
| 5246 | Binder.restoreCallingIdentity(token); |
| 5247 | } |
| 5248 | } |
| 5249 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5250 | public void setImsRegistrationState(boolean registered) { |
| 5251 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5252 | |
| 5253 | final long identity = Binder.clearCallingIdentity(); |
| 5254 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5255 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5256 | } finally { |
| 5257 | Binder.restoreCallingIdentity(identity); |
| 5258 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5259 | } |
| 5260 | |
| 5261 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5262 | * Set the network selection mode to automatic. |
| 5263 | * |
| 5264 | */ |
| 5265 | @Override |
| 5266 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5267 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5268 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5269 | |
| 5270 | final long identity = Binder.clearCallingIdentity(); |
| 5271 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5272 | if (!isActiveSubscription(subId)) { |
| 5273 | return; |
| 5274 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5275 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 5276 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 5277 | } finally { |
| 5278 | Binder.restoreCallingIdentity(identity); |
| 5279 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5280 | } |
| 5281 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5282 | /** |
| 5283 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5284 | * |
| 5285 | * @param subId the id of the subscription. |
| 5286 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5287 | * the operator to attach to. |
| 5288 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5289 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5290 | * normal network selection next time. |
| 5291 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5292 | */ |
| 5293 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5294 | public boolean setNetworkSelectionModeManual( |
| 5295 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5296 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5297 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5298 | |
| 5299 | if (!isActiveSubscription(subId)) { |
| 5300 | return false; |
| 5301 | } |
| 5302 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5303 | final long identity = Binder.clearCallingIdentity(); |
| 5304 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5305 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5306 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5307 | if (DBG) { |
| 5308 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5309 | + " operator: " + operatorInfo); |
| 5310 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5311 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5312 | } finally { |
| 5313 | Binder.restoreCallingIdentity(identity); |
| 5314 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5315 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5316 | /** |
| 5317 | * Get the manual network selection |
| 5318 | * |
| 5319 | * @param subId the id of the subscription. |
| 5320 | * |
| 5321 | * @return the previously saved user selected PLMN |
| 5322 | */ |
| 5323 | @Override |
| 5324 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5325 | TelephonyPermissions |
| 5326 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5327 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5328 | |
| 5329 | final long identity = Binder.clearCallingIdentity(); |
| 5330 | try { |
| 5331 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5332 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5333 | } |
| 5334 | |
| 5335 | final Phone phone = getPhone(subId); |
| 5336 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5337 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5338 | } |
| 5339 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5340 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5341 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5342 | } finally { |
| 5343 | Binder.restoreCallingIdentity(identity); |
| 5344 | } |
| 5345 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5346 | |
| 5347 | /** |
| 5348 | * Scans for available networks. |
| 5349 | */ |
| 5350 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5351 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5352 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5353 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5354 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5355 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5356 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5357 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5358 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5359 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5360 | .setCallingPid(Binder.getCallingPid()) |
| 5361 | .setCallingUid(Binder.getCallingUid()) |
| 5362 | .setMethod("getCellNetworkScanResults") |
| 5363 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 5364 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5365 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5366 | .build()); |
| 5367 | switch (locationResult) { |
| 5368 | case DENIED_HARD: |
| 5369 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5370 | case DENIED_SOFT: |
| 5371 | return null; |
| 5372 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5373 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5374 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5375 | try { |
| 5376 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5377 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5378 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5379 | } finally { |
| 5380 | Binder.restoreCallingIdentity(identity); |
| 5381 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5382 | } |
| 5383 | |
| 5384 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5385 | * Get the call forwarding info, given the call forwarding reason. |
| 5386 | */ |
| 5387 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5388 | public void getCallForwarding(int subId, int callForwardingReason, |
| 5389 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5390 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5391 | long identity = Binder.clearCallingIdentity(); |
| 5392 | try { |
| 5393 | if (DBG) { |
| 5394 | log("getCallForwarding: subId " + subId |
| 5395 | + " callForwardingReason" + callForwardingReason); |
| 5396 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5397 | |
| 5398 | Phone phone = getPhone(subId); |
| 5399 | if (phone == null) { |
| 5400 | try { |
| 5401 | callback.onError(CallForwardingInfo.ERROR_UNKNOWN); |
| 5402 | } catch (RemoteException e) { |
| 5403 | // ignore |
| 5404 | } |
| 5405 | return; |
| 5406 | } |
| 5407 | |
| 5408 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 5409 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 5410 | @Override |
| 5411 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 5412 | try { |
| 5413 | callback.onCallForwardingInfoAvailable(info); |
| 5414 | } catch (RemoteException e) { |
| 5415 | // ignore |
| 5416 | } |
| 5417 | } |
| 5418 | |
| 5419 | @Override |
| 5420 | public void onError(int error) { |
| 5421 | try { |
| 5422 | callback.onError(error); |
| 5423 | } catch (RemoteException e) { |
| 5424 | // ignore |
| 5425 | } |
| 5426 | } |
| 5427 | }); |
| 5428 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5429 | } finally { |
| 5430 | Binder.restoreCallingIdentity(identity); |
| 5431 | } |
| 5432 | } |
| 5433 | |
| 5434 | /** |
| 5435 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5436 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5437 | */ |
| 5438 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5439 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 5440 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5441 | enforceModifyPermission(); |
| 5442 | long identity = Binder.clearCallingIdentity(); |
| 5443 | try { |
| 5444 | if (DBG) { |
| 5445 | log("setCallForwarding: subId " + subId |
| 5446 | + " callForwardingInfo" + callForwardingInfo); |
| 5447 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5448 | |
| 5449 | Phone phone = getPhone(subId); |
| 5450 | if (phone == null) { |
| 5451 | try { |
| 5452 | callback.accept(CallForwardingInfo.ERROR_UNKNOWN); |
| 5453 | } catch (RemoteException e) { |
| 5454 | // ignore |
| 5455 | } |
| 5456 | return; |
| 5457 | } |
| 5458 | |
| 5459 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 5460 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5461 | |
| 5462 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5463 | } finally { |
| 5464 | Binder.restoreCallingIdentity(identity); |
| 5465 | } |
| 5466 | } |
| 5467 | |
| 5468 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5469 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5470 | */ |
| 5471 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5472 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5473 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5474 | long identity = Binder.clearCallingIdentity(); |
| 5475 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5476 | |
| 5477 | Phone phone = getPhone(subId); |
| 5478 | if (phone == null) { |
| 5479 | try { |
| 5480 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5481 | } catch (RemoteException e) { |
| 5482 | // ignore |
| 5483 | } |
| 5484 | return; |
| 5485 | } |
| 5486 | |
| 5487 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 5488 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5489 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5490 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5491 | } finally { |
| 5492 | Binder.restoreCallingIdentity(identity); |
| 5493 | } |
| 5494 | } |
| 5495 | |
| 5496 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5497 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5498 | */ |
| 5499 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5500 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5501 | enforceModifyPermission(); |
| 5502 | long identity = Binder.clearCallingIdentity(); |
| 5503 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5504 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 5505 | |
| 5506 | Phone phone = getPhone(subId); |
| 5507 | if (phone == null) { |
| 5508 | try { |
| 5509 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5510 | } catch (RemoteException e) { |
| 5511 | // ignore |
| 5512 | } |
| 5513 | return; |
| 5514 | } |
| 5515 | |
| 5516 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 5517 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5518 | |
| 5519 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5520 | } finally { |
| 5521 | Binder.restoreCallingIdentity(identity); |
| 5522 | } |
| 5523 | } |
| 5524 | |
| 5525 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5526 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5527 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5528 | * @param subId id of the subscription |
| 5529 | * @param request contains the radio access networks with bands/channels to scan |
| 5530 | * @param messenger callback messenger for scan results or errors |
| 5531 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5532 | * @return the id of the requested scan which can be used to stop the scan. |
| 5533 | */ |
| 5534 | @Override |
| 5535 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5536 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5537 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5538 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5539 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5540 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5541 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5542 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5543 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5544 | .setCallingPid(Binder.getCallingPid()) |
| 5545 | .setCallingUid(Binder.getCallingUid()) |
| 5546 | .setMethod("requestNetworkScan") |
| 5547 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
James.cf Lin | 1d4d739 | 2020-07-03 18:22:53 +0800 | [diff] [blame] | 5548 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5549 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5550 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5551 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5552 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5553 | if (e != null) { |
| 5554 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5555 | throw e; |
| 5556 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5557 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5558 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5559 | } |
| 5560 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5561 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5562 | int callingUid = Binder.getCallingUid(); |
| 5563 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5564 | final long identity = Binder.clearCallingIdentity(); |
| 5565 | try { |
| 5566 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5567 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5568 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5569 | } finally { |
| 5570 | Binder.restoreCallingIdentity(identity); |
| 5571 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5572 | } |
| 5573 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5574 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5575 | NetworkScanRequest request, int subId) { |
| 5576 | boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid()) |
| 5577 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5578 | boolean hasNetworkScanPermission = |
| 5579 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5580 | == PERMISSION_GRANTED; |
| 5581 | |
| 5582 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5583 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5584 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5585 | } |
| 5586 | |
| 5587 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5588 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5589 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5590 | return new SecurityException("Specific channels must not be" |
| 5591 | + " scanned without location access."); |
| 5592 | } |
| 5593 | } |
| 5594 | } |
| 5595 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5596 | return null; |
| 5597 | } |
| 5598 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5599 | /** |
| 5600 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5601 | * |
| 5602 | * @param subId id of the subscription |
| 5603 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5604 | */ |
| 5605 | @Override |
| 5606 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5607 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5608 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5609 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5610 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5611 | final long identity = Binder.clearCallingIdentity(); |
| 5612 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5613 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5614 | } finally { |
| 5615 | Binder.restoreCallingIdentity(identity); |
| 5616 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5617 | } |
| 5618 | |
| 5619 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5620 | * Get the calculated preferred network type. |
| 5621 | * Used for debugging incorrect network type. |
| 5622 | * |
| 5623 | * @return the preferred network type, defined in RILConstants.java. |
| 5624 | */ |
| 5625 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5626 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5627 | final Phone defaultPhone = getDefaultPhone(); |
| 5628 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5629 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5630 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5631 | } |
| 5632 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5633 | final long identity = Binder.clearCallingIdentity(); |
| 5634 | try { |
| 5635 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5636 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5637 | } finally { |
| 5638 | Binder.restoreCallingIdentity(identity); |
| 5639 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5640 | } |
| 5641 | |
| 5642 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5643 | * Get the preferred network type. |
| 5644 | * Used for device configuration by some CDMA operators. |
| 5645 | * |
| 5646 | * @return the preferred network type, defined in RILConstants.java. |
| 5647 | */ |
| 5648 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5649 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5650 | TelephonyPermissions |
| 5651 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5652 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5653 | |
| 5654 | final long identity = Binder.clearCallingIdentity(); |
| 5655 | try { |
| 5656 | if (DBG) log("getPreferredNetworkType"); |
| 5657 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5658 | int networkType = (result != null ? result[0] : -1); |
| 5659 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5660 | return networkType; |
| 5661 | } finally { |
| 5662 | Binder.restoreCallingIdentity(identity); |
| 5663 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5664 | } |
| 5665 | |
| 5666 | /** |
| 5667 | * Set the preferred network type. |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5668 | * |
| 5669 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5670 | * @return true on success; false on any failure. |
| 5671 | */ |
| 5672 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5673 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5674 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5675 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5676 | |
| 5677 | final long identity = Binder.clearCallingIdentity(); |
| 5678 | try { |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5679 | Boolean success = (Boolean) sendRequest( |
| 5680 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
calvinpan | 03641a7 | 2020-08-18 16:53:59 +0800 | [diff] [blame] | 5681 | |
| 5682 | if (success) { |
| 5683 | Settings.Global.putInt(mApp.getContentResolver(), |
| 5684 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 5685 | } |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5686 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 5687 | return success; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5688 | } finally { |
| 5689 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5690 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5691 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5692 | |
| 5693 | /** |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5694 | * Get the allowed network types that store in the telephony provider. |
| 5695 | * |
| 5696 | * @param subId the id of the subscription. |
| 5697 | * @return allowedNetworkTypes the allowed network types. |
| 5698 | */ |
| 5699 | @Override |
| 5700 | public long getAllowedNetworkTypes(int subId) { |
| 5701 | TelephonyPermissions |
| 5702 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5703 | mApp, subId, "getAllowedNetworkTypes"); |
| 5704 | |
| 5705 | final long identity = Binder.clearCallingIdentity(); |
| 5706 | try { |
| 5707 | return SubscriptionManager.getLongSubscriptionProperty( |
| 5708 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5709 | } finally { |
| 5710 | Binder.restoreCallingIdentity(identity); |
| 5711 | } |
| 5712 | } |
| 5713 | |
| 5714 | /** |
| 5715 | * Set the allowed network types. |
| 5716 | * |
| 5717 | * @param subId the id of the subscription. |
| 5718 | * @param allowedNetworkTypes the allowed network types. |
| 5719 | * @return true on success; false on any failure. |
| 5720 | */ |
| 5721 | @Override |
| 5722 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 5723 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5724 | mApp, subId, "setAllowedNetworkTypes"); |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5725 | |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5726 | SubscriptionManager.setSubscriptionProperty(subId, |
| 5727 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 5728 | String.valueOf(allowedNetworkTypes)); |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5729 | |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5730 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 5731 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5732 | RILConstants.PREFERRED_NETWORK_MODE); |
| 5733 | return setPreferredNetworkType(subId, preferredNetworkMode); |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5734 | } |
| 5735 | |
| 5736 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 5737 | * Get the allowed network types for certain reason. |
| 5738 | * |
| 5739 | * @param subId the id of the subscription. |
| 5740 | * @param reason the reason the allowed network type change is taking place |
| 5741 | * @return the allowed network types. |
| 5742 | */ |
| 5743 | @Override |
| 5744 | public long getAllowedNetworkTypesForReason(int subId, |
| 5745 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
| 5746 | TelephonyPermissions |
| 5747 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5748 | mApp, subId, "getAllowedNetworkTypesForReason"); |
| 5749 | final long identity = Binder.clearCallingIdentity(); |
| 5750 | try { |
| 5751 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 5752 | } finally { |
| 5753 | Binder.restoreCallingIdentity(identity); |
| 5754 | } |
| 5755 | } |
| 5756 | |
| 5757 | /** |
| 5758 | * Get the effective allowed network types on the device. |
| 5759 | * This API will return an intersection of allowed network types for all reasons, |
| 5760 | * including the configuration done through setAllowedNetworkTypes |
| 5761 | * |
| 5762 | * @param subId the id of the subscription. |
| 5763 | * @return the allowed network types |
| 5764 | */ |
| 5765 | @Override |
| 5766 | public long getEffectiveAllowedNetworkTypes(int subId) { |
| 5767 | TelephonyPermissions |
| 5768 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5769 | mApp, subId, "getEffectiveAllowedNetworkTypes"); |
| 5770 | final long identity = Binder.clearCallingIdentity(); |
| 5771 | try { |
| 5772 | return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes(); |
| 5773 | } finally { |
| 5774 | Binder.restoreCallingIdentity(identity); |
| 5775 | } |
| 5776 | } |
| 5777 | |
| 5778 | /** |
| 5779 | * Set the allowed network types of the device and |
| 5780 | * provide the reason triggering the allowed network change. |
| 5781 | * |
| 5782 | * @param subId the id of the subscription. |
| 5783 | * @param reason the reason the allowed network type change is taking place |
| 5784 | * @param allowedNetworkTypes the allowed network types. |
| 5785 | * @return true on success; false on any failure. |
| 5786 | */ |
| 5787 | @Override |
| 5788 | public boolean setAllowedNetworkTypesForReason(int subId, |
| 5789 | @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) { |
| 5790 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5791 | mApp, subId, "setAllowedNetworkTypesForReason"); |
| 5792 | final long identity = Binder.clearCallingIdentity(); |
| 5793 | try { |
| 5794 | getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes); |
| 5795 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 5796 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5797 | RILConstants.PREFERRED_NETWORK_MODE); |
| 5798 | return setPreferredNetworkType(subId, preferredNetworkMode); |
| 5799 | } finally { |
| 5800 | Binder.restoreCallingIdentity(identity); |
| 5801 | } |
| 5802 | } |
| 5803 | |
| 5804 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5805 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5806 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5807 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 5808 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5809 | * @hide |
| 5810 | */ |
| 5811 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 5812 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5813 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5814 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5815 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5816 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5817 | if (phone != null) { |
| 5818 | return phone.hasMatchedTetherApnSetting(); |
| 5819 | } else { |
| 5820 | return false; |
| 5821 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5822 | } finally { |
| 5823 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5824 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5825 | } |
| 5826 | |
| 5827 | /** |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 5828 | * Enable or disable always reporting signal strength changes from radio. |
| 5829 | * |
| 5830 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 5831 | */ |
| 5832 | @Override |
| 5833 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 5834 | enforceModifyPermission(); |
| 5835 | enforceSystemCaller(); |
| 5836 | |
| 5837 | final long identity = Binder.clearCallingIdentity(); |
| 5838 | final Phone phone = getPhone(subId); |
| 5839 | try { |
| 5840 | if (phone != null) { |
| 5841 | if (DBG) { |
| 5842 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 5843 | + " isEnable=" + isEnable); |
| 5844 | } |
| 5845 | phone.setAlwaysReportSignalStrength(isEnable); |
| 5846 | } else { |
| 5847 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 5848 | + subId); |
| 5849 | } |
| 5850 | } finally { |
| 5851 | Binder.restoreCallingIdentity(identity); |
| 5852 | } |
| 5853 | } |
| 5854 | |
| 5855 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5856 | * Get the user enabled state of Mobile Data. |
| 5857 | * |
| 5858 | * TODO: remove and use isUserDataEnabled. |
| 5859 | * This can't be removed now because some vendor codes |
| 5860 | * calls through ITelephony directly while they should |
| 5861 | * use TelephonyManager. |
| 5862 | * |
| 5863 | * @return true on enabled |
| 5864 | */ |
| 5865 | @Override |
| 5866 | public boolean getDataEnabled(int subId) { |
| 5867 | return isUserDataEnabled(subId); |
| 5868 | } |
| 5869 | |
| 5870 | /** |
| 5871 | * Get whether mobile data is enabled per user setting. |
| 5872 | * |
| 5873 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 5874 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5875 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 5876 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5877 | * |
| 5878 | * @return {@code true} if data is enabled else {@code false} |
| 5879 | */ |
| 5880 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5881 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5882 | try { |
| 5883 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 5884 | null); |
| 5885 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5886 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5887 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5888 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5889 | |
| 5890 | final long identity = Binder.clearCallingIdentity(); |
| 5891 | try { |
| 5892 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5893 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5894 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5895 | if (phone != null) { |
| 5896 | boolean retVal = phone.isUserDataEnabled(); |
| 5897 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5898 | return retVal; |
| 5899 | } else { |
| 5900 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5901 | return false; |
| 5902 | } |
| 5903 | } finally { |
| 5904 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5905 | } |
| 5906 | } |
| 5907 | |
| 5908 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5909 | * Checks if the device is capable of mobile data by considering whether whether the |
| 5910 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 5911 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5912 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5913 | * @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] | 5914 | */ |
| 5915 | @Override |
| 5916 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 5917 | try { |
| 5918 | try { |
| 5919 | mApp.enforceCallingOrSelfPermission( |
| 5920 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 5921 | null); |
| 5922 | } catch (Exception e) { |
| 5923 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 5924 | "isDataEnabled"); |
| 5925 | } |
| 5926 | } catch (Exception e) { |
| 5927 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 5928 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5929 | |
| 5930 | final long identity = Binder.clearCallingIdentity(); |
| 5931 | try { |
| 5932 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5933 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5934 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5935 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5936 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5937 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5938 | return retVal; |
| 5939 | } else { |
| 5940 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5941 | return false; |
| 5942 | } |
| 5943 | } finally { |
| 5944 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5945 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5946 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5947 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 5948 | /** |
| 5949 | * Check if data is enabled for a specific reason |
| 5950 | * @param subId Subscription index |
| 5951 | * @param reason the reason the data enable change is taking place |
| 5952 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 5953 | */ |
| 5954 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 5955 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 5956 | @TelephonyManager.DataEnabledReason int reason) { |
| 5957 | try { |
| 5958 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 5959 | null); |
| 5960 | } catch (Exception e) { |
| 5961 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 5962 | "isDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 5963 | } |
| 5964 | |
| 5965 | |
| 5966 | final long identity = Binder.clearCallingIdentity(); |
| 5967 | try { |
| 5968 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5969 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 5970 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 5971 | + " reason=" + reason); |
| 5972 | } |
| 5973 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5974 | if (phone != null) { |
| 5975 | boolean retVal; |
| 5976 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 5977 | retVal = phone.isUserDataEnabled(); |
| 5978 | } else { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 5979 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 5980 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 5981 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 5982 | return retVal; |
| 5983 | } else { |
| 5984 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 5985 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 5986 | + subId + " retVal=false"); |
| 5987 | } |
| 5988 | return false; |
| 5989 | } |
| 5990 | } finally { |
| 5991 | Binder.restoreCallingIdentity(identity); |
| 5992 | } |
| 5993 | } |
| 5994 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 5995 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5996 | Phone phone) { |
Hall Liu | 54a2a0c | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 5997 | if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) { |
| 5998 | // Skip the check if it's one of these special uids |
| 5999 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6000 | } |
| 6001 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6002 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6003 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6004 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6005 | || subController == null) return privilegeFromSim; |
| 6006 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6007 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6008 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6009 | |
| 6010 | final long identity = Binder.clearCallingIdentity(); |
| 6011 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6012 | int subId = phone.getSubId(); |
| 6013 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6014 | // A test override is in place for the privileges for this subId, so don't try to |
| 6015 | // read the subscription privileges. |
| 6016 | return privilegeFromSim; |
| 6017 | } |
| 6018 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6019 | SubscriptionManager subManager = (SubscriptionManager) |
| 6020 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6021 | for (String pkg : packages) { |
| 6022 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6023 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6024 | } |
| 6025 | } |
| 6026 | return privilegeFromSim; |
| 6027 | } finally { |
| 6028 | Binder.restoreCallingIdentity(identity); |
| 6029 | } |
| 6030 | } |
| 6031 | |
| 6032 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6033 | String pkgName) { |
| 6034 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6035 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6036 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6037 | || subController == null) return privilegeFromSim; |
| 6038 | |
| 6039 | final long identity = Binder.clearCallingIdentity(); |
| 6040 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6041 | int subId = phone.getSubId(); |
| 6042 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6043 | // A test override is in place for the privileges for this subId, so don't try to |
| 6044 | // read the subscription privileges. |
| 6045 | return privilegeFromSim; |
| 6046 | } |
| 6047 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6048 | SubscriptionManager subManager = (SubscriptionManager) |
| 6049 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6050 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6051 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6052 | } finally { |
| 6053 | Binder.restoreCallingIdentity(identity); |
| 6054 | } |
| 6055 | } |
| 6056 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6057 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6058 | public int getCarrierPrivilegeStatus(int subId) { |
| 6059 | final Phone phone = getPhone(subId); |
| 6060 | if (phone == null) { |
| 6061 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6062 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6063 | } |
| 6064 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6065 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6066 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6067 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6068 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6069 | |
| 6070 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6071 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6072 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6073 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6074 | |
| 6075 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6076 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6077 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6078 | final Phone phone = getPhone(subId); |
| 6079 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6080 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6081 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6082 | } |
| 6083 | UiccProfile profile = |
| 6084 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6085 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6086 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6087 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6088 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6089 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6090 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6091 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6092 | } |
| 6093 | |
| 6094 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6095 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 6096 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6097 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6098 | } |
| 6099 | |
| 6100 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 6101 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6102 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6103 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6104 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6105 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6106 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6107 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6108 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6109 | } |
| 6110 | |
| 6111 | @Override |
| 6112 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6113 | if (TextUtils.isEmpty(pkgName)) |
| 6114 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6115 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6116 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6117 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 6118 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6119 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6120 | continue; |
| 6121 | } |
| 6122 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6123 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6124 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6125 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6126 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6127 | break; |
| 6128 | } |
| 6129 | } |
| 6130 | |
| 6131 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6132 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6133 | |
| 6134 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6135 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 6136 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6137 | loge("phoneId " + phoneId + " is not valid."); |
| 6138 | return null; |
| 6139 | } |
| 6140 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6141 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6142 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6143 | return null ; |
| 6144 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6145 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6146 | } |
| 6147 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6148 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6149 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6150 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6151 | List<String> privilegedPackages = new ArrayList<>(); |
| 6152 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6153 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 6154 | // has UICC in that slot. |
| 6155 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6156 | if (card.hasCarrierPrivilegeRules()) { |
| 6157 | if (packages == null) { |
| 6158 | // Only check packages in user 0 for now |
| 6159 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6160 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6161 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6162 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6163 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6164 | } |
| 6165 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6166 | PackageInfo pkgInfo = packages.get(p); |
| 6167 | if (pkgInfo != null && pkgInfo.packageName != null |
| 6168 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6169 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6170 | privilegedPackages.add(pkgInfo.packageName); |
| 6171 | } |
| 6172 | } |
| 6173 | } |
| 6174 | } |
| 6175 | return privilegedPackages; |
| 6176 | } |
| 6177 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6178 | @Override |
| 6179 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6180 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6181 | |
| 6182 | final long identity = Binder.clearCallingIdentity(); |
| 6183 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6184 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6185 | try { |
| 6186 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6187 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6188 | } |
| 6189 | } finally { |
| 6190 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6191 | } |
| 6192 | return privilegedPackages; |
| 6193 | } |
| 6194 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6195 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6196 | final Phone phone = getPhone(subId); |
| 6197 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6198 | if (card == null) { |
| 6199 | loge("getIccId: No UICC"); |
| 6200 | return null; |
| 6201 | } |
| 6202 | String iccId = card.getIccId(); |
| 6203 | if (TextUtils.isEmpty(iccId)) { |
| 6204 | loge("getIccId: ICC ID is null or empty."); |
| 6205 | return null; |
| 6206 | } |
| 6207 | return iccId; |
| 6208 | } |
| 6209 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6210 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6211 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6212 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6213 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6214 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6215 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6216 | final long identity = Binder.clearCallingIdentity(); |
| 6217 | try { |
| 6218 | final String iccId = getIccId(subId); |
| 6219 | final Phone phone = getPhone(subId); |
| 6220 | if (phone == null) { |
| 6221 | return false; |
| 6222 | } |
| 6223 | final String subscriberId = phone.getSubscriberId(); |
| 6224 | |
| 6225 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6226 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6227 | + subscriberId + " to " + number); |
| 6228 | } |
| 6229 | |
| 6230 | if (TextUtils.isEmpty(iccId)) { |
| 6231 | return false; |
| 6232 | } |
| 6233 | |
| 6234 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6235 | |
| 6236 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6237 | if (alphaTag == null) { |
| 6238 | editor.remove(alphaTagPrefKey); |
| 6239 | } else { |
| 6240 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6241 | } |
| 6242 | |
| 6243 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6244 | // track all merged IMSIs based on line number |
| 6245 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6246 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6247 | if (number == null) { |
| 6248 | editor.remove(numberPrefKey); |
| 6249 | editor.remove(subscriberPrefKey); |
| 6250 | } else { |
| 6251 | editor.putString(numberPrefKey, number); |
| 6252 | editor.putString(subscriberPrefKey, subscriberId); |
| 6253 | } |
| 6254 | |
| 6255 | editor.commit(); |
| 6256 | return true; |
| 6257 | } finally { |
| 6258 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6259 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6260 | } |
| 6261 | |
| 6262 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6263 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6264 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6265 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6266 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6267 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6268 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6269 | return null; |
| 6270 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6271 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6272 | final long identity = Binder.clearCallingIdentity(); |
| 6273 | try { |
| 6274 | String iccId = getIccId(subId); |
| 6275 | if (iccId != null) { |
| 6276 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6277 | if (DBG_MERGE) { |
| 6278 | log("getLine1NumberForDisplay returning " |
| 6279 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6280 | } |
| 6281 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6282 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6283 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6284 | return null; |
| 6285 | } finally { |
| 6286 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6287 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6288 | } |
| 6289 | |
| 6290 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6291 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6292 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6293 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6294 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6295 | return null; |
| 6296 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6297 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6298 | final long identity = Binder.clearCallingIdentity(); |
| 6299 | try { |
| 6300 | String iccId = getIccId(subId); |
| 6301 | if (iccId != null) { |
| 6302 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6303 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6304 | } |
| 6305 | return null; |
| 6306 | } finally { |
| 6307 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6308 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6309 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6310 | |
| 6311 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6312 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6313 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6314 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6315 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6316 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6317 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6318 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6319 | return null; |
| 6320 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6321 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6322 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6323 | // the process, where TelephonyManager was instantiated. |
| 6324 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6325 | final long identity = Binder.clearCallingIdentity(); |
| 6326 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6327 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6328 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6329 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6330 | |
| 6331 | // Figure out what subscribers are currently active |
| 6332 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6333 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6334 | // Only consider subs which match the current subId |
| 6335 | // This logic can be simplified. See b/131189269 for progress. |
| 6336 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6337 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6338 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6339 | |
| 6340 | // First pass, find a number override for an active subscriber |
| 6341 | String mergeNumber = null; |
| 6342 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6343 | for (String key : prefs.keySet()) { |
| 6344 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6345 | final String subscriberId = (String) prefs.get(key); |
| 6346 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6347 | final String iccId = key.substring( |
| 6348 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6349 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6350 | mergeNumber = (String) prefs.get(numberKey); |
| 6351 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6352 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6353 | + " for active subscriber " + subscriberId); |
| 6354 | } |
| 6355 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6356 | break; |
| 6357 | } |
| 6358 | } |
| 6359 | } |
| 6360 | } |
| 6361 | |
| 6362 | // Shortcut when no active merged subscribers |
| 6363 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6364 | return null; |
| 6365 | } |
| 6366 | |
| 6367 | // Second pass, find all subscribers under that line override |
| 6368 | final ArraySet<String> result = new ArraySet<>(); |
| 6369 | for (String key : prefs.keySet()) { |
| 6370 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6371 | final String number = (String) prefs.get(key); |
| 6372 | if (mergeNumber.equals(number)) { |
| 6373 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6374 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6375 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6376 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6377 | result.add(subscriberId); |
| 6378 | } |
| 6379 | } |
| 6380 | } |
| 6381 | } |
| 6382 | |
| 6383 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6384 | Arrays.sort(resultArray); |
| 6385 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6386 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6387 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6388 | } |
| 6389 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6390 | } finally { |
| 6391 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6392 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6393 | } |
| 6394 | |
| 6395 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6396 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6397 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6398 | |
| 6399 | final long identity = Binder.clearCallingIdentity(); |
| 6400 | try { |
| 6401 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6402 | TelephonyManager.class); |
| 6403 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6404 | if (subscriberId == null) { |
| 6405 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6406 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6407 | + subId); |
| 6408 | } |
| 6409 | return null; |
| 6410 | } |
| 6411 | |
| 6412 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6413 | .getSubscriptionInfo(subId); |
| 6414 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6415 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6416 | if (groupUuid == null) { |
| 6417 | return new String[]{subscriberId}; |
| 6418 | } |
| 6419 | |
| 6420 | // Get all subscriberIds from the group. |
| 6421 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6422 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6423 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6424 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6425 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6426 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6427 | if (subscriberId != null) { |
| 6428 | mergedSubscriberIds.add(subscriberId); |
| 6429 | } |
| 6430 | } |
| 6431 | |
| 6432 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6433 | } finally { |
| 6434 | Binder.restoreCallingIdentity(identity); |
| 6435 | |
| 6436 | } |
| 6437 | } |
| 6438 | |
| 6439 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6440 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6441 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6442 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6443 | |
| 6444 | final long identity = Binder.clearCallingIdentity(); |
| 6445 | try { |
| 6446 | final Phone phone = getPhone(subId); |
| 6447 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6448 | } finally { |
| 6449 | Binder.restoreCallingIdentity(identity); |
| 6450 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6451 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6452 | |
| 6453 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6454 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6455 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6456 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6457 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6458 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6459 | |
| 6460 | final long identity = Binder.clearCallingIdentity(); |
| 6461 | try { |
| 6462 | final Phone phone = getPhone(subId); |
| 6463 | if (phone == null) { |
| 6464 | return false; |
| 6465 | } |
| 6466 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6467 | cdmaNonRoamingList); |
| 6468 | } finally { |
| 6469 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6470 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6471 | } |
| 6472 | |
| 6473 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6474 | @Deprecated |
| 6475 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6476 | enforceModifyPermission(); |
| 6477 | |
| 6478 | int returnValue = 0; |
| 6479 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6480 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6481 | if(result.exception == null) { |
| 6482 | if (result.result != null) { |
| 6483 | byte[] responseData = (byte[])(result.result); |
| 6484 | if(responseData.length > oemResp.length) { |
| 6485 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6486 | responseData.length + "bytes. Buffer Size is " + |
| 6487 | oemResp.length + "bytes."); |
| 6488 | } |
| 6489 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6490 | returnValue = responseData.length; |
| 6491 | } |
| 6492 | } else { |
| 6493 | CommandException ex = (CommandException) result.exception; |
| 6494 | returnValue = ex.getCommandError().ordinal(); |
| 6495 | if(returnValue > 0) returnValue *= -1; |
| 6496 | } |
| 6497 | } catch (RuntimeException e) { |
| 6498 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6499 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6500 | if(returnValue > 0) returnValue *= -1; |
| 6501 | } |
| 6502 | |
| 6503 | return returnValue; |
| 6504 | } |
| 6505 | |
| 6506 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6507 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6508 | try { |
| 6509 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6510 | } catch (RuntimeException e) { |
| 6511 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6512 | } |
| 6513 | } |
| 6514 | |
| 6515 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6516 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6517 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 6518 | try { |
| 6519 | TelephonyPermissions |
| 6520 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6521 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6522 | } catch (SecurityException e) { |
| 6523 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 6524 | throw e; |
| 6525 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6526 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6527 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6528 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6529 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6530 | final long identity = Binder.clearCallingIdentity(); |
| 6531 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6532 | TelephonyPermissions |
| 6533 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6534 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6535 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6536 | } finally { |
| 6537 | Binder.restoreCallingIdentity(identity); |
| 6538 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6539 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6540 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6541 | |
| 6542 | @Override |
| 6543 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6544 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6545 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6546 | |
| 6547 | final long identity = Binder.clearCallingIdentity(); |
| 6548 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6549 | ImsManager.getInstance(defaultPhone.getContext(), |
| 6550 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6551 | } finally { |
| 6552 | Binder.restoreCallingIdentity(identity); |
| 6553 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6554 | } |
| 6555 | |
| 6556 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6557 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6558 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6559 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 6560 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6561 | return false; |
| 6562 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6563 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6564 | final long identity = Binder.clearCallingIdentity(); |
| 6565 | try { |
| 6566 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 6567 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 6568 | // In the long run, we may instead need to check if there exists a connection service |
| 6569 | // which can support video calling. |
| 6570 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6571 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6572 | return imsManager.isVtEnabledByPlatform() |
| 6573 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 6574 | && imsManager.isVtEnabledByUser(); |
| 6575 | } finally { |
| 6576 | Binder.restoreCallingIdentity(identity); |
| 6577 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6578 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 6579 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6580 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6581 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 6582 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6583 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6584 | mApp, subId, callingPackage, callingFeatureId, |
| 6585 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6586 | return false; |
| 6587 | } |
| 6588 | |
| 6589 | final long identity = Binder.clearCallingIdentity(); |
| 6590 | try { |
| 6591 | CarrierConfigManager configManager = |
| 6592 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6593 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6594 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 6595 | } finally { |
| 6596 | Binder.restoreCallingIdentity(identity); |
| 6597 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6598 | } |
| 6599 | |
| 6600 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6601 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6602 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6603 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6604 | return false; |
| 6605 | } |
| 6606 | |
| 6607 | final long identity = Binder.clearCallingIdentity(); |
| 6608 | try { |
| 6609 | CarrierConfigManager configManager = |
| 6610 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6611 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6612 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 6613 | } finally { |
| 6614 | Binder.restoreCallingIdentity(identity); |
| 6615 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6616 | } |
| 6617 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6618 | @Override |
| 6619 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6620 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 6621 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6622 | } |
| 6623 | |
| 6624 | @Override |
| 6625 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6626 | final long identity = Binder.clearCallingIdentity(); |
| 6627 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6628 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6629 | } finally { |
| 6630 | Binder.restoreCallingIdentity(identity); |
| 6631 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6632 | } |
| 6633 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6634 | /** |
| 6635 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 6636 | * support for the feature and device firmware support. |
| 6637 | * |
| 6638 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 6639 | */ |
| 6640 | @Override |
| 6641 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6642 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6643 | final Phone phone = getPhone(subscriptionId); |
| 6644 | if (phone == null) { |
| 6645 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 6646 | return false; |
| 6647 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6648 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6649 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6650 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 6651 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6652 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6653 | return isCarrierSupported && isDeviceSupported; |
| 6654 | } finally { |
| 6655 | Binder.restoreCallingIdentity(identity); |
| 6656 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 6657 | } |
| 6658 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6659 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 6660 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 6661 | * RTT setting, will return true if the device and carrier both support RTT. |
| 6662 | * 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] | 6663 | */ |
| 6664 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6665 | final long identity = Binder.clearCallingIdentity(); |
| 6666 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 6667 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 6668 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 6669 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 6670 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 6671 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 6672 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6673 | } finally { |
| 6674 | Binder.restoreCallingIdentity(identity); |
| 6675 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 6676 | } |
| 6677 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6678 | @Deprecated |
| 6679 | @Override |
| 6680 | public String getDeviceId(String callingPackage) { |
| 6681 | return getDeviceIdWithFeature(callingPackage, null); |
| 6682 | } |
| 6683 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6684 | /** |
| 6685 | * Returns the unique device ID of phone, for example, the IMEI for |
| 6686 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 6687 | * |
| 6688 | * <p>Requires Permission: |
| 6689 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 6690 | */ |
| 6691 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6692 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6693 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6694 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6695 | return null; |
| 6696 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6697 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 6698 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6699 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6700 | return null; |
| 6701 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6702 | |
| 6703 | final long identity = Binder.clearCallingIdentity(); |
| 6704 | try { |
| 6705 | return phone.getDeviceId(); |
| 6706 | } finally { |
| 6707 | Binder.restoreCallingIdentity(identity); |
| 6708 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6709 | } |
| 6710 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6711 | /** |
| 6712 | * {@hide} |
| 6713 | * Returns the IMS Registration Status on a particular subid |
| 6714 | * |
| 6715 | * @param subId |
| 6716 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6717 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6718 | Phone phone = getPhone(subId); |
| 6719 | if (phone != null) { |
| 6720 | return phone.isImsRegistered(); |
| 6721 | } else { |
| 6722 | return false; |
| 6723 | } |
| 6724 | } |
| 6725 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6726 | @Override |
| 6727 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6728 | final long identity = Binder.clearCallingIdentity(); |
| 6729 | try { |
| 6730 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 6731 | } finally { |
| 6732 | Binder.restoreCallingIdentity(identity); |
| 6733 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6734 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 6735 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6736 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6737 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6738 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6739 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6740 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6741 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6742 | } |
| 6743 | final long identity = Binder.clearCallingIdentity(); |
| 6744 | try { |
| 6745 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 6746 | } finally { |
| 6747 | Binder.restoreCallingIdentity(identity); |
| 6748 | } |
| 6749 | } |
| 6750 | |
| 6751 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6752 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
duki.hong | fd96bde | 2020-07-22 17:32:19 +0900 | [diff] [blame] | 6753 | enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, " |
| 6754 | + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6755 | final long identity = Binder.clearCallingIdentity(); |
| 6756 | try { |
| 6757 | Phone phone = getPhone(subscriptionId); |
| 6758 | if (phone == null) { |
| 6759 | return null; |
| 6760 | } |
| 6761 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 6762 | } finally { |
| 6763 | Binder.restoreCallingIdentity(identity); |
| 6764 | } |
| 6765 | } |
| 6766 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6767 | /** |
| 6768 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6769 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6770 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6771 | final long identity = Binder.clearCallingIdentity(); |
| 6772 | try { |
| 6773 | Phone phone = getPhone(subId); |
| 6774 | if (phone != null) { |
| 6775 | return phone.isWifiCallingEnabled(); |
| 6776 | } else { |
| 6777 | return false; |
| 6778 | } |
| 6779 | } finally { |
| 6780 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6781 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6782 | } |
| 6783 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6784 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6785 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6786 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6787 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6788 | final long identity = Binder.clearCallingIdentity(); |
| 6789 | try { |
| 6790 | Phone phone = getPhone(subId); |
| 6791 | if (phone != null) { |
| 6792 | return phone.isVideoEnabled(); |
| 6793 | } else { |
| 6794 | return false; |
| 6795 | } |
| 6796 | } finally { |
| 6797 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6798 | } |
| 6799 | } |
| 6800 | |
| 6801 | /** |
| 6802 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 6803 | * defined in {@link ImsRegistrationImplBase}. |
| 6804 | */ |
| 6805 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6806 | final long identity = Binder.clearCallingIdentity(); |
| 6807 | try { |
| 6808 | Phone phone = getPhone(subId); |
| 6809 | if (phone != null) { |
| 6810 | return phone.getImsRegistrationTech(); |
| 6811 | } else { |
| 6812 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 6813 | } |
| 6814 | } finally { |
| 6815 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6816 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6817 | } |
| 6818 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6819 | @Override |
| 6820 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 6821 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6822 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 6823 | return; |
| 6824 | } |
| 6825 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6826 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6827 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6828 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6829 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 6830 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6831 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6832 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6833 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6834 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6835 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 6836 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6837 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6838 | // There has been issues when Sms raw table somehow stores orphan |
| 6839 | // fragments. They lead to garbled message when new fragments come |
| 6840 | // in and combined with those stale ones. In case this happens again, |
| 6841 | // user can reset all network settings which will clean up this table. |
| 6842 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6843 | // Clean up IMS settings as well here. |
| 6844 | int slotId = getSlotIndex(subId); |
| 6845 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6846 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 6847 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 6848 | |
| 6849 | // Erase modem config if erase modem on network setting is enabled. |
| 6850 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 6851 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 6852 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 6853 | sendEraseModemConfig(getDefaultPhone()); |
| 6854 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6855 | } finally { |
| 6856 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6857 | } |
| 6858 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6859 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6860 | private void cleanUpSmsRawTable(Context context) { |
| 6861 | ContentResolver resolver = context.getContentResolver(); |
| 6862 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 6863 | resolver.delete(uri, null, null); |
| 6864 | } |
| 6865 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6866 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6867 | public String getSimLocaleForSubscriber(int subId) { |
| 6868 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 6869 | final Phone phone = getPhone(subId); |
| 6870 | if (phone == null) { |
| 6871 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 6872 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6873 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6874 | final long identity = Binder.clearCallingIdentity(); |
| 6875 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6876 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6877 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 6878 | if (info == null) { |
| 6879 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 6880 | return null; |
| 6881 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6882 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 6883 | // preferences (EF-PL and EF-LI)... |
| 6884 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6885 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6886 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 6887 | if (localeFromDefaultSim != null) { |
| 6888 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 6889 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 6890 | + localeFromDefaultSim); |
| 6891 | return localeFromDefaultSim.toLanguageTag(); |
| 6892 | } else { |
| 6893 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6894 | } |
| 6895 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6896 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6897 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 6898 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 6899 | // the SIM and carrier preferences does not include a country we add the country |
| 6900 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 6901 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6902 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6903 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6904 | return mccLocale.toLanguageTag(); |
| 6905 | } |
| 6906 | |
| 6907 | if (DBG) log("No locale found - returning null"); |
| 6908 | return null; |
| 6909 | } finally { |
| 6910 | Binder.restoreCallingIdentity(identity); |
| 6911 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6912 | } |
| 6913 | |
| 6914 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6915 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6916 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6917 | } |
| 6918 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6919 | /** |
| 6920 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 6921 | */ |
| 6922 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6923 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6924 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6925 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6926 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6927 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6928 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6929 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6930 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6931 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 6932 | * representing the state of the modem. |
| 6933 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6934 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 6935 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6936 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6937 | */ |
| 6938 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6939 | public void requestModemActivityInfo(ResultReceiver result) { |
| 6940 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6941 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6942 | |
| 6943 | final long identity = Binder.clearCallingIdentity(); |
| 6944 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 6945 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6946 | } finally { |
| 6947 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6948 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6949 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6950 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6951 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 6952 | // less than total activity duration. |
| 6953 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 6954 | if (info == null) { |
| 6955 | return false; |
| 6956 | } |
| 6957 | int activityDurationMs = |
| 6958 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 6959 | int totalTxTimeMs = 0; |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6960 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6961 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 6962 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6963 | } |
| 6964 | return (info.isValid() |
| 6965 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 6966 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6967 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6968 | && (totalTxTimeMs <= activityDurationMs)); |
| 6969 | } |
| 6970 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6971 | /** |
| 6972 | * {@hide} |
| 6973 | * Returns the service state information on specified subscription. |
| 6974 | */ |
| 6975 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6976 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 6977 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6978 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6979 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6980 | return null; |
| 6981 | } |
| 6982 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6983 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 6984 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6985 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6986 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6987 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6988 | .setCallingPid(Binder.getCallingPid()) |
| 6989 | .setCallingUid(Binder.getCallingUid()) |
| 6990 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6991 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6992 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 6993 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6994 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6995 | .build()); |
| 6996 | |
| 6997 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 6998 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6999 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7000 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7001 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7002 | .setCallingPid(Binder.getCallingPid()) |
| 7003 | .setCallingUid(Binder.getCallingUid()) |
| 7004 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7005 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7006 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7007 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7008 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7009 | .build()); |
| 7010 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7011 | boolean hasFinePermission = |
| 7012 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7013 | boolean hasCoarsePermission = |
| 7014 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7015 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7016 | final long identity = Binder.clearCallingIdentity(); |
| 7017 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7018 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7019 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7020 | Rlog.d(LOG_TAG, |
| 7021 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7022 | return null; |
| 7023 | } |
| 7024 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7025 | final Phone phone = getPhone(subId); |
| 7026 | if (phone == null) { |
| 7027 | return null; |
| 7028 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7029 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7030 | ServiceState ss = phone.getServiceState(); |
| 7031 | |
| 7032 | // Scrub out the location info in ServiceState depending on what level of access |
| 7033 | // the caller has. |
| 7034 | if (hasFinePermission) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7035 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7036 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7037 | } finally { |
| 7038 | Binder.restoreCallingIdentity(identity); |
| 7039 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7040 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7041 | |
| 7042 | /** |
| 7043 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7044 | * |
| 7045 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7046 | * voicemail ringtone. |
| 7047 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7048 | * PhoneAccount. |
| 7049 | */ |
| 7050 | @Override |
| 7051 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7052 | final long identity = Binder.clearCallingIdentity(); |
| 7053 | try { |
| 7054 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7055 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7056 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7057 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7058 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7059 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7060 | } finally { |
| 7061 | Binder.restoreCallingIdentity(identity); |
| 7062 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7063 | } |
| 7064 | |
| 7065 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7066 | * Sets the per-account voicemail ringtone. |
| 7067 | * |
| 7068 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7069 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7070 | * |
| 7071 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7072 | * voicemail ringtone. |
| 7073 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7074 | * PhoneAccount. |
| 7075 | */ |
| 7076 | @Override |
| 7077 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7078 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7079 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7080 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7081 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7082 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7083 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7084 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7085 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7086 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7087 | |
| 7088 | final long identity = Binder.clearCallingIdentity(); |
| 7089 | try { |
| 7090 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7091 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7092 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7093 | } |
| 7094 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7095 | } finally { |
| 7096 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7097 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7098 | } |
| 7099 | |
| 7100 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7101 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7102 | * |
| 7103 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7104 | * voicemail vibration setting. |
| 7105 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7106 | */ |
| 7107 | @Override |
| 7108 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7109 | final long identity = Binder.clearCallingIdentity(); |
| 7110 | try { |
| 7111 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7112 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7113 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7114 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7115 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7116 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7117 | } finally { |
| 7118 | Binder.restoreCallingIdentity(identity); |
| 7119 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7120 | } |
| 7121 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7122 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7123 | * Sets the per-account voicemail vibration. |
| 7124 | * |
| 7125 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7126 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7127 | * |
| 7128 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7129 | * voicemail vibration setting. |
| 7130 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7131 | * specific PhoneAccount. |
| 7132 | */ |
| 7133 | @Override |
| 7134 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7135 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7136 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7137 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7138 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7139 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7140 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7141 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7142 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7143 | } |
| 7144 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7145 | final long identity = Binder.clearCallingIdentity(); |
| 7146 | try { |
| 7147 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7148 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7149 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7150 | } |
| 7151 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7152 | } finally { |
| 7153 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7154 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7155 | } |
| 7156 | |
| 7157 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7158 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 7159 | * |
| 7160 | * @throws SecurityException if the caller does not have the required permission |
| 7161 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7162 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7163 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7164 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7165 | } |
| 7166 | |
| 7167 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7168 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 7169 | * permission. |
| 7170 | * |
| 7171 | * @throws SecurityException if the caller does not have the required permission |
| 7172 | */ |
| 7173 | private void enforceSendSmsPermission() { |
| 7174 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 7175 | } |
| 7176 | |
| 7177 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7178 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7179 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7180 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7181 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7182 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7183 | final long identity = Binder.clearCallingIdentity(); |
| 7184 | try { |
| 7185 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7186 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7187 | if (componentName == null) { |
| 7188 | throw new SecurityException( |
| 7189 | "Caller not current active visual voicemail package[null]"); |
| 7190 | } |
| 7191 | String vvmPackage = componentName.getPackageName(); |
| 7192 | if (!callingPackage.equals(vvmPackage)) { |
| 7193 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 7194 | + vvmPackage + "]"); |
| 7195 | } |
| 7196 | } finally { |
| 7197 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7198 | } |
| 7199 | } |
| 7200 | |
| 7201 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7202 | * Return the application ID for the app type. |
| 7203 | * |
| 7204 | * @param subId the subscription ID that this request applies to. |
| 7205 | * @param appType the uicc app type. |
| 7206 | * @return Application ID for specificied app type, or null if no uicc. |
| 7207 | */ |
| 7208 | @Override |
| 7209 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7210 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7211 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7212 | |
| 7213 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7214 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7215 | if (phone == null) { |
| 7216 | return null; |
| 7217 | } |
| 7218 | String aid = null; |
| 7219 | try { |
| 7220 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 7221 | .getApplicationByType(appType).getAid(); |
| 7222 | } catch (Exception e) { |
| 7223 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 7224 | } |
| 7225 | return aid; |
| 7226 | } finally { |
| 7227 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7228 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7229 | } |
| 7230 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7231 | /** |
| 7232 | * Return the Electronic Serial Number. |
| 7233 | * |
| 7234 | * @param subId the subscription ID that this request applies to. |
| 7235 | * @return ESN or null if error. |
| 7236 | */ |
| 7237 | @Override |
| 7238 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7239 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7240 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7241 | |
| 7242 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7243 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7244 | if (phone == null) { |
| 7245 | return null; |
| 7246 | } |
| 7247 | String esn = null; |
| 7248 | try { |
| 7249 | esn = phone.getEsn(); |
| 7250 | } catch (Exception e) { |
| 7251 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 7252 | } |
| 7253 | return esn; |
| 7254 | } finally { |
| 7255 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7256 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7257 | } |
| 7258 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7259 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7260 | * Return the Preferred Roaming List Version. |
| 7261 | * |
| 7262 | * @param subId the subscription ID that this request applies to. |
| 7263 | * @return PRLVersion or null if error. |
| 7264 | */ |
| 7265 | @Override |
| 7266 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7267 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7268 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7269 | |
| 7270 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7271 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7272 | if (phone == null) { |
| 7273 | return null; |
| 7274 | } |
| 7275 | String cdmaPrlVersion = null; |
| 7276 | try { |
| 7277 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7278 | } catch (Exception e) { |
| 7279 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7280 | } |
| 7281 | return cdmaPrlVersion; |
| 7282 | } finally { |
| 7283 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7284 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7285 | } |
| 7286 | |
| 7287 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7288 | * Get snapshot of Telephony histograms |
| 7289 | * @return List of Telephony histograms |
| 7290 | * @hide |
| 7291 | */ |
| 7292 | @Override |
| 7293 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7294 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7295 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7296 | |
| 7297 | final long identity = Binder.clearCallingIdentity(); |
| 7298 | try { |
| 7299 | return RIL.getTelephonyRILTimingHistograms(); |
| 7300 | } finally { |
| 7301 | Binder.restoreCallingIdentity(identity); |
| 7302 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7303 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7304 | |
| 7305 | /** |
| 7306 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7307 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7308 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7309 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7310 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7311 | * @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] | 7312 | */ |
| 7313 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7314 | @TelephonyManager.SetCarrierRestrictionResult |
| 7315 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7316 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7317 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7318 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7319 | if (carrierRestrictionRules == null) { |
| 7320 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7321 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7322 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7323 | final long identity = Binder.clearCallingIdentity(); |
| 7324 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7325 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7326 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7327 | } finally { |
| 7328 | Binder.restoreCallingIdentity(identity); |
| 7329 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7330 | } |
| 7331 | |
| 7332 | /** |
| 7333 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7334 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7335 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7336 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7337 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7338 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7339 | */ |
| 7340 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7341 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7342 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7343 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7344 | |
| 7345 | final long identity = Binder.clearCallingIdentity(); |
| 7346 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7347 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7348 | if (response instanceof CarrierRestrictionRules) { |
| 7349 | return (CarrierRestrictionRules) response; |
| 7350 | } |
| 7351 | // Response is an Exception of some kind, |
| 7352 | // which is signalled to the user as a NULL retval |
| 7353 | return null; |
| 7354 | } catch (Exception e) { |
| 7355 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7356 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7357 | } finally { |
| 7358 | Binder.restoreCallingIdentity(identity); |
| 7359 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7360 | } |
| 7361 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7362 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7363 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7364 | * @param subId the subscription ID that this action applies to. |
| 7365 | * @param enabled control enable or disable radio. |
| 7366 | * {@hide} |
| 7367 | */ |
| 7368 | @Override |
| 7369 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7370 | enforceModifyPermission(); |
| 7371 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7372 | |
| 7373 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7374 | if (phone == null) { |
| 7375 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7376 | return; |
| 7377 | } |
| 7378 | try { |
| 7379 | phone.carrierActionSetRadioEnabled(enabled); |
| 7380 | } catch (Exception e) { |
| 7381 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7382 | } finally { |
| 7383 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7384 | } |
| 7385 | } |
| 7386 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7387 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7388 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7389 | * network status based on which carrier apps could apply actions accordingly, |
| 7390 | * enable/disable default url handler for example. |
| 7391 | * |
| 7392 | * @param subId the subscription ID that this action applies to. |
| 7393 | * @param report control start/stop reporting the default network status. |
| 7394 | * {@hide} |
| 7395 | */ |
| 7396 | @Override |
| 7397 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7398 | enforceModifyPermission(); |
| 7399 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7400 | |
| 7401 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7402 | if (phone == null) { |
| 7403 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7404 | return; |
| 7405 | } |
| 7406 | try { |
| 7407 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7408 | } catch (Exception e) { |
| 7409 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7410 | } finally { |
| 7411 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7412 | } |
| 7413 | } |
| 7414 | |
| 7415 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7416 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7417 | * @param subId the subscription ID that this action applies to. |
| 7418 | * {@hide} |
| 7419 | */ |
| 7420 | @Override |
| 7421 | public void carrierActionResetAll(int subId) { |
| 7422 | enforceModifyPermission(); |
| 7423 | final Phone phone = getPhone(subId); |
| 7424 | if (phone == null) { |
| 7425 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7426 | return; |
| 7427 | } |
| 7428 | try { |
| 7429 | phone.carrierActionResetAll(); |
| 7430 | } catch (Exception e) { |
| 7431 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7432 | } |
| 7433 | } |
| 7434 | |
| 7435 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7436 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7437 | * bug report is being generated. |
| 7438 | */ |
| 7439 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7440 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7441 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7442 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7443 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7444 | + Binder.getCallingPid() |
| 7445 | + ", uid=" + Binder.getCallingUid() |
| 7446 | + "without permission " |
| 7447 | + android.Manifest.permission.DUMP); |
| 7448 | return; |
| 7449 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7450 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7451 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7452 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7453 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 7454 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 7455 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 7456 | @NonNull String[] args) { |
| 7457 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 7458 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 7459 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7460 | } |
| 7461 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7462 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7463 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 7464 | * @param subId Subscription index |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7465 | * @param reason the reason the data enable change is taking place |
| 7466 | * @param enabled True if enabling the data, otherwise disabling. |
| 7467 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7468 | */ |
| 7469 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7470 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7471 | boolean enabled) { |
| 7472 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 7473 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7474 | try { |
| 7475 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7476 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7477 | } catch (SecurityException se) { |
| 7478 | enforceModifyPermission(); |
| 7479 | } |
| 7480 | } else { |
| 7481 | enforceModifyPermission(); |
| 7482 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7483 | |
| 7484 | final long identity = Binder.clearCallingIdentity(); |
| 7485 | try { |
| 7486 | Phone phone = getPhone(subId); |
| 7487 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7488 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7489 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7490 | } else { |
| 7491 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 7492 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7493 | } |
| 7494 | } finally { |
| 7495 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7496 | } |
| 7497 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7498 | |
| 7499 | /** |
| 7500 | * Get Client request stats |
| 7501 | * @return List of Client Request Stats |
| 7502 | * @hide |
| 7503 | */ |
| 7504 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7505 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7506 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7507 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7508 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7509 | return null; |
| 7510 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7511 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7512 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7513 | final long identity = Binder.clearCallingIdentity(); |
| 7514 | try { |
| 7515 | if (phone != null) { |
| 7516 | return phone.getClientRequestStats(); |
| 7517 | } |
| 7518 | |
| 7519 | return null; |
| 7520 | } finally { |
| 7521 | Binder.restoreCallingIdentity(identity); |
| 7522 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7523 | } |
| 7524 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7525 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7526 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7527 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7528 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7529 | |
| 7530 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7531 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7532 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7533 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7534 | * @param state State of SIM (power down, power up, pass through) |
| 7535 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7536 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7537 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7538 | * |
| 7539 | **/ |
| 7540 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7541 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7542 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7543 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7544 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7545 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7546 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7547 | final long identity = Binder.clearCallingIdentity(); |
| 7548 | try { |
| 7549 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7550 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7551 | } |
| 7552 | } finally { |
| 7553 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7554 | } |
| 7555 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7556 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7557 | private boolean isUssdApiAllowed(int subId) { |
| 7558 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7559 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7560 | if (configManager == null) { |
| 7561 | return false; |
| 7562 | } |
| 7563 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 7564 | if (pb == null) { |
| 7565 | return false; |
| 7566 | } |
| 7567 | return pb.getBoolean( |
| 7568 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 7569 | } |
| 7570 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7571 | /** |
| 7572 | * Check if phone is in emergency callback mode |
| 7573 | * @return true if phone is in emergency callback mode |
| 7574 | * @param subId sub id |
| 7575 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 7576 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7577 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7578 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7579 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7580 | |
| 7581 | final long identity = Binder.clearCallingIdentity(); |
| 7582 | try { |
| 7583 | if (phone != null) { |
| 7584 | return phone.isInEcm(); |
| 7585 | } else { |
| 7586 | return false; |
| 7587 | } |
| 7588 | } finally { |
| 7589 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7590 | } |
| 7591 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7592 | |
| 7593 | /** |
| 7594 | * Get the current signal strength information for the given subscription. |
| 7595 | * Because this information is not updated when the device is in a low power state |
| 7596 | * it should not be relied-upon to be current. |
| 7597 | * @param subId Subscription index |
| 7598 | * @return the most recent cached signal strength info from the modem |
| 7599 | */ |
| 7600 | @Override |
| 7601 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7602 | final long identity = Binder.clearCallingIdentity(); |
| 7603 | try { |
| 7604 | Phone p = getPhone(subId); |
| 7605 | if (p == null) { |
| 7606 | return null; |
| 7607 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7608 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7609 | return p.getSignalStrength(); |
| 7610 | } finally { |
| 7611 | Binder.restoreCallingIdentity(identity); |
| 7612 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7613 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7614 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7615 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7616 | * Get the current modem radio state for the given slot. |
| 7617 | * @param slotIndex slot index. |
| 7618 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7619 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7620 | * @return the current radio power state from the modem |
| 7621 | */ |
| 7622 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7623 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7624 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7625 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7626 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 7627 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7628 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7629 | } |
| 7630 | |
| 7631 | final long identity = Binder.clearCallingIdentity(); |
| 7632 | try { |
| 7633 | return phone.getRadioPowerState(); |
| 7634 | } finally { |
| 7635 | Binder.restoreCallingIdentity(identity); |
| 7636 | } |
| 7637 | } |
| 7638 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7639 | } |
| 7640 | |
| 7641 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7642 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 7643 | * |
| 7644 | * <p>Requires one of the following permissions: |
| 7645 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 7646 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 7647 | * privileges. |
| 7648 | * |
| 7649 | * @param subId subscription id |
| 7650 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 7651 | * {@code false}. |
| 7652 | */ |
| 7653 | @Override |
| 7654 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 7655 | try { |
| 7656 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7657 | null); |
| 7658 | } catch (Exception e) { |
| 7659 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 7660 | mApp, subId, "isDataRoamingEnabled"); |
| 7661 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7662 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7663 | boolean isEnabled = false; |
| 7664 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7665 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7666 | Phone phone = getPhone(subId); |
| 7667 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7668 | } finally { |
| 7669 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7670 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7671 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7672 | } |
| 7673 | |
| 7674 | |
| 7675 | /** |
| 7676 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 7677 | * |
| 7678 | * <p> Requires permission: |
| 7679 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 7680 | * privileges. |
| 7681 | * |
| 7682 | * @param subId subscription id |
| 7683 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 7684 | */ |
| 7685 | @Override |
| 7686 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7687 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7688 | mApp, subId, "setDataRoamingEnabled"); |
| 7689 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7690 | final long identity = Binder.clearCallingIdentity(); |
| 7691 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7692 | Phone phone = getPhone(subId); |
| 7693 | if (phone != null) { |
| 7694 | phone.setDataRoamingEnabled(isEnabled); |
| 7695 | } |
| 7696 | } finally { |
| 7697 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7698 | } |
| 7699 | } |
| 7700 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7701 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7702 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 7703 | TelephonyPermissions |
| 7704 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7705 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 7706 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7707 | boolean isAllowed = true; |
| 7708 | final long identity = Binder.clearCallingIdentity(); |
| 7709 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7710 | Phone phone = getPhone(subId); |
| 7711 | if (phone != null) { |
| 7712 | isAllowed = phone.isCspPlmnEnabled(); |
| 7713 | } |
| 7714 | } finally { |
| 7715 | Binder.restoreCallingIdentity(identity); |
| 7716 | } |
| 7717 | return isAllowed; |
| 7718 | } |
| 7719 | |
| 7720 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7721 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 7722 | // Verify that tha callingPackage belongs to the calling UID |
| 7723 | mApp.getSystemService(AppOpsManager.class) |
| 7724 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 7725 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7726 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7727 | try { |
| 7728 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7729 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7730 | } catch (SecurityException e) { |
| 7731 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 7732 | // has carrier privileges on an active UICC |
| 7733 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 7734 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7735 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7736 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7737 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7738 | |
| 7739 | final long identity = Binder.clearCallingIdentity(); |
| 7740 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7741 | UiccController uiccController = UiccController.getInstance(); |
| 7742 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7743 | if (hasReadPermission) { |
| 7744 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7745 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7746 | |
| 7747 | // Remove private info if the caller doesn't have access |
| 7748 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 7749 | for (UiccCardInfo cardInfo : cardInfos) { |
| 7750 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 7751 | // is available |
| 7752 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 7753 | if (card == null || card.getUiccProfile() == null) { |
| 7754 | // assume no access if the card or profile is unavailable |
| 7755 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7756 | continue; |
| 7757 | } |
| 7758 | UiccProfile profile = card.getUiccProfile(); |
| 7759 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 7760 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7761 | filteredInfos.add(cardInfo); |
| 7762 | } else { |
| 7763 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7764 | } |
| 7765 | } |
| 7766 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7767 | } finally { |
| 7768 | Binder.restoreCallingIdentity(identity); |
| 7769 | } |
| 7770 | } |
| 7771 | |
| 7772 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7773 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7774 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7775 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7776 | final long identity = Binder.clearCallingIdentity(); |
| 7777 | try { |
| 7778 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 7779 | if (slots == null) { |
| 7780 | Rlog.i(LOG_TAG, "slots is null."); |
| 7781 | return null; |
| 7782 | } |
| 7783 | |
| 7784 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 7785 | for (int i = 0; i < slots.length; i++) { |
| 7786 | UiccSlot slot = slots[i]; |
| 7787 | if (slot == null) { |
| 7788 | continue; |
| 7789 | } |
| 7790 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7791 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7792 | UiccCard card = slot.getUiccCard(); |
| 7793 | if (card != null) { |
| 7794 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7795 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 7796 | cardId = slot.getEid(); |
| 7797 | if (TextUtils.isEmpty(cardId)) { |
| 7798 | cardId = slot.getIccId(); |
| 7799 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7800 | } |
| 7801 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 7802 | if (cardId != null) { |
| 7803 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 7804 | // if cardId is an EID, it's all digits so this is fine |
| 7805 | cardId = IccUtils.stripTrailingFs(cardId); |
| 7806 | } |
| 7807 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7808 | int cardState = 0; |
| 7809 | switch (slot.getCardState()) { |
| 7810 | case CARDSTATE_ABSENT: |
| 7811 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 7812 | break; |
| 7813 | case CARDSTATE_PRESENT: |
| 7814 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 7815 | break; |
| 7816 | case CARDSTATE_ERROR: |
| 7817 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 7818 | break; |
| 7819 | case CARDSTATE_RESTRICTED: |
| 7820 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 7821 | break; |
| 7822 | default: |
| 7823 | break; |
| 7824 | |
| 7825 | } |
| 7826 | |
| 7827 | infos[i] = new UiccSlotInfo( |
| 7828 | slot.isActive(), |
| 7829 | slot.isEuicc(), |
| 7830 | cardId, |
| 7831 | cardState, |
| 7832 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 7833 | slot.isExtendedApduSupported(), |
| 7834 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7835 | } |
| 7836 | return infos; |
| 7837 | } finally { |
| 7838 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 7839 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7840 | } |
| 7841 | |
| 7842 | @Override |
| 7843 | public boolean switchSlots(int[] physicalSlots) { |
| 7844 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7845 | |
| 7846 | final long identity = Binder.clearCallingIdentity(); |
| 7847 | try { |
| 7848 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 7849 | } finally { |
| 7850 | Binder.restoreCallingIdentity(identity); |
| 7851 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7852 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7853 | |
| 7854 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7855 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7856 | final long identity = Binder.clearCallingIdentity(); |
| 7857 | try { |
| 7858 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 7859 | } finally { |
| 7860 | Binder.restoreCallingIdentity(identity); |
| 7861 | } |
| 7862 | } |
| 7863 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7864 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 7865 | * A test API to reload the UICC profile. |
| 7866 | * |
| 7867 | * <p>Requires that the calling app has permission |
| 7868 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7869 | * @hide |
| 7870 | */ |
| 7871 | @Override |
| 7872 | public void refreshUiccProfile(int subId) { |
| 7873 | enforceModifyPermission(); |
| 7874 | |
| 7875 | final long identity = Binder.clearCallingIdentity(); |
| 7876 | try { |
| 7877 | Phone phone = getPhone(subId); |
| 7878 | if (phone == null) { |
| 7879 | return; |
| 7880 | } |
| 7881 | UiccCard uiccCard = phone.getUiccCard(); |
| 7882 | if (uiccCard == null) { |
| 7883 | return; |
| 7884 | } |
| 7885 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7886 | if (uiccProfile == null) { |
| 7887 | return; |
| 7888 | } |
| 7889 | uiccProfile.refresh(); |
| 7890 | } finally { |
| 7891 | Binder.restoreCallingIdentity(identity); |
| 7892 | } |
| 7893 | } |
| 7894 | |
| 7895 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7896 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 7897 | */ |
| 7898 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7899 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7900 | } |
| 7901 | |
| 7902 | /** |
| 7903 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 7904 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 7905 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 7906 | */ |
| 7907 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 7908 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7909 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 7910 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7911 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 7912 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 7913 | return isDataRoamingEnabled; |
| 7914 | } |
| 7915 | |
| 7916 | /** |
| 7917 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 7918 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 7919 | */ |
| 7920 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7921 | List<Integer> list = TelephonyProperties.default_network(); |
| 7922 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 7923 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 7924 | return list.get(phoneId); |
| 7925 | } |
| 7926 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7927 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7928 | |
| 7929 | @Override |
| 7930 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7931 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7932 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7933 | |
| 7934 | final long identity = Binder.clearCallingIdentity(); |
| 7935 | try { |
| 7936 | final Phone phone = getPhone(subId); |
| 7937 | if (phone == null) { |
| 7938 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 7939 | return; |
| 7940 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7941 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 7942 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 7943 | if (carrierPrivilegeRules == null) { |
| 7944 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 7945 | } else { |
| 7946 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 7947 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7948 | } finally { |
| 7949 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7950 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7951 | } |
| 7952 | |
| 7953 | @Override |
| 7954 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7955 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7956 | |
| 7957 | final long identity = Binder.clearCallingIdentity(); |
| 7958 | try { |
| 7959 | final Phone phone = getPhone(subId); |
| 7960 | if (phone == null) { |
| 7961 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 7962 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 7963 | } |
| 7964 | return phone.getCarrierIdListVersion(); |
| 7965 | } finally { |
| 7966 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7967 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7968 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7969 | |
| 7970 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7971 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 7972 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7973 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7974 | mApp, subId, callingPackage, callingFeatureId, |
| 7975 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7976 | return -1; |
| 7977 | } |
| 7978 | |
| 7979 | final long identity = Binder.clearCallingIdentity(); |
| 7980 | try { |
| 7981 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 7982 | } finally { |
| 7983 | Binder.restoreCallingIdentity(identity); |
| 7984 | } |
| 7985 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7986 | |
| 7987 | @Override |
| 7988 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 7989 | TelephonyPermissions |
| 7990 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7991 | mApp, subId, "getCdmaRoamingMode"); |
| 7992 | |
| 7993 | final long identity = Binder.clearCallingIdentity(); |
| 7994 | try { |
| 7995 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 7996 | } finally { |
| 7997 | Binder.restoreCallingIdentity(identity); |
| 7998 | } |
| 7999 | } |
| 8000 | |
| 8001 | @Override |
| 8002 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 8003 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8004 | mApp, subId, "setCdmaRoamingMode"); |
| 8005 | |
| 8006 | final long identity = Binder.clearCallingIdentity(); |
| 8007 | try { |
| 8008 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 8009 | } finally { |
| 8010 | Binder.restoreCallingIdentity(identity); |
| 8011 | } |
| 8012 | } |
| 8013 | |
| 8014 | @Override |
| 8015 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 8016 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8017 | mApp, subId, "setCdmaSubscriptionMode"); |
| 8018 | |
| 8019 | final long identity = Binder.clearCallingIdentity(); |
| 8020 | try { |
| 8021 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 8022 | } finally { |
| 8023 | Binder.restoreCallingIdentity(identity); |
| 8024 | } |
| 8025 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8026 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8027 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8028 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8029 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8030 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8031 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 8032 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8033 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8034 | } |
| 8035 | final long identity = Binder.clearCallingIdentity(); |
| 8036 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8037 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 8038 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8039 | if (phone.getEmergencyNumberTracker() != null |
| 8040 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 8041 | emergencyNumberListInternal.put( |
| 8042 | phone.getSubId(), |
| 8043 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 8044 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8045 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8046 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8047 | } finally { |
| 8048 | Binder.restoreCallingIdentity(identity); |
| 8049 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8050 | } |
| 8051 | |
| 8052 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8053 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8054 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8055 | if (!exactMatch) { |
| 8056 | TelephonyPermissions |
| 8057 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8058 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8059 | } |
| 8060 | final long identity = Binder.clearCallingIdentity(); |
| 8061 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8062 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8063 | if (phone.getEmergencyNumberTracker() != null |
| 8064 | && phone.getEmergencyNumberTracker() != null) { |
| 8065 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 8066 | number, exactMatch)) { |
| 8067 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8068 | } |
| 8069 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8070 | } |
| 8071 | return false; |
| 8072 | } finally { |
| 8073 | Binder.restoreCallingIdentity(identity); |
| 8074 | } |
| 8075 | } |
| 8076 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8077 | /** |
| 8078 | * Update emergency number list for test mode. |
| 8079 | */ |
| 8080 | @Override |
| 8081 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 8082 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8083 | "updateEmergencyNumberListTestMode"); |
| 8084 | |
| 8085 | final long identity = Binder.clearCallingIdentity(); |
| 8086 | try { |
| 8087 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8088 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8089 | if (tracker != null) { |
| 8090 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 8091 | } |
| 8092 | } |
| 8093 | } finally { |
| 8094 | Binder.restoreCallingIdentity(identity); |
| 8095 | } |
| 8096 | } |
| 8097 | |
| 8098 | /** |
| 8099 | * Get the full emergency number list for test mode. |
| 8100 | */ |
| 8101 | @Override |
| 8102 | public List<String> getEmergencyNumberListTestMode() { |
| 8103 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8104 | "getEmergencyNumberListTestMode"); |
| 8105 | |
| 8106 | final long identity = Binder.clearCallingIdentity(); |
| 8107 | try { |
| 8108 | Set<String> emergencyNumbers = new HashSet<>(); |
| 8109 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8110 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8111 | if (tracker != null) { |
| 8112 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 8113 | emergencyNumbers.add(num.getNumber()); |
| 8114 | } |
| 8115 | } |
| 8116 | } |
| 8117 | return new ArrayList<>(emergencyNumbers); |
| 8118 | } finally { |
| 8119 | Binder.restoreCallingIdentity(identity); |
| 8120 | } |
| 8121 | } |
| 8122 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8123 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8124 | public int getEmergencyNumberDbVersion(int subId) { |
| 8125 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 8126 | |
| 8127 | final long identity = Binder.clearCallingIdentity(); |
| 8128 | try { |
| 8129 | final Phone phone = getPhone(subId); |
| 8130 | if (phone == null) { |
| 8131 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 8132 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 8133 | } |
| 8134 | return phone.getEmergencyNumberDbVersion(); |
| 8135 | } finally { |
| 8136 | Binder.restoreCallingIdentity(identity); |
| 8137 | } |
| 8138 | } |
| 8139 | |
| 8140 | @Override |
| 8141 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 8142 | enforceModifyPermission(); |
| 8143 | |
| 8144 | final long identity = Binder.clearCallingIdentity(); |
| 8145 | try { |
| 8146 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8147 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8148 | if (tracker != null) { |
| 8149 | tracker.updateOtaEmergencyNumberDatabase(); |
| 8150 | } |
| 8151 | } |
| 8152 | } finally { |
| 8153 | Binder.restoreCallingIdentity(identity); |
| 8154 | } |
| 8155 | } |
| 8156 | |
| 8157 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8158 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8159 | enforceActiveEmergencySessionPermission(); |
| 8160 | |
| 8161 | final long identity = Binder.clearCallingIdentity(); |
| 8162 | try { |
| 8163 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8164 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8165 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8166 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 8167 | } |
| 8168 | } |
| 8169 | } finally { |
| 8170 | Binder.restoreCallingIdentity(identity); |
| 8171 | } |
| 8172 | } |
| 8173 | |
| 8174 | @Override |
| 8175 | public void resetOtaEmergencyNumberDbFilePath() { |
| 8176 | enforceActiveEmergencySessionPermission(); |
| 8177 | |
| 8178 | final long identity = Binder.clearCallingIdentity(); |
| 8179 | try { |
| 8180 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8181 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8182 | if (tracker != null) { |
| 8183 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8184 | } |
| 8185 | } |
| 8186 | } finally { |
| 8187 | Binder.restoreCallingIdentity(identity); |
| 8188 | } |
| 8189 | } |
| 8190 | |
| 8191 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8192 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 8193 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 8194 | Phone phone = getPhone(subId); |
| 8195 | if (phone == null) { |
| 8196 | return null; |
| 8197 | } |
| 8198 | final long identity = Binder.clearCallingIdentity(); |
| 8199 | try { |
| 8200 | UiccProfile profile = UiccController.getInstance() |
| 8201 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 8202 | if (profile != null) { |
| 8203 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 8204 | } |
| 8205 | } finally { |
| 8206 | Binder.restoreCallingIdentity(identity); |
| 8207 | } |
| 8208 | return null; |
| 8209 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 8210 | |
| 8211 | /** |
| 8212 | * Enable or disable a modem stack. |
| 8213 | */ |
| 8214 | @Override |
| 8215 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 8216 | enforceModifyPermission(); |
| 8217 | |
| 8218 | final long identity = Binder.clearCallingIdentity(); |
| 8219 | try { |
| 8220 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8221 | if (phone == null) { |
| 8222 | return false; |
| 8223 | } else { |
| 8224 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 8225 | } |
| 8226 | } finally { |
| 8227 | Binder.restoreCallingIdentity(identity); |
| 8228 | } |
| 8229 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8230 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8231 | /** |
| 8232 | * Whether a modem stack is enabled or not. |
| 8233 | */ |
| 8234 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8235 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 8236 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8237 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8238 | if (phone == null) return false; |
| 8239 | |
| 8240 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8241 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 8242 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8243 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8244 | } |
| 8245 | |
| 8246 | final long identity = Binder.clearCallingIdentity(); |
| 8247 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8248 | try { |
| 8249 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 8250 | } catch (NoSuchElementException ex) { |
| 8251 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 8252 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8253 | } finally { |
| 8254 | Binder.restoreCallingIdentity(identity); |
| 8255 | } |
| 8256 | } |
| 8257 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8258 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8259 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8260 | enforceModifyPermission(); |
| 8261 | |
| 8262 | final long identity = Binder.clearCallingIdentity(); |
| 8263 | try { |
| 8264 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8265 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8266 | .commit(); |
| 8267 | } finally { |
| 8268 | Binder.restoreCallingIdentity(identity); |
| 8269 | } |
| 8270 | } |
| 8271 | |
| 8272 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8273 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8274 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8275 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8276 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8277 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8278 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8279 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8280 | |
| 8281 | final long identity = Binder.clearCallingIdentity(); |
| 8282 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8283 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8284 | } finally { |
| 8285 | Binder.restoreCallingIdentity(identity); |
| 8286 | } |
| 8287 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8288 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8289 | @TelephonyManager.IsMultiSimSupportedResult |
| 8290 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8291 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8292 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8293 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8294 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8295 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8296 | } |
| 8297 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8298 | // supported by the modem, indicate that it is restricted. |
| 8299 | PhoneCapability staticCapability = |
| 8300 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8301 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8302 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8303 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8304 | } |
Sarah Chin | 7caee49 | 2020-02-18 20:49:02 +0000 | [diff] [blame] | 8305 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8306 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8307 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8308 | } |
| 8309 | // Check if support of multiple SIMs is restricted by carrier |
| 8310 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8311 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8312 | } |
| 8313 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8314 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8315 | } |
| 8316 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8317 | /** |
| 8318 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8319 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8320 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8321 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8322 | * @param numOfSims number of active sims we want to switch to |
| 8323 | */ |
| 8324 | @Override |
| 8325 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8326 | if (numOfSims == 1) { |
| 8327 | enforceModifyPermission(); |
| 8328 | } else { |
| 8329 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8330 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8331 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8332 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8333 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8334 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8335 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8336 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8337 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8338 | return; |
| 8339 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8340 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8341 | } finally { |
| 8342 | Binder.restoreCallingIdentity(identity); |
| 8343 | } |
| 8344 | } |
| 8345 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8346 | @Override |
| 8347 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8348 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8349 | Phone phone = getPhone(subId); |
| 8350 | if (phone == null) { |
| 8351 | return false; |
| 8352 | } |
| 8353 | final long identity = Binder.clearCallingIdentity(); |
| 8354 | try { |
| 8355 | UiccCard uiccCard = phone.getUiccCard(); |
| 8356 | if (uiccCard == null) { |
| 8357 | return false; |
| 8358 | } |
| 8359 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8360 | if (uiccProfile == null) { |
| 8361 | return false; |
| 8362 | } |
| 8363 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8364 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8365 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8366 | } |
| 8367 | return false; |
| 8368 | } finally { |
| 8369 | Binder.restoreCallingIdentity(identity); |
| 8370 | } |
| 8371 | } |
| 8372 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8373 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8374 | * Get whether making changes to modem configurations will trigger reboot. |
| 8375 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8376 | */ |
| 8377 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8378 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8379 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8380 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8381 | mApp, subId, callingPackage, callingFeatureId, |
| 8382 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8383 | return false; |
| 8384 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8385 | final long identity = Binder.clearCallingIdentity(); |
| 8386 | try { |
| 8387 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8388 | } finally { |
| 8389 | Binder.restoreCallingIdentity(identity); |
| 8390 | } |
| 8391 | } |
| 8392 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8393 | private void updateModemStateMetrics() { |
| 8394 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8395 | // TODO: check the state for each modem if the api is ready. |
| 8396 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8397 | } |
| 8398 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8399 | @Override |
| 8400 | public int[] getSlotsMapping() { |
| 8401 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8402 | |
| 8403 | final long identity = Binder.clearCallingIdentity(); |
| 8404 | try { |
| 8405 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8406 | // All logical slots should have a mapping to a physical slot. |
| 8407 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8408 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8409 | for (int i = 0; i < slotInfos.length; i++) { |
| 8410 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8411 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8412 | } |
| 8413 | } |
| 8414 | return logicalSlotsMapping; |
| 8415 | } finally { |
| 8416 | Binder.restoreCallingIdentity(identity); |
| 8417 | } |
| 8418 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8419 | |
| 8420 | /** |
| 8421 | * Get the IRadio HAL Version |
| 8422 | */ |
| 8423 | @Override |
| 8424 | public int getRadioHalVersion() { |
| 8425 | Phone phone = getDefaultPhone(); |
| 8426 | if (phone == null) return -1; |
| 8427 | HalVersion hv = phone.getHalVersion(); |
| 8428 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8429 | return hv.major * 100 + hv.minor; |
| 8430 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8431 | |
| 8432 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8433 | * Get the current calling package name. |
| 8434 | * @return the current calling package name |
| 8435 | */ |
| 8436 | @Override |
| 8437 | public String getCurrentPackageName() { |
| 8438 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8439 | } |
| 8440 | |
| 8441 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8442 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8443 | * corresponding network requests on a subId. |
| 8444 | * |
| 8445 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8446 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8447 | * 2) APN is un-metered for this subscription, or |
| 8448 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8449 | * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8450 | * |
| 8451 | * @return whether data is allowed for a apn type. |
| 8452 | * |
| 8453 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8454 | */ |
| 8455 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8456 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8457 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8458 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8459 | |
| 8460 | // Now that all security checks passes, perform the operation as ourselves. |
| 8461 | final long identity = Binder.clearCallingIdentity(); |
| 8462 | try { |
| 8463 | Phone phone = getPhone(subId); |
| 8464 | if (phone == null) return false; |
| 8465 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8466 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8467 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8468 | } finally { |
| 8469 | Binder.restoreCallingIdentity(identity); |
| 8470 | } |
| 8471 | } |
| 8472 | |
| 8473 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8474 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8475 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8476 | |
| 8477 | // Now that all security checks passes, perform the operation as ourselves. |
| 8478 | final long identity = Binder.clearCallingIdentity(); |
| 8479 | try { |
| 8480 | Phone phone = getPhone(subId); |
| 8481 | if (phone == null) return true; // By default return true. |
| 8482 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8483 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8484 | } finally { |
| 8485 | Binder.restoreCallingIdentity(identity); |
| 8486 | } |
| 8487 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8488 | |
| 8489 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 8490 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 8491 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 8492 | enforceModifyPermission(); |
| 8493 | long token = Binder.clearCallingIdentity(); |
| 8494 | try { |
| 8495 | Phone phone = getPhone(subscriptionId); |
| 8496 | if (phone == null) { |
| 8497 | try { |
| 8498 | if (resultCallback != null) { |
| 8499 | resultCallback.accept(false); |
| 8500 | } |
| 8501 | } catch (RemoteException e) { |
| 8502 | // ignore |
| 8503 | } |
| 8504 | return; |
| 8505 | } |
| 8506 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 8507 | Pair.create(specifiers, (x) -> { |
| 8508 | try { |
| 8509 | if (resultCallback != null) { |
| 8510 | resultCallback.accept(x); |
| 8511 | } |
| 8512 | } catch (RemoteException e) { |
| 8513 | // ignore |
| 8514 | } |
| 8515 | }); |
| 8516 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 8517 | } finally { |
| 8518 | Binder.restoreCallingIdentity(token); |
| 8519 | } |
| 8520 | } |
| 8521 | |
| 8522 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8523 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 8524 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8525 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 8526 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 8527 | if (iccRecords == null) { |
| 8528 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 8529 | return false; |
| 8530 | } |
| 8531 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 8532 | } |
| 8533 | |
| 8534 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8535 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 8536 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8537 | if (callingPackage == null) { |
| 8538 | callingPackage = getCurrentPackageName(); |
| 8539 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8540 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 8541 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8542 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 8543 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8544 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 8545 | } |
| 8546 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 8547 | Intent intent = new Intent(); |
| 8548 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 8549 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 8550 | // Bring up choose default SMS subscription dialog right now |
| 8551 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 8552 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 8553 | mApp.startActivity(intent); |
| 8554 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8555 | |
| 8556 | @Override |
| 8557 | public String getMmsUAProfUrl(int subId) { |
| 8558 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8559 | final long identity = Binder.clearCallingIdentity(); |
| 8560 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 8561 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 8562 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 8563 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 8564 | return carrierUAProfUrl; |
| 8565 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 8566 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8567 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8568 | } finally { |
| 8569 | Binder.restoreCallingIdentity(identity); |
| 8570 | } |
| 8571 | } |
| 8572 | |
| 8573 | @Override |
| 8574 | public String getMmsUserAgent(int subId) { |
| 8575 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8576 | final long identity = Binder.clearCallingIdentity(); |
| 8577 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 8578 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 8579 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 8580 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 8581 | return carrierUserAgent; |
| 8582 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 8583 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8584 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8585 | } finally { |
| 8586 | Binder.restoreCallingIdentity(identity); |
| 8587 | } |
| 8588 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8589 | |
| 8590 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame^] | 8591 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 8592 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
| 8593 | |
| 8594 | final long identity = Binder.clearCallingIdentity(); |
| 8595 | try { |
| 8596 | Phone phone = getPhone(subscriptionId); |
| 8597 | if (phone == null) return false; |
| 8598 | |
| 8599 | switch (policy) { |
| 8600 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 8601 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 8602 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 8603 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 8604 | default: |
| 8605 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 8606 | } |
| 8607 | } finally { |
| 8608 | Binder.restoreCallingIdentity(identity); |
| 8609 | } |
| 8610 | } |
| 8611 | |
| 8612 | @Override |
| 8613 | public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy, |
| 8614 | boolean enabled) { |
| 8615 | enforceModifyPermission(); |
| 8616 | |
| 8617 | final long identity = Binder.clearCallingIdentity(); |
| 8618 | try { |
| 8619 | Phone phone = getPhone(subscriptionId); |
| 8620 | if (phone == null) return; |
| 8621 | |
| 8622 | switch (policy) { |
| 8623 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 8624 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 8625 | break; |
| 8626 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 8627 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 8628 | break; |
| 8629 | default: |
| 8630 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 8631 | } |
| 8632 | } finally { |
| 8633 | Binder.restoreCallingIdentity(identity); |
| 8634 | } |
| 8635 | } |
| 8636 | |
| 8637 | @Override |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8638 | public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) { |
| 8639 | enforceModifyPermission(); |
| 8640 | |
| 8641 | // Now that all security checks passes, perform the operation as ourselves. |
| 8642 | final long identity = Binder.clearCallingIdentity(); |
| 8643 | try { |
| 8644 | Phone phone = getPhone(subId); |
| 8645 | if (phone == null) return false; |
| 8646 | |
| 8647 | return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow); |
| 8648 | } finally { |
| 8649 | Binder.restoreCallingIdentity(identity); |
| 8650 | } |
| 8651 | } |
| 8652 | |
| 8653 | @Override |
| 8654 | public boolean isDataAllowedInVoiceCall(int subId) { |
| 8655 | enforceReadPrivilegedPermission("isDataAllowedInVoiceCall"); |
| 8656 | |
| 8657 | // Now that all security checks passes, perform the operation as ourselves. |
| 8658 | final long identity = Binder.clearCallingIdentity(); |
| 8659 | try { |
| 8660 | Phone phone = getPhone(subId); |
| 8661 | if (phone == null) return false; |
| 8662 | |
| 8663 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 8664 | } finally { |
| 8665 | Binder.restoreCallingIdentity(identity); |
| 8666 | } |
| 8667 | } |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8668 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8669 | @Override |
| 8670 | public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) { |
| 8671 | enforceModifyPermission(); |
| 8672 | |
| 8673 | // Now that all security checks passes, perform the operation as ourselves. |
| 8674 | final long identity = Binder.clearCallingIdentity(); |
| 8675 | try { |
| 8676 | Phone phone = getPhone(subId); |
| 8677 | if (phone == null) return false; |
| 8678 | |
| 8679 | return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow); |
| 8680 | } finally { |
| 8681 | Binder.restoreCallingIdentity(identity); |
| 8682 | } |
| 8683 | } |
| 8684 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8685 | /** |
| 8686 | * Updates whether conference event pacakge handling is enabled. |
| 8687 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 8688 | * otherwise. |
| 8689 | */ |
| 8690 | @Override |
| 8691 | public void setCepEnabled(boolean isCepEnabled) { |
| 8692 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 8693 | |
| 8694 | final long identity = Binder.clearCallingIdentity(); |
| 8695 | try { |
| 8696 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 8697 | for (Phone phone : PhoneFactory.getPhones()) { |
| 8698 | Phone defaultPhone = phone.getImsPhone(); |
| 8699 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 8700 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 8701 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 8702 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 8703 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 8704 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 8705 | + imsPhone.getMsisdn()); |
| 8706 | } |
| 8707 | } |
| 8708 | } finally { |
| 8709 | Binder.restoreCallingIdentity(identity); |
| 8710 | } |
| 8711 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 8712 | |
| 8713 | /** |
| 8714 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 8715 | * |
| 8716 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 8717 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 8718 | * before being read. |
| 8719 | */ |
| 8720 | @Override |
| 8721 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 8722 | isCompressed) { |
| 8723 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8724 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
| 8725 | try { |
| 8726 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 8727 | if (configBinder == null) { |
| 8728 | Rlog.e(LOG_TAG, "null result for getImsConfig"); |
| 8729 | } else { |
| 8730 | configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed); |
| 8731 | } |
| 8732 | } catch (RemoteException e) { |
| 8733 | Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage()); |
| 8734 | } |
| 8735 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8736 | |
| 8737 | @Override |
| 8738 | public boolean isIccLockEnabled(int subId) { |
| 8739 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 8740 | |
| 8741 | // Now that all security checks passes, perform the operation as ourselves. |
| 8742 | final long identity = Binder.clearCallingIdentity(); |
| 8743 | try { |
| 8744 | Phone phone = getPhone(subId); |
| 8745 | if (phone != null && phone.getIccCard() != null) { |
| 8746 | return phone.getIccCard().getIccLockEnabled(); |
| 8747 | } else { |
| 8748 | return false; |
| 8749 | } |
| 8750 | } finally { |
| 8751 | Binder.restoreCallingIdentity(identity); |
| 8752 | } |
| 8753 | } |
| 8754 | |
| 8755 | /** |
| 8756 | * Set the ICC pin lock enabled or disabled. |
| 8757 | * |
| 8758 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 8759 | * three cases: |
| 8760 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 8761 | * successfully. |
| 8762 | * - Positive number and zero for remaining password attempts. |
| 8763 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 8764 | * |
| 8765 | */ |
| 8766 | @Override |
| 8767 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 8768 | enforceModifyPermission(); |
| 8769 | |
| 8770 | Phone phone = getPhone(subId); |
| 8771 | if (phone == null) { |
| 8772 | return 0; |
| 8773 | } |
| 8774 | // Now that all security checks passes, perform the operation as ourselves. |
| 8775 | final long identity = Binder.clearCallingIdentity(); |
| 8776 | try { |
| 8777 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 8778 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 8779 | return attemptsRemaining; |
| 8780 | |
| 8781 | } catch (Exception e) { |
| 8782 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 8783 | } finally { |
| 8784 | Binder.restoreCallingIdentity(identity); |
| 8785 | } |
| 8786 | return 0; |
| 8787 | } |
| 8788 | |
| 8789 | /** |
| 8790 | * Change the ICC password used in ICC pin lock. |
| 8791 | * |
| 8792 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 8793 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 8794 | * - Positive number and zero for remaining password attempts. |
| 8795 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 8796 | * |
| 8797 | */ |
| 8798 | @Override |
| 8799 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 8800 | enforceModifyPermission(); |
| 8801 | |
| 8802 | Phone phone = getPhone(subId); |
| 8803 | if (phone == null) { |
| 8804 | return 0; |
| 8805 | } |
| 8806 | // Now that all security checks passes, perform the operation as ourselves. |
| 8807 | final long identity = Binder.clearCallingIdentity(); |
| 8808 | try { |
| 8809 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 8810 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 8811 | return attemptsRemaining; |
| 8812 | |
| 8813 | } catch (Exception e) { |
| 8814 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 8815 | } finally { |
| 8816 | Binder.restoreCallingIdentity(identity); |
| 8817 | } |
| 8818 | return 0; |
| 8819 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 8820 | |
| 8821 | /** |
| 8822 | * Request for receiving user activity notification |
| 8823 | */ |
| 8824 | @Override |
| 8825 | public void requestUserActivityNotification() { |
| 8826 | if (!mNotifyUserActivity.get() |
| 8827 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 8828 | mNotifyUserActivity.set(true); |
| 8829 | } |
| 8830 | } |
| 8831 | |
| 8832 | /** |
| 8833 | * Called when userActivity is signalled in the power manager. |
| 8834 | * This is safe to call from any thread, with any window manager locks held or not. |
| 8835 | */ |
| 8836 | @Override |
| 8837 | public void userActivity() { |
| 8838 | // *************************************** |
| 8839 | // * Inherited from PhoneWindowManager * |
| 8840 | // *************************************** |
| 8841 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 8842 | // WITH ITS LOCKS HELD. |
| 8843 | // |
| 8844 | // This code must be VERY careful about the locks |
| 8845 | // it acquires. |
| 8846 | // In fact, the current code acquires way too many, |
| 8847 | // and probably has lurking deadlocks. |
| 8848 | |
| 8849 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 8850 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 8851 | } |
| 8852 | |
| 8853 | if (mNotifyUserActivity.getAndSet(false)) { |
| 8854 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 8855 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 8856 | } |
| 8857 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 8858 | |
| 8859 | @Override |
| 8860 | public boolean canConnectTo5GInDsdsMode() { |
| 8861 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 8862 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 8863 | } |