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; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 118 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 119 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 120 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 121 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 122 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 123 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 124 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 127 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 130 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 132 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 133 | import com.android.internal.telephony.IBooleanConsumer; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 134 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 135 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 137 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 143 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 152 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 153 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 156 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 158 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 160 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 161 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 164 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 168 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 170 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 171 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 172 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 173 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 174 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 175 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 176 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 177 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 178 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 179 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 180 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 181 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 182 | import java.io.FileDescriptor; |
| 183 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 184 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 185 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 186 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 187 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 188 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 189 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 190 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 191 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 192 | import java.util.Set; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 193 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 194 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 195 | |
| 196 | /** |
| 197 | * Implementation of the ITelephony interface. |
| 198 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 199 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 200 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 201 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 202 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 203 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 204 | |
| 205 | // Message codes used with mMainThreadHandler |
| 206 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 207 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 208 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 209 | private static final int CMD_OPEN_CHANNEL = 9; |
| 210 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 211 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 212 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 213 | private static final int CMD_NV_READ_ITEM = 13; |
| 214 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 215 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 216 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 217 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 218 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 219 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 220 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 221 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 222 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 223 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 224 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 225 | private static final int CMD_SEND_ENVELOPE = 25; |
| 226 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 227 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 228 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 229 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 230 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 231 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 232 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 233 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 234 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 235 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 236 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 237 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 238 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 239 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 240 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 241 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 242 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 243 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 244 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 245 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 246 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 247 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 248 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 249 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 250 | private static final int CMD_SWITCH_SLOTS = 50; |
| 251 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 252 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 253 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 254 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 255 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 256 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 257 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 258 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 259 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 260 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 261 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 262 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 263 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 264 | private static final int CMD_MODEM_REBOOT = 64; |
| 265 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 266 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 267 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 268 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 269 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 270 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 271 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 272 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 273 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 274 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 275 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 276 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 277 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 278 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 279 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 280 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 281 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 282 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 283 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 284 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 285 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 286 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 287 | private static final int CMD_GET_CALL_WAITING = 87; |
| 288 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 289 | private static final int CMD_SET_CALL_WAITING = 89; |
| 290 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 291 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 292 | // Parameters of select command. |
| 293 | private static final int SELECT_COMMAND = 0xA4; |
| 294 | private static final int SELECT_P1 = 0x04; |
| 295 | private static final int SELECT_P2 = 0; |
| 296 | private static final int SELECT_P3 = 0x10; |
| 297 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 298 | /** The singleton instance. */ |
| 299 | private static PhoneInterfaceManager sInstance; |
| 300 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 301 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 302 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 303 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 304 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 305 | private AppOpsManager mAppOps; |
| 306 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 307 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 308 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 309 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 310 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 311 | /** User Activity */ |
| 312 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 313 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 314 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 315 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 316 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 317 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 318 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 319 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 320 | // String to store multi SIM allowed |
| 321 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 322 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 323 | // The AID of ISD-R. |
| 324 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 325 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 326 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 327 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 328 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 329 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 330 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 331 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 332 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 333 | */ |
| 334 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 335 | "reset_network_erase_modem_config_enabled"; |
| 336 | |
| 337 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 338 | * A request object to use for transmitting data to an ICC. |
| 339 | */ |
| 340 | private static final class IccAPDUArgument { |
| 341 | public int channel, cla, command, p1, p2, p3; |
| 342 | public String data; |
| 343 | |
| 344 | public IccAPDUArgument(int channel, int cla, int command, |
| 345 | int p1, int p2, int p3, String data) { |
| 346 | this.channel = channel; |
| 347 | this.cla = cla; |
| 348 | this.command = command; |
| 349 | this.p1 = p1; |
| 350 | this.p2 = p2; |
| 351 | this.p3 = p3; |
| 352 | this.data = data; |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 357 | * A request object to use for transmitting data to an ICC. |
| 358 | */ |
| 359 | private static final class ManualNetworkSelectionArgument { |
| 360 | public OperatorInfo operatorInfo; |
| 361 | public boolean persistSelection; |
| 362 | |
| 363 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 364 | this.operatorInfo = operatorInfo; |
| 365 | this.persistSelection = persistSelection; |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 370 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 371 | * request after sending. The main thread will notify the request when it is complete. |
| 372 | */ |
| 373 | private static final class MainThreadRequest { |
| 374 | /** The argument to use for the request */ |
| 375 | public Object argument; |
| 376 | /** The result of the request that is run on the main thread */ |
| 377 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 378 | // The subscriber id that this request applies to. Defaults to |
| 379 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 380 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 381 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 382 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 383 | public Phone phone; |
| 384 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 385 | public WorkSource workSource; |
| 386 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 387 | public MainThreadRequest(Object argument) { |
| 388 | this.argument = argument; |
| 389 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 390 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 391 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 392 | this.argument = argument; |
| 393 | if (phone != null) { |
| 394 | this.phone = phone; |
| 395 | } |
| 396 | this.workSource = workSource; |
| 397 | } |
| 398 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 399 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 400 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 401 | if (subId != null) { |
| 402 | this.subId = subId; |
| 403 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 404 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 405 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 406 | } |
| 407 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 408 | private static final class IncomingThirdPartyCallArgs { |
| 409 | public final ComponentName component; |
| 410 | public final String callId; |
| 411 | public final String callerDisplayName; |
| 412 | |
| 413 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 414 | String callerDisplayName) { |
| 415 | this.component = component; |
| 416 | this.callId = callId; |
| 417 | this.callerDisplayName = callerDisplayName; |
| 418 | } |
| 419 | } |
| 420 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 421 | /** |
| 422 | * A handler that processes messages on the main thread in the phone process. Since many |
| 423 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 424 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 425 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 426 | * on, which will be notified when the operation completes and will contain the result of the |
| 427 | * request. |
| 428 | * |
| 429 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 430 | * note that request.result must be set to something non-null for the calling thread to |
| 431 | * unblock. |
| 432 | */ |
| 433 | private final class MainThreadHandler extends Handler { |
| 434 | @Override |
| 435 | public void handleMessage(Message msg) { |
| 436 | MainThreadRequest request; |
| 437 | Message onCompleted; |
| 438 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 439 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 440 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 441 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 442 | |
| 443 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 444 | case CMD_HANDLE_USSD_REQUEST: { |
| 445 | request = (MainThreadRequest) msg.obj; |
| 446 | final Phone phone = getPhoneFromRequest(request); |
| 447 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 448 | String ussdRequest = ussdObject.first; |
| 449 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 450 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 451 | if (!isUssdApiAllowed(request.subId)) { |
| 452 | // Carrier does not support use of this API, return failure. |
| 453 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 454 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 455 | Bundle returnData = new Bundle(); |
| 456 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 457 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 458 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 459 | request.result = true; |
| 460 | notifyRequester(request); |
| 461 | return; |
| 462 | } |
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 | try { |
| 465 | request.result = phone != null |
| 466 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 467 | } catch (CallStateException cse) { |
| 468 | request.result = false; |
| 469 | } |
| 470 | // Wake up the requesting thread |
| 471 | notifyRequester(request); |
| 472 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 473 | } |
| 474 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 475 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 476 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 477 | final Phone phone = getPhoneFromRequest(request); |
| 478 | request.result = phone != null ? |
| 479 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 480 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 481 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 482 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 483 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 484 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 485 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 486 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 487 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 488 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 489 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 490 | if (uiccCard == null) { |
| 491 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 492 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 493 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 494 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 495 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 496 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 497 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 498 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 499 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 500 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 501 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 502 | break; |
| 503 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 504 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 505 | ar = (AsyncResult) msg.obj; |
| 506 | request = (MainThreadRequest) ar.userObj; |
| 507 | if (ar.exception == null && ar.result != null) { |
| 508 | request.result = ar.result; |
| 509 | } else { |
| 510 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 511 | if (ar.result == null) { |
| 512 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 513 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 514 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 515 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 516 | } else { |
| 517 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 518 | } |
| 519 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 520 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 521 | break; |
| 522 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 523 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 524 | request = (MainThreadRequest) msg.obj; |
| 525 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 526 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 527 | if (uiccCard == null) { |
| 528 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 529 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 530 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 531 | } else { |
| 532 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 533 | request); |
| 534 | uiccCard.iccTransmitApduBasicChannel( |
| 535 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 536 | iccArgument.p3, iccArgument.data, onCompleted); |
| 537 | } |
| 538 | break; |
| 539 | |
| 540 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 541 | ar = (AsyncResult) msg.obj; |
| 542 | request = (MainThreadRequest) ar.userObj; |
| 543 | if (ar.exception == null && ar.result != null) { |
| 544 | request.result = ar.result; |
| 545 | } else { |
| 546 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 547 | if (ar.result == null) { |
| 548 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 549 | } else if (ar.exception instanceof CommandException) { |
| 550 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 551 | ar.exception); |
| 552 | } else { |
| 553 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 554 | } |
| 555 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 556 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 557 | break; |
| 558 | |
| 559 | case CMD_EXCHANGE_SIM_IO: |
| 560 | request = (MainThreadRequest) msg.obj; |
| 561 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 562 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 563 | if (uiccCard == null) { |
| 564 | loge("iccExchangeSimIO: No UICC"); |
| 565 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 566 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 567 | } else { |
| 568 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 569 | request); |
| 570 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 571 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 572 | iccArgument.data, onCompleted); |
| 573 | } |
| 574 | break; |
| 575 | |
| 576 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 577 | ar = (AsyncResult) msg.obj; |
| 578 | request = (MainThreadRequest) ar.userObj; |
| 579 | if (ar.exception == null && ar.result != null) { |
| 580 | request.result = ar.result; |
| 581 | } else { |
| 582 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 583 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 584 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 585 | break; |
| 586 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 587 | case CMD_SEND_ENVELOPE: |
| 588 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 589 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 590 | if (uiccCard == null) { |
| 591 | loge("sendEnvelopeWithStatus: No UICC"); |
| 592 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 593 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 594 | } else { |
| 595 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 596 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 597 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 598 | break; |
| 599 | |
| 600 | case EVENT_SEND_ENVELOPE_DONE: |
| 601 | ar = (AsyncResult) msg.obj; |
| 602 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 603 | if (ar.exception == null && ar.result != null) { |
| 604 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 605 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 606 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 607 | if (ar.result == null) { |
| 608 | loge("sendEnvelopeWithStatus: Empty response"); |
| 609 | } else if (ar.exception instanceof CommandException) { |
| 610 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 611 | ar.exception); |
| 612 | } else { |
| 613 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 614 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 615 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 616 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 617 | break; |
| 618 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 619 | case CMD_OPEN_CHANNEL: |
| 620 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 621 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 622 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 623 | if (uiccCard == null) { |
| 624 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 625 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 626 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 627 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 628 | } else { |
| 629 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 630 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 631 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 632 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 633 | break; |
| 634 | |
| 635 | case EVENT_OPEN_CHANNEL_DONE: |
| 636 | ar = (AsyncResult) msg.obj; |
| 637 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 638 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 639 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 640 | int[] result = (int[]) ar.result; |
| 641 | int channelId = result[0]; |
| 642 | byte[] selectResponse = null; |
| 643 | if (result.length > 1) { |
| 644 | selectResponse = new byte[result.length - 1]; |
| 645 | for (int i = 1; i < result.length; ++i) { |
| 646 | selectResponse[i - 1] = (byte) result[i]; |
| 647 | } |
| 648 | } |
| 649 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 650 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 651 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 652 | if (ar.result == null) { |
| 653 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 654 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 655 | if (ar.exception != null) { |
| 656 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 657 | } |
| 658 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 659 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 660 | if (ar.exception instanceof CommandException) { |
| 661 | CommandException.Error error = |
| 662 | ((CommandException) (ar.exception)).getCommandError(); |
| 663 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 664 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 665 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 666 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 667 | } |
| 668 | } |
| 669 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 670 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 671 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 672 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 673 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 674 | break; |
| 675 | |
| 676 | case CMD_CLOSE_CHANNEL: |
| 677 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 678 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 679 | if (uiccCard == null) { |
| 680 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 681 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 682 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 683 | } else { |
| 684 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 685 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 686 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 687 | break; |
| 688 | |
| 689 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 690 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 691 | break; |
| 692 | |
| 693 | case CMD_NV_READ_ITEM: |
| 694 | request = (MainThreadRequest) msg.obj; |
| 695 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 696 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 697 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 698 | break; |
| 699 | |
| 700 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 701 | ar = (AsyncResult) msg.obj; |
| 702 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 703 | if (ar.exception == null && ar.result != null) { |
| 704 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 705 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 706 | request.result = ""; |
| 707 | if (ar.result == null) { |
| 708 | loge("nvReadItem: Empty response"); |
| 709 | } else if (ar.exception instanceof CommandException) { |
| 710 | loge("nvReadItem: CommandException: " + |
| 711 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 712 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 713 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 714 | } |
| 715 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 716 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 717 | break; |
| 718 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 719 | case CMD_NV_WRITE_ITEM: |
| 720 | request = (MainThreadRequest) msg.obj; |
| 721 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 722 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 723 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 724 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 725 | break; |
| 726 | |
| 727 | case EVENT_NV_WRITE_ITEM_DONE: |
| 728 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 729 | break; |
| 730 | |
| 731 | case CMD_NV_WRITE_CDMA_PRL: |
| 732 | request = (MainThreadRequest) msg.obj; |
| 733 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 734 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 735 | break; |
| 736 | |
| 737 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 738 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 739 | break; |
| 740 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 741 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 742 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 743 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 744 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 745 | break; |
| 746 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 747 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 748 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 749 | break; |
| 750 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 751 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 752 | request = (MainThreadRequest) msg.obj; |
| 753 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 754 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 755 | break; |
| 756 | |
| 757 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 758 | ar = (AsyncResult) msg.obj; |
| 759 | request = (MainThreadRequest) ar.userObj; |
| 760 | if (ar.exception == null && ar.result != null) { |
| 761 | request.result = ar.result; // Integer |
| 762 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 763 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 764 | if (ar.result == null) { |
| 765 | loge("getPreferredNetworkType: Empty response"); |
| 766 | } else if (ar.exception instanceof CommandException) { |
| 767 | loge("getPreferredNetworkType: CommandException: " + |
| 768 | ar.exception); |
| 769 | } else { |
| 770 | loge("getPreferredNetworkType: Unknown exception"); |
| 771 | } |
| 772 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 773 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 774 | break; |
| 775 | |
| 776 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 777 | request = (MainThreadRequest) msg.obj; |
| 778 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 779 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 780 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 781 | break; |
| 782 | |
| 783 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 784 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 785 | break; |
| 786 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 787 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 788 | request = (MainThreadRequest)msg.obj; |
| 789 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 790 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 791 | break; |
| 792 | |
| 793 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 794 | ar = (AsyncResult)msg.obj; |
| 795 | request = (MainThreadRequest)ar.userObj; |
| 796 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 797 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 798 | break; |
| 799 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 800 | case CMD_SET_VOICEMAIL_NUMBER: |
| 801 | request = (MainThreadRequest) msg.obj; |
| 802 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 803 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 804 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 805 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 806 | break; |
| 807 | |
| 808 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 809 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 810 | break; |
| 811 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 812 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 813 | request = (MainThreadRequest) msg.obj; |
| 814 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 815 | request); |
| 816 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 817 | break; |
| 818 | |
| 819 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 820 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 821 | break; |
| 822 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 823 | case CMD_PERFORM_NETWORK_SCAN: |
| 824 | request = (MainThreadRequest) msg.obj; |
| 825 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 826 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 827 | break; |
| 828 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 829 | case CMD_GET_CALL_FORWARDING: |
| 830 | request = (MainThreadRequest) msg.obj; |
| 831 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
| 832 | int callForwardingReason = (Integer) request.argument; |
| 833 | getPhoneFromRequest(request).getCallForwardingOption( |
| 834 | callForwardingReason, onCompleted); |
| 835 | break; |
| 836 | |
| 837 | case EVENT_GET_CALL_FORWARDING_DONE: |
| 838 | ar = (AsyncResult) msg.obj; |
| 839 | request = (MainThreadRequest) ar.userObj; |
| 840 | CallForwardingInfo callForwardingInfo = null; |
| 841 | if (ar.exception == null && ar.result != null) { |
| 842 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 843 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 844 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 845 | // any service for voice call. |
| 846 | if ((callForwardInfo.serviceClass |
| 847 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
| 848 | callForwardingInfo = new CallForwardingInfo( |
| 849 | callForwardInfo.serviceClass, callForwardInfo.reason, |
| 850 | callForwardInfo.number, |
| 851 | callForwardInfo.timeSeconds); |
| 852 | break; |
| 853 | } |
| 854 | } |
| 855 | // Didn't find a call forward info for voice call. |
| 856 | if (callForwardingInfo == null) { |
| 857 | callForwardingInfo = new CallForwardingInfo( |
| 858 | CallForwardingInfo.STATUS_UNKNOWN_ERROR, |
| 859 | 0 /* reason */, null /* number */, 0 /* timeout */); |
| 860 | } |
| 861 | } else { |
| 862 | if (ar.result == null) { |
| 863 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 864 | } |
| 865 | if (ar.exception != null) { |
| 866 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 867 | } |
| 868 | int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR; |
| 869 | if (ar.exception instanceof CommandException) { |
| 870 | CommandException.Error error = |
| 871 | ((CommandException) (ar.exception)).getCommandError(); |
| 872 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 873 | errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE; |
| 874 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 875 | errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED; |
| 876 | } |
| 877 | } |
| 878 | callForwardingInfo = new CallForwardingInfo( |
| 879 | errorCode, 0 /* reason */, null /* number */, 0 /* timeout */); |
| 880 | } |
| 881 | request.result = callForwardingInfo; |
| 882 | notifyRequester(request); |
| 883 | break; |
| 884 | |
| 885 | case CMD_SET_CALL_FORWARDING: |
| 886 | request = (MainThreadRequest) msg.obj; |
| 887 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
| 888 | CallForwardingInfo callForwardingInfoToSet = |
| 889 | (CallForwardingInfo) request.argument; |
| 890 | getPhoneFromRequest(request).setCallForwardingOption( |
| 891 | callForwardingInfoToSet.getStatus(), |
| 892 | callForwardingInfoToSet.getReason(), |
| 893 | callForwardingInfoToSet.getNumber(), |
| 894 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 895 | break; |
| 896 | |
| 897 | case EVENT_SET_CALL_FORWARDING_DONE: |
| 898 | ar = (AsyncResult) msg.obj; |
| 899 | request = (MainThreadRequest) ar.userObj; |
| 900 | if (ar.exception == null) { |
| 901 | request.result = true; |
| 902 | } else { |
| 903 | request.result = false; |
| 904 | loge("setCallForwarding exception: " + ar.exception); |
| 905 | } |
| 906 | notifyRequester(request); |
| 907 | break; |
| 908 | |
| 909 | case CMD_GET_CALL_WAITING: |
| 910 | request = (MainThreadRequest) msg.obj; |
| 911 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 912 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 913 | break; |
| 914 | |
| 915 | case EVENT_GET_CALL_WAITING_DONE: |
| 916 | ar = (AsyncResult) msg.obj; |
| 917 | request = (MainThreadRequest) ar.userObj; |
| 918 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 919 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 920 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 921 | // Service Class is a bit mask per 3gpp 27.007. |
| 922 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 923 | if (callForwardResults.length > 1 |
| 924 | && ((callForwardResults[1] |
| 925 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
| 926 | callForwardingStatus = callForwardResults[0] == 0 |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 927 | ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE |
| 928 | : TelephonyManager.CALL_WAITING_STATUS_ACTIVE; |
| 929 | } else { |
| 930 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE; |
| 931 | } |
| 932 | } else { |
| 933 | if (ar.result == null) { |
| 934 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 935 | } |
| 936 | if (ar.exception != null) { |
| 937 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 938 | } |
| 939 | if (ar.exception instanceof CommandException) { |
| 940 | CommandException.Error error = |
| 941 | ((CommandException) (ar.exception)).getCommandError(); |
| 942 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 943 | callForwardingStatus = |
| 944 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 945 | } |
| 946 | } |
| 947 | } |
| 948 | request.result = callForwardingStatus; |
| 949 | notifyRequester(request); |
| 950 | break; |
| 951 | |
| 952 | case CMD_SET_CALL_WAITING: |
| 953 | request = (MainThreadRequest) msg.obj; |
| 954 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
| 955 | boolean isEnable = (Boolean) request.argument; |
| 956 | getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted); |
| 957 | break; |
| 958 | |
| 959 | case EVENT_SET_CALL_WAITING_DONE: |
| 960 | ar = (AsyncResult) msg.obj; |
| 961 | request = (MainThreadRequest) ar.userObj; |
| 962 | if (ar.exception == null) { |
| 963 | request.result = true; |
| 964 | } else { |
| 965 | request.result = false; |
| 966 | loge("setCallWaiting exception: " + ar.exception); |
| 967 | } |
| 968 | notifyRequester(request); |
| 969 | break; |
| 970 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 971 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 972 | ar = (AsyncResult) msg.obj; |
| 973 | request = (MainThreadRequest) ar.userObj; |
| 974 | CellNetworkScanResult cellScanResult; |
| 975 | if (ar.exception == null && ar.result != null) { |
| 976 | cellScanResult = new CellNetworkScanResult( |
| 977 | CellNetworkScanResult.STATUS_SUCCESS, |
| 978 | (List<OperatorInfo>) ar.result); |
| 979 | } else { |
| 980 | if (ar.result == null) { |
| 981 | loge("getCellNetworkScanResults: Empty response"); |
| 982 | } |
| 983 | if (ar.exception != null) { |
| 984 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 985 | } |
| 986 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 987 | if (ar.exception instanceof CommandException) { |
| 988 | CommandException.Error error = |
| 989 | ((CommandException) (ar.exception)).getCommandError(); |
| 990 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 991 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 992 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 993 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 994 | } |
| 995 | } |
| 996 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 997 | } |
| 998 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 999 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1000 | break; |
| 1001 | |
| 1002 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1003 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1004 | ManualNetworkSelectionArgument selArg = |
| 1005 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1006 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1007 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1008 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1009 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1010 | break; |
| 1011 | |
| 1012 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1013 | ar = (AsyncResult) msg.obj; |
| 1014 | request = (MainThreadRequest) ar.userObj; |
| 1015 | if (ar.exception == null) { |
| 1016 | request.result = true; |
| 1017 | } else { |
| 1018 | request.result = false; |
| 1019 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1020 | } |
| 1021 | notifyRequester(request); |
| 1022 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1023 | break; |
| 1024 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1025 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1026 | request = (MainThreadRequest) msg.obj; |
| 1027 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1028 | if (defaultPhone != null) { |
| 1029 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 1d931ee | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1030 | } else { |
| 1031 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1032 | Bundle bundle = new Bundle(); |
| 1033 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
| 1034 | new ModemActivityInfo(0, 0, 0, new int[0], 0)); |
| 1035 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1036 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1037 | break; |
| 1038 | |
| 1039 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 1040 | ar = (AsyncResult) msg.obj; |
| 1041 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 1d931ee | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1042 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1043 | |
| 1044 | ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1045 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 1d931ee | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1046 | // Update the last modem activity info and the result of the request. |
| 1047 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1048 | if (isModemActivityInfoValid(info)) { |
| 1049 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 1050 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1051 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1052 | .getTransmitTimeMillis(); |
| 1053 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1054 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1055 | } |
| 1056 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 1057 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1058 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1059 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1060 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1061 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1062 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1063 | info.getReceiveTimeMillis() |
| 1064 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1065 | } |
| 1066 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 1067 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1068 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1069 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1070 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1071 | } else { |
| 1072 | if (ar.result == null) { |
| 1073 | loge("queryModemActivityInfo: Empty response"); |
| 1074 | } else if (ar.exception instanceof CommandException) { |
| 1075 | loge("queryModemActivityInfo: CommandException: " + |
| 1076 | ar.exception); |
| 1077 | } else { |
| 1078 | loge("queryModemActivityInfo: Unknown exception"); |
| 1079 | } |
| 1080 | } |
Shuo Qian | 1d931ee | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1081 | Bundle bundle = new Bundle(); |
| 1082 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1083 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1084 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1085 | break; |
| 1086 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1087 | case CMD_SET_ALLOWED_CARRIERS: |
| 1088 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1089 | CarrierRestrictionRules argument = |
| 1090 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1091 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1092 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1093 | break; |
| 1094 | |
| 1095 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1096 | ar = (AsyncResult) msg.obj; |
| 1097 | request = (MainThreadRequest) ar.userObj; |
| 1098 | if (ar.exception == null && ar.result != null) { |
| 1099 | request.result = ar.result; |
| 1100 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1101 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1102 | if (ar.exception instanceof CommandException) { |
| 1103 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1104 | CommandException.Error error = |
| 1105 | ((CommandException) (ar.exception)).getCommandError(); |
| 1106 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1107 | request.result = |
| 1108 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1109 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1110 | } else { |
| 1111 | loge("setAllowedCarriers: Unknown exception"); |
| 1112 | } |
| 1113 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1114 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1115 | break; |
| 1116 | |
| 1117 | case CMD_GET_ALLOWED_CARRIERS: |
| 1118 | request = (MainThreadRequest) msg.obj; |
| 1119 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1120 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1121 | break; |
| 1122 | |
| 1123 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1124 | ar = (AsyncResult) msg.obj; |
| 1125 | request = (MainThreadRequest) ar.userObj; |
| 1126 | if (ar.exception == null && ar.result != null) { |
| 1127 | request.result = ar.result; |
| 1128 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1129 | request.result = new IllegalStateException( |
| 1130 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1131 | if (ar.result == null) { |
| 1132 | loge("getAllowedCarriers: Empty response"); |
| 1133 | } else if (ar.exception instanceof CommandException) { |
| 1134 | loge("getAllowedCarriers: CommandException: " + |
| 1135 | ar.exception); |
| 1136 | } else { |
| 1137 | loge("getAllowedCarriers: Unknown exception"); |
| 1138 | } |
| 1139 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1140 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1141 | break; |
| 1142 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1143 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1144 | ar = (AsyncResult) msg.obj; |
| 1145 | request = (MainThreadRequest) ar.userObj; |
| 1146 | if (ar.exception == null && ar.result != null) { |
| 1147 | request.result = ar.result; |
| 1148 | } else { |
| 1149 | request.result = new IllegalArgumentException( |
| 1150 | "Failed to retrieve Forbidden Plmns"); |
| 1151 | if (ar.result == null) { |
| 1152 | loge("getForbiddenPlmns: Empty response"); |
| 1153 | } else { |
| 1154 | loge("getForbiddenPlmns: Unknown exception"); |
| 1155 | } |
| 1156 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1157 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1158 | break; |
| 1159 | |
| 1160 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1161 | request = (MainThreadRequest) msg.obj; |
| 1162 | uiccCard = getUiccCardFromRequest(request); |
| 1163 | if (uiccCard == null) { |
| 1164 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1165 | request.result = new IllegalArgumentException( |
| 1166 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1167 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1168 | break; |
| 1169 | } |
| 1170 | Integer appType = (Integer) request.argument; |
| 1171 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1172 | if (uiccApp == null) { |
| 1173 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1174 | + appType); |
| 1175 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1176 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1177 | break; |
| 1178 | } else { |
| 1179 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1180 | + " specified type -- " + appType); |
| 1181 | } |
| 1182 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1183 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1184 | onCompleted); |
| 1185 | break; |
| 1186 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1187 | case CMD_SWITCH_SLOTS: |
| 1188 | request = (MainThreadRequest) msg.obj; |
| 1189 | int[] physicalSlots = (int[]) request.argument; |
| 1190 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1191 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1192 | break; |
| 1193 | |
| 1194 | case EVENT_SWITCH_SLOTS_DONE: |
| 1195 | ar = (AsyncResult) msg.obj; |
| 1196 | request = (MainThreadRequest) ar.userObj; |
| 1197 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1198 | notifyRequester(request); |
| 1199 | break; |
| 1200 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1201 | request = (MainThreadRequest) msg.obj; |
| 1202 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1203 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1204 | break; |
| 1205 | |
| 1206 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1207 | ar = (AsyncResult) msg.obj; |
| 1208 | request = (MainThreadRequest) ar.userObj; |
| 1209 | if (ar.exception != null) { |
| 1210 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1211 | } else { |
| 1212 | int mode = ((int[]) ar.result)[0]; |
| 1213 | if (mode == 0) { |
| 1214 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1215 | } else { |
| 1216 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1217 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1218 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1219 | notifyRequester(request); |
| 1220 | break; |
| 1221 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1222 | request = (MainThreadRequest) msg.obj; |
| 1223 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1224 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1225 | break; |
| 1226 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1227 | ar = (AsyncResult) msg.obj; |
| 1228 | request = (MainThreadRequest) ar.userObj; |
| 1229 | if (ar.exception != null) { |
| 1230 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1231 | } else { |
| 1232 | request.result = ((int[]) ar.result)[0]; |
| 1233 | } |
| 1234 | notifyRequester(request); |
| 1235 | break; |
| 1236 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1237 | request = (MainThreadRequest) msg.obj; |
| 1238 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1239 | int mode = (int) request.argument; |
| 1240 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1241 | break; |
| 1242 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1243 | ar = (AsyncResult) msg.obj; |
| 1244 | request = (MainThreadRequest) ar.userObj; |
| 1245 | request.result = ar.exception == null; |
| 1246 | notifyRequester(request); |
| 1247 | break; |
| 1248 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1249 | request = (MainThreadRequest) msg.obj; |
| 1250 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1251 | int subscriptionMode = (int) request.argument; |
| 1252 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1253 | break; |
| 1254 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1255 | ar = (AsyncResult) msg.obj; |
| 1256 | request = (MainThreadRequest) ar.userObj; |
| 1257 | request.result = ar.exception == null; |
| 1258 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1259 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1260 | case CMD_GET_ALL_CELL_INFO: |
| 1261 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1262 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1263 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1264 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1265 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1266 | ar = (AsyncResult) msg.obj; |
| 1267 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1268 | // If a timeout occurs, the response will be null |
| 1269 | request.result = (ar.exception == null && ar.result != null) |
| 1270 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1271 | synchronized (request) { |
| 1272 | request.notifyAll(); |
| 1273 | } |
| 1274 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1275 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1276 | request = (MainThreadRequest) msg.obj; |
| 1277 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1278 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1279 | break; |
| 1280 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1281 | ar = (AsyncResult) msg.obj; |
| 1282 | request = (MainThreadRequest) ar.userObj; |
| 1283 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1284 | try { |
| 1285 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1286 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1287 | cb.onError( |
| 1288 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1289 | ar.exception.getClass().getName(), |
| 1290 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1291 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1292 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1293 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1294 | } else { |
| 1295 | // use the result as returned |
| 1296 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1297 | } |
| 1298 | } catch (RemoteException re) { |
| 1299 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1300 | } |
| 1301 | break; |
| 1302 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1303 | request = (MainThreadRequest) msg.obj; |
| 1304 | WorkSource ws = (WorkSource) request.argument; |
| 1305 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1306 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1307 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1308 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1309 | ar = (AsyncResult) msg.obj; |
| 1310 | request = (MainThreadRequest) ar.userObj; |
| 1311 | if (ar.exception == null) { |
| 1312 | request.result = ar.result; |
| 1313 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1314 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1315 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1316 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1317 | } |
| 1318 | |
| 1319 | synchronized (request) { |
| 1320 | request.notifyAll(); |
| 1321 | } |
| 1322 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1323 | case CMD_MODEM_REBOOT: |
| 1324 | request = (MainThreadRequest) msg.obj; |
| 1325 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1326 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1327 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1328 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1329 | handleNullReturnEvent(msg, "rebootModem"); |
| 1330 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1331 | case CMD_REQUEST_ENABLE_MODEM: |
| 1332 | request = (MainThreadRequest) msg.obj; |
| 1333 | boolean enable = (boolean) request.argument; |
| 1334 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1335 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1336 | PhoneConfigurationManager.getInstance() |
| 1337 | .enablePhone(request.phone, enable, onCompleted); |
| 1338 | break; |
| 1339 | case EVENT_ENABLE_MODEM_DONE: |
| 1340 | ar = (AsyncResult) msg.obj; |
| 1341 | request = (MainThreadRequest) ar.userObj; |
| 1342 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1343 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1344 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1345 | if ((boolean) request.result) { |
| 1346 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1347 | updateModemStateMetrics(); |
| 1348 | } else { |
| 1349 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1350 | + ar.exception); |
| 1351 | } |
| 1352 | notifyRequester(request); |
| 1353 | break; |
| 1354 | case CMD_GET_MODEM_STATUS: |
| 1355 | request = (MainThreadRequest) msg.obj; |
| 1356 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1357 | PhoneConfigurationManager.getInstance() |
| 1358 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1359 | break; |
| 1360 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1361 | ar = (AsyncResult) msg.obj; |
| 1362 | request = (MainThreadRequest) ar.userObj; |
| 1363 | int id = request.phone.getPhoneId(); |
| 1364 | if (ar.exception == null && ar.result != null) { |
| 1365 | request.result = ar.result; |
| 1366 | //update the cache as modem status has changed |
| 1367 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1368 | (boolean) request.result); |
| 1369 | } else { |
| 1370 | // Return true if modem status cannot be retrieved. For most cases, |
| 1371 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1372 | // and disable modem are not supported. Modem is always on. |
| 1373 | // TODO: this should be fixed in R to support a third |
| 1374 | // status UNKNOWN b/131631629 |
| 1375 | request.result = true; |
| 1376 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1377 | + ar.exception); |
| 1378 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1379 | notifyRequester(request); |
| 1380 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1381 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1382 | request = (MainThreadRequest) msg.obj; |
| 1383 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1384 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1385 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1386 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1387 | break; |
| 1388 | } |
| 1389 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1390 | ar = (AsyncResult) msg.obj; |
| 1391 | request = (MainThreadRequest) ar.userObj; |
| 1392 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1393 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1394 | args.second.accept(ar.exception == null); |
| 1395 | notifyRequester(request); |
| 1396 | break; |
| 1397 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1398 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1399 | ar = (AsyncResult) msg.obj; |
| 1400 | request = (MainThreadRequest) ar.userObj; |
| 1401 | if (ar.exception == null && ar.result != null) { |
| 1402 | request.result = ar.result; |
| 1403 | } else { |
| 1404 | request.result = -1; |
| 1405 | loge("Failed to set Forbidden Plmns"); |
| 1406 | if (ar.result == null) { |
| 1407 | loge("setForbidenPlmns: Empty response"); |
| 1408 | } else if (ar.exception != null) { |
| 1409 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1410 | request.result = -1; |
| 1411 | } else { |
| 1412 | loge("setForbiddenPlmns: Unknown exception"); |
| 1413 | } |
| 1414 | } |
| 1415 | notifyRequester(request); |
| 1416 | break; |
| 1417 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1418 | request = (MainThreadRequest) msg.obj; |
| 1419 | uiccCard = getUiccCardFromRequest(request); |
| 1420 | if (uiccCard == null) { |
| 1421 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1422 | request.result = -1; |
| 1423 | notifyRequester(request); |
| 1424 | break; |
| 1425 | } |
| 1426 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1427 | (Pair<Integer, List<String>>) request.argument; |
| 1428 | appType = setFplmnsArgs.first; |
| 1429 | List<String> fplmns = setFplmnsArgs.second; |
| 1430 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1431 | if (uiccApp == null) { |
| 1432 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1433 | request.result = -1; |
| 1434 | loge("Failed to get UICC App"); |
| 1435 | notifyRequester(request); |
| 1436 | } else { |
| 1437 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1438 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1439 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1440 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1441 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1442 | case CMD_ERASE_MODEM_CONFIG: |
| 1443 | request = (MainThreadRequest) msg.obj; |
| 1444 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1445 | defaultPhone.eraseModemConfig(onCompleted); |
| 1446 | break; |
| 1447 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1448 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1449 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1450 | |
| 1451 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1452 | request = (MainThreadRequest) msg.obj; |
| 1453 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1454 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1455 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1456 | changed.first, changed.second, onCompleted); |
| 1457 | break; |
| 1458 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1459 | ar = (AsyncResult) msg.obj; |
| 1460 | request = (MainThreadRequest) ar.userObj; |
| 1461 | if (ar.exception == null) { |
| 1462 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1463 | } else { |
| 1464 | request.result = msg.arg1; |
| 1465 | } |
| 1466 | notifyRequester(request); |
| 1467 | break; |
| 1468 | |
| 1469 | case CMD_SET_ICC_LOCK_ENABLED: |
| 1470 | request = (MainThreadRequest) msg.obj; |
| 1471 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1472 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1473 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1474 | enabled.first, enabled.second, onCompleted); |
| 1475 | break; |
| 1476 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1477 | ar = (AsyncResult) msg.obj; |
| 1478 | request = (MainThreadRequest) ar.userObj; |
| 1479 | if (ar.exception == null) { |
| 1480 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1481 | } else { |
| 1482 | request.result = msg.arg1; |
| 1483 | } |
| 1484 | notifyRequester(request); |
| 1485 | break; |
| 1486 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1487 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1488 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1489 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1490 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1491 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1492 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1493 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1494 | default: |
| 1495 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1496 | break; |
| 1497 | } |
| 1498 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1499 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1500 | private void notifyRequester(MainThreadRequest request) { |
| 1501 | synchronized (request) { |
| 1502 | request.notifyAll(); |
| 1503 | } |
| 1504 | } |
| 1505 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1506 | private void handleNullReturnEvent(Message msg, String command) { |
| 1507 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1508 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1509 | if (ar.exception == null) { |
| 1510 | request.result = true; |
| 1511 | } else { |
| 1512 | request.result = false; |
| 1513 | if (ar.exception instanceof CommandException) { |
| 1514 | loge(command + ": CommandException: " + ar.exception); |
| 1515 | } else { |
| 1516 | loge(command + ": Unknown exception"); |
| 1517 | } |
| 1518 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1519 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1520 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1521 | } |
| 1522 | |
| 1523 | /** |
| 1524 | * Posts the specified command to be executed on the main thread, |
| 1525 | * waits for the request to complete, and returns the result. |
| 1526 | * @see #sendRequestAsync |
| 1527 | */ |
| 1528 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1529 | return sendRequest( |
| 1530 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1531 | } |
| 1532 | |
| 1533 | /** |
| 1534 | * Posts the specified command to be executed on the main thread, |
| 1535 | * waits for the request to complete, and returns the result. |
| 1536 | * @see #sendRequestAsync |
| 1537 | */ |
| 1538 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1539 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1540 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1541 | } |
| 1542 | |
| 1543 | /** |
| 1544 | * Posts the specified command to be executed on the main thread, |
| 1545 | * waits for the request to complete, and returns the result. |
| 1546 | * @see #sendRequestAsync |
| 1547 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1548 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1549 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1550 | } |
| 1551 | |
| 1552 | /** |
| 1553 | * Posts the specified command to be executed on the main thread, |
| 1554 | * waits for the request to complete, and returns the result. |
| 1555 | * @see #sendRequestAsync |
| 1556 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1557 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1558 | return sendRequest(command, argument, subId, null, workSource); |
| 1559 | } |
| 1560 | |
| 1561 | /** |
| 1562 | * Posts the specified command to be executed on the main thread, |
| 1563 | * waits for the request to complete, and returns the result. |
| 1564 | * @see #sendRequestAsync |
| 1565 | */ |
| 1566 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1567 | return sendRequest( |
| 1568 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1569 | } |
| 1570 | |
| 1571 | /** |
| 1572 | * Posts the specified command to be executed on the main thread, |
| 1573 | * waits for the request to complete, and returns the result. |
| 1574 | * @see #sendRequestAsync |
| 1575 | */ |
| 1576 | private Object sendRequest( |
| 1577 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1578 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1579 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1580 | } |
| 1581 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1582 | MainThreadRequest request = null; |
| 1583 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1584 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1585 | } else if (phone != null) { |
| 1586 | request = new MainThreadRequest(argument, phone, workSource); |
| 1587 | } else { |
| 1588 | request = new MainThreadRequest(argument, subId, workSource); |
| 1589 | } |
| 1590 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1591 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1592 | msg.sendToTarget(); |
| 1593 | |
| 1594 | // Wait for the request to complete |
| 1595 | synchronized (request) { |
| 1596 | while (request.result == null) { |
| 1597 | try { |
| 1598 | request.wait(); |
| 1599 | } catch (InterruptedException e) { |
| 1600 | // Do nothing, go back and wait until the request is complete |
| 1601 | } |
| 1602 | } |
| 1603 | } |
| 1604 | return request.result; |
| 1605 | } |
| 1606 | |
| 1607 | /** |
| 1608 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1609 | * Posts the specified command to be executed on the main thread, and |
| 1610 | * returns immediately. |
| 1611 | * @see #sendRequest |
| 1612 | */ |
| 1613 | private void sendRequestAsync(int command) { |
| 1614 | mMainThreadHandler.sendEmptyMessage(command); |
| 1615 | } |
| 1616 | |
| 1617 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1618 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1619 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1620 | */ |
| 1621 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1622 | sendRequestAsync(command, argument, null, null); |
| 1623 | } |
| 1624 | |
| 1625 | /** |
| 1626 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1627 | * @see {@link #sendRequest(int,Object)} |
| 1628 | */ |
| 1629 | private void sendRequestAsync( |
| 1630 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1631 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1632 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1633 | msg.sendToTarget(); |
| 1634 | } |
| 1635 | |
| 1636 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1637 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1638 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1639 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1640 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1641 | synchronized (PhoneInterfaceManager.class) { |
| 1642 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1643 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1644 | } else { |
| 1645 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1646 | } |
| 1647 | return sInstance; |
| 1648 | } |
| 1649 | } |
| 1650 | |
| 1651 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 1652 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1653 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1654 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1655 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1656 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1657 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1658 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1659 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1660 | mTelephonySharedPreferences = |
| 1661 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1662 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1663 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 1664 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1665 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1666 | publish(); |
| 1667 | } |
| 1668 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1669 | private Phone getDefaultPhone() { |
| 1670 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1671 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1672 | } |
| 1673 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1674 | private void publish() { |
| 1675 | if (DBG) log("publish: " + this); |
| 1676 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 1677 | TelephonyFrameworkInitializer |
| 1678 | .getTelephonyServiceManager() |
| 1679 | .getTelephonyServiceRegisterer() |
| 1680 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1681 | } |
| 1682 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1683 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1684 | if (request.phone != null) { |
| 1685 | return request.phone; |
| 1686 | } else { |
| 1687 | return getPhoneFromSubId(request.subId); |
| 1688 | } |
| 1689 | } |
| 1690 | |
| 1691 | private Phone getPhoneFromSubId(int subId) { |
| 1692 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1693 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1694 | } |
| 1695 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1696 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1697 | Phone phone = getPhoneFromRequest(request); |
| 1698 | return phone == null ? null : |
| 1699 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1700 | } |
| 1701 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1702 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1703 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1704 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1705 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1706 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1707 | private void sendEraseModemConfig(Phone phone) { |
| 1708 | if (phone != null) { |
| 1709 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 1710 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 1711 | final long identity = Binder.clearCallingIdentity(); |
| 1712 | try { |
| 1713 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 1714 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 1715 | } finally { |
| 1716 | Binder.restoreCallingIdentity(identity); |
| 1717 | } |
| 1718 | } |
| 1719 | } |
| 1720 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 1721 | private boolean isImsAvailableOnDevice() { |
| 1722 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 1723 | if (pm == null) { |
| 1724 | // For some reason package manger is not available.. This will fail internally anyway, |
| 1725 | // so do not throw error and allow. |
| 1726 | return true; |
| 1727 | } |
| 1728 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 1729 | } |
| 1730 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1731 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1732 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1733 | } |
| 1734 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1735 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1736 | if (DBG) log("dial: " + number); |
| 1737 | // No permission check needed here: This is just a wrapper around the |
| 1738 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1739 | // the UI before it does anything. |
| 1740 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1741 | final long identity = Binder.clearCallingIdentity(); |
| 1742 | try { |
| 1743 | String url = createTelUrl(number); |
| 1744 | if (url == null) { |
| 1745 | return; |
| 1746 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1747 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1748 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1749 | PhoneConstants.State state = mCM.getState(subId); |
| 1750 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1751 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1752 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1753 | mApp.startActivity(intent); |
| 1754 | } |
| 1755 | } finally { |
| 1756 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1757 | } |
| 1758 | } |
| 1759 | |
| 1760 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1761 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1762 | } |
| 1763 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1764 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1765 | if (DBG) log("call: " + number); |
| 1766 | |
| 1767 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1768 | // need to do a permission check since we're calling startActivity() |
| 1769 | // from the context of the phone app. |
| 1770 | enforceCallPermission(); |
| 1771 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 1772 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1773 | != AppOpsManager.MODE_ALLOWED) { |
| 1774 | return; |
| 1775 | } |
| 1776 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1777 | final long identity = Binder.clearCallingIdentity(); |
| 1778 | try { |
| 1779 | String url = createTelUrl(number); |
| 1780 | if (url == null) { |
| 1781 | return; |
| 1782 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1783 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1784 | boolean isValid = false; |
| 1785 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1786 | if (slist != null) { |
| 1787 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1788 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1789 | isValid = true; |
| 1790 | break; |
| 1791 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1792 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1793 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1794 | if (!isValid) { |
| 1795 | return; |
| 1796 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1797 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1798 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1799 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1800 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1801 | mApp.startActivity(intent); |
| 1802 | } finally { |
| 1803 | Binder.restoreCallingIdentity(identity); |
| 1804 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1805 | } |
| 1806 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1807 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1808 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1809 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1810 | } |
| 1811 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1812 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1813 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1814 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1815 | } |
| 1816 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1817 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1818 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1819 | |
| 1820 | final long identity = Binder.clearCallingIdentity(); |
| 1821 | try { |
| 1822 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1823 | checkSimPin.start(); |
| 1824 | return checkSimPin.unlockSim(null, pin); |
| 1825 | } finally { |
| 1826 | Binder.restoreCallingIdentity(identity); |
| 1827 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1828 | } |
| 1829 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1830 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1831 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1832 | |
| 1833 | final long identity = Binder.clearCallingIdentity(); |
| 1834 | try { |
| 1835 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1836 | checkSimPuk.start(); |
| 1837 | return checkSimPuk.unlockSim(puk, pin); |
| 1838 | } finally { |
| 1839 | Binder.restoreCallingIdentity(identity); |
| 1840 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1841 | } |
| 1842 | |
| 1843 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1844 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1845 | * a synchronous one. |
| 1846 | */ |
| 1847 | private static class UnlockSim extends Thread { |
| 1848 | |
| 1849 | private final IccCard mSimCard; |
| 1850 | |
| 1851 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1852 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1853 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1854 | |
| 1855 | // For replies from SimCard interface |
| 1856 | private Handler mHandler; |
| 1857 | |
| 1858 | // For async handler to identify request type |
| 1859 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1860 | |
| 1861 | public UnlockSim(IccCard simCard) { |
| 1862 | mSimCard = simCard; |
| 1863 | } |
| 1864 | |
| 1865 | @Override |
| 1866 | public void run() { |
| 1867 | Looper.prepare(); |
| 1868 | synchronized (UnlockSim.this) { |
| 1869 | mHandler = new Handler() { |
| 1870 | @Override |
| 1871 | public void handleMessage(Message msg) { |
| 1872 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1873 | switch (msg.what) { |
| 1874 | case SUPPLY_PIN_COMPLETE: |
| 1875 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1876 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1877 | mRetryCount = msg.arg1; |
| 1878 | if (ar.exception != null) { |
| 1879 | if (ar.exception instanceof CommandException && |
| 1880 | ((CommandException)(ar.exception)).getCommandError() |
| 1881 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1882 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1883 | } else { |
| 1884 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1885 | } |
| 1886 | } else { |
| 1887 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1888 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1889 | mDone = true; |
| 1890 | UnlockSim.this.notifyAll(); |
| 1891 | } |
| 1892 | break; |
| 1893 | } |
| 1894 | } |
| 1895 | }; |
| 1896 | UnlockSim.this.notifyAll(); |
| 1897 | } |
| 1898 | Looper.loop(); |
| 1899 | } |
| 1900 | |
| 1901 | /* |
| 1902 | * Use PIN or PUK to unlock SIM card |
| 1903 | * |
| 1904 | * If PUK is null, unlock SIM card with PIN |
| 1905 | * |
| 1906 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1907 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1908 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1909 | |
| 1910 | while (mHandler == null) { |
| 1911 | try { |
| 1912 | wait(); |
| 1913 | } catch (InterruptedException e) { |
| 1914 | Thread.currentThread().interrupt(); |
| 1915 | } |
| 1916 | } |
| 1917 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1918 | |
| 1919 | if (puk == null) { |
| 1920 | mSimCard.supplyPin(pin, callback); |
| 1921 | } else { |
| 1922 | mSimCard.supplyPuk(puk, pin, callback); |
| 1923 | } |
| 1924 | |
| 1925 | while (!mDone) { |
| 1926 | try { |
| 1927 | Log.d(LOG_TAG, "wait for done"); |
| 1928 | wait(); |
| 1929 | } catch (InterruptedException e) { |
| 1930 | // Restore the interrupted status |
| 1931 | Thread.currentThread().interrupt(); |
| 1932 | } |
| 1933 | } |
| 1934 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1935 | int[] resultArray = new int[2]; |
| 1936 | resultArray[0] = mResult; |
| 1937 | resultArray[1] = mRetryCount; |
| 1938 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1939 | } |
| 1940 | } |
| 1941 | |
| 1942 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1943 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1944 | |
| 1945 | } |
| 1946 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1947 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1948 | // No permission check needed here: this call is harmless, and it's |
| 1949 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1950 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1951 | final long identity = Binder.clearCallingIdentity(); |
| 1952 | try { |
| 1953 | final Phone phone = getPhone(subId); |
| 1954 | if (phone != null) { |
| 1955 | phone.updateServiceLocation(); |
| 1956 | } |
| 1957 | } finally { |
| 1958 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1959 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1960 | } |
| 1961 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1962 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1963 | @Override |
| 1964 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1965 | return isRadioOnWithFeature(callingPackage, null); |
| 1966 | } |
| 1967 | |
| 1968 | |
| 1969 | @Override |
| 1970 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 1971 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 1972 | callingFeatureId); |
| 1973 | } |
| 1974 | |
| 1975 | @Deprecated |
| 1976 | @Override |
| 1977 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 1978 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1979 | } |
| 1980 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1981 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1982 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 1983 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1984 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1985 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1986 | return false; |
| 1987 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1988 | |
| 1989 | final long identity = Binder.clearCallingIdentity(); |
| 1990 | try { |
| 1991 | return isRadioOnForSubscriber(subId); |
| 1992 | } finally { |
| 1993 | Binder.restoreCallingIdentity(identity); |
| 1994 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1995 | } |
| 1996 | |
| 1997 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1998 | final long identity = Binder.clearCallingIdentity(); |
| 1999 | try { |
| 2000 | final Phone phone = getPhone(subId); |
| 2001 | if (phone != null) { |
| 2002 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2003 | } else { |
| 2004 | return false; |
| 2005 | } |
| 2006 | } finally { |
| 2007 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2008 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2009 | } |
| 2010 | |
| 2011 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2012 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2013 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2014 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2015 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2016 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2017 | |
| 2018 | final long identity = Binder.clearCallingIdentity(); |
| 2019 | try { |
| 2020 | final Phone phone = getPhone(subId); |
| 2021 | if (phone != null) { |
| 2022 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2023 | } |
| 2024 | } finally { |
| 2025 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2026 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2027 | } |
| 2028 | |
| 2029 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2030 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2031 | } |
| 2032 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2033 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2034 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2035 | |
| 2036 | final long identity = Binder.clearCallingIdentity(); |
| 2037 | try { |
| 2038 | final Phone phone = getPhone(subId); |
| 2039 | if (phone == null) { |
| 2040 | return false; |
| 2041 | } |
| 2042 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2043 | toggleRadioOnOffForSubscriber(subId); |
| 2044 | } |
| 2045 | return true; |
| 2046 | } finally { |
| 2047 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2048 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2049 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2050 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2051 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2052 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2053 | /* |
| 2054 | * If any of the Radios are available, it will need to be |
| 2055 | * shutdown. So return true if any Radio is available. |
| 2056 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2057 | final long identity = Binder.clearCallingIdentity(); |
| 2058 | try { |
| 2059 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2060 | Phone phone = PhoneFactory.getPhone(i); |
| 2061 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2062 | } |
| 2063 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2064 | return false; |
| 2065 | } finally { |
| 2066 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2067 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2068 | } |
| 2069 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2070 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2071 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2072 | enforceModifyPermission(); |
| 2073 | |
| 2074 | final long identity = Binder.clearCallingIdentity(); |
| 2075 | try { |
| 2076 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2077 | logv("Shutting down Phone " + i); |
| 2078 | shutdownRadioUsingPhoneId(i); |
| 2079 | } |
| 2080 | } finally { |
| 2081 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2082 | } |
| 2083 | } |
| 2084 | |
| 2085 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2086 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2087 | if (phone != null && phone.isRadioAvailable()) { |
| 2088 | phone.shutdownRadio(); |
| 2089 | } |
| 2090 | } |
| 2091 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2092 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2093 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2094 | |
| 2095 | final long identity = Binder.clearCallingIdentity(); |
| 2096 | try { |
| 2097 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2098 | if (defaultPhone != null) { |
| 2099 | defaultPhone.setRadioPower(turnOn); |
| 2100 | return true; |
| 2101 | } else { |
| 2102 | loge("There's no default phone."); |
| 2103 | return false; |
| 2104 | } |
| 2105 | } finally { |
| 2106 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2107 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2108 | } |
| 2109 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2110 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2111 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2112 | |
| 2113 | final long identity = Binder.clearCallingIdentity(); |
| 2114 | try { |
| 2115 | final Phone phone = getPhone(subId); |
| 2116 | if (phone != null) { |
| 2117 | phone.setRadioPower(turnOn); |
| 2118 | return true; |
| 2119 | } else { |
| 2120 | return false; |
| 2121 | } |
| 2122 | } finally { |
| 2123 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2124 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2125 | } |
| 2126 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2127 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2128 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2129 | public boolean enableDataConnectivity() { |
| 2130 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2131 | |
| 2132 | final long identity = Binder.clearCallingIdentity(); |
| 2133 | try { |
| 2134 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2135 | final Phone phone = getPhone(subId); |
| 2136 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 2137 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2138 | return true; |
| 2139 | } else { |
| 2140 | return false; |
| 2141 | } |
| 2142 | } finally { |
| 2143 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2144 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2145 | } |
| 2146 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2147 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2148 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2149 | public boolean disableDataConnectivity() { |
| 2150 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2151 | |
| 2152 | final long identity = Binder.clearCallingIdentity(); |
| 2153 | try { |
| 2154 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2155 | final Phone phone = getPhone(subId); |
| 2156 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 2157 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2158 | return true; |
| 2159 | } else { |
| 2160 | return false; |
| 2161 | } |
| 2162 | } finally { |
| 2163 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2164 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2165 | } |
| 2166 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2167 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2168 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2169 | final long identity = Binder.clearCallingIdentity(); |
| 2170 | try { |
| 2171 | final Phone phone = getPhone(subId); |
| 2172 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2173 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2174 | } else { |
| 2175 | return false; |
| 2176 | } |
| 2177 | } finally { |
| 2178 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2179 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2180 | } |
| 2181 | |
| 2182 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2183 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2184 | } |
| 2185 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2186 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2187 | enforceCallPermission(); |
| 2188 | |
| 2189 | final long identity = Binder.clearCallingIdentity(); |
| 2190 | try { |
| 2191 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2192 | return; |
| 2193 | } |
| 2194 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2195 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2196 | } finally { |
| 2197 | Binder.restoreCallingIdentity(identity); |
| 2198 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2199 | }; |
| 2200 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2201 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2202 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2203 | |
| 2204 | final long identity = Binder.clearCallingIdentity(); |
| 2205 | try { |
| 2206 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2207 | return false; |
| 2208 | } |
| 2209 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2210 | } finally { |
| 2211 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2212 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2213 | } |
| 2214 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2215 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2216 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2217 | } |
| 2218 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2219 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2220 | final long identity = Binder.clearCallingIdentity(); |
| 2221 | try { |
| 2222 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2223 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2224 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2225 | } finally { |
| 2226 | Binder.restoreCallingIdentity(identity); |
| 2227 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2228 | } |
| 2229 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2230 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2231 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2232 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2233 | } |
| 2234 | |
| 2235 | @Override |
| 2236 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2237 | final long identity = Binder.clearCallingIdentity(); |
| 2238 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2239 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2240 | if (phone != null) { |
| 2241 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2242 | } else { |
| 2243 | return PhoneConstantConversions.convertDataState( |
| 2244 | PhoneConstants.DataState.DISCONNECTED); |
| 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 |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2252 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2253 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2254 | } |
| 2255 | |
| 2256 | @Override |
| 2257 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2258 | final long identity = Binder.clearCallingIdentity(); |
| 2259 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2260 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2261 | if (phone != null) { |
| 2262 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2263 | } else { |
| 2264 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2265 | } |
| 2266 | } finally { |
| 2267 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2268 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2269 | } |
| 2270 | |
| 2271 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2272 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2273 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2274 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2275 | |
| 2276 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2277 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2278 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2279 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2280 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2281 | .setCallingPid(Binder.getCallingPid()) |
| 2282 | .setCallingUid(Binder.getCallingUid()) |
| 2283 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2284 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2285 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2286 | .build()); |
| 2287 | switch (locationResult) { |
| 2288 | case DENIED_HARD: |
| 2289 | throw new SecurityException("Not allowed to access cell location"); |
| 2290 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2291 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2292 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2293 | } |
| 2294 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2295 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2296 | final long identity = Binder.clearCallingIdentity(); |
| 2297 | try { |
| 2298 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2299 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2300 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2301 | } finally { |
| 2302 | Binder.restoreCallingIdentity(identity); |
| 2303 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2304 | } |
| 2305 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2306 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2307 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2308 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2309 | // registered cell info, so return a NULL country instead. |
| 2310 | final long identity = Binder.clearCallingIdentity(); |
| 2311 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2312 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2313 | // Get default phone in this case. |
| 2314 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2315 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2316 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2317 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2318 | if (phone == null) return ""; |
| 2319 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2320 | if (sst == null) return ""; |
| 2321 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2322 | if (lt == null) return ""; |
| 2323 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry(); |
| 2324 | EmergencyNumberTracker ent = phone.getEmergencyNumberTracker(); |
| 2325 | return (ent == null) ? "" : ent.getEmergencyCountryIso(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2326 | } finally { |
| 2327 | Binder.restoreCallingIdentity(identity); |
| 2328 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2329 | } |
| 2330 | |
| 2331 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2332 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2333 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2334 | } |
| 2335 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2336 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2337 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2338 | mApp.enforceCallingOrSelfPermission( |
| 2339 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2340 | |
| 2341 | final long identity = Binder.clearCallingIdentity(); |
| 2342 | try { |
| 2343 | final Phone phone = getPhone(subId); |
| 2344 | if (phone != null) { |
| 2345 | phone.enableLocationUpdates(); |
| 2346 | } |
| 2347 | } finally { |
| 2348 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2349 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2350 | } |
| 2351 | |
| 2352 | @Override |
| 2353 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2354 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2355 | } |
| 2356 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2357 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2358 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2359 | mApp.enforceCallingOrSelfPermission( |
| 2360 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2361 | |
| 2362 | final long identity = Binder.clearCallingIdentity(); |
| 2363 | try { |
| 2364 | final Phone phone = getPhone(subId); |
| 2365 | if (phone != null) { |
| 2366 | phone.disableLocationUpdates(); |
| 2367 | } |
| 2368 | } finally { |
| 2369 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2370 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2371 | } |
| 2372 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2373 | /** |
| 2374 | * Returns the target SDK version number for a given package name. |
| 2375 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2376 | * This call MUST be invoked before clearing the calling UID. |
| 2377 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2378 | * @return target SDK if the package is found or INT_MAX. |
| 2379 | */ |
| 2380 | private int getTargetSdk(String packageName) { |
| 2381 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2382 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 0150f0e | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2383 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2384 | if (ai != null) return ai.targetSdkVersion; |
| 2385 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2386 | loge("Failed to get package info for pkg=" |
| 2387 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2388 | } |
| 2389 | return Integer.MAX_VALUE; |
| 2390 | } |
| 2391 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2392 | @Override |
| 2393 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2394 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2395 | String callingFeatureId) { |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2396 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2397 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2398 | throw new SecurityException( |
| 2399 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2400 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2401 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2402 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2403 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2404 | return null; |
| 2405 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2406 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2407 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2408 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2409 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2410 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2411 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2412 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2413 | for (CellInfo ci : info) { |
| 2414 | if (ci instanceof CellInfoGsm) { |
| 2415 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2416 | } else if (ci instanceof CellInfoWcdma) { |
| 2417 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2418 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2419 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2420 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2421 | } |
| 2422 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2423 | private List<CellInfo> getCachedCellInfo() { |
| 2424 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2425 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2426 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2427 | if (info != null) cellInfos.addAll(info); |
| 2428 | } |
| 2429 | return cellInfos; |
| 2430 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2431 | |
| 2432 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2433 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2434 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2435 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2436 | |
| 2437 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2438 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2439 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2440 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2441 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2442 | .setCallingPid(Binder.getCallingPid()) |
| 2443 | .setCallingUid(Binder.getCallingUid()) |
| 2444 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2445 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2446 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2447 | .build()); |
| 2448 | switch (locationResult) { |
| 2449 | case DENIED_HARD: |
| 2450 | throw new SecurityException("Not allowed to access cell info"); |
| 2451 | case DENIED_SOFT: |
| 2452 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2453 | } |
| 2454 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2455 | final int targetSdk = getTargetSdk(callingPackage); |
| 2456 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2457 | return getCachedCellInfo(); |
| 2458 | } |
| 2459 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2460 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2461 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2462 | final long identity = Binder.clearCallingIdentity(); |
| 2463 | try { |
| 2464 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2465 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2466 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2467 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2468 | if (info != null) cellInfos.addAll(info); |
| 2469 | } |
| 2470 | return cellInfos; |
| 2471 | } finally { |
| 2472 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2473 | } |
| 2474 | } |
| 2475 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2476 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2477 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2478 | String callingFeatureId) { |
| 2479 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2480 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2481 | } |
| 2482 | |
| 2483 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2484 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2485 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2486 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2487 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2488 | } |
| 2489 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2490 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2491 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2492 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2493 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2494 | |
| 2495 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2496 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2497 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2498 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2499 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2500 | .setCallingPid(Binder.getCallingPid()) |
| 2501 | .setCallingUid(Binder.getCallingUid()) |
| 2502 | .setMethod("requestCellInfoUpdate") |
| 2503 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2504 | .build()); |
| 2505 | switch (locationResult) { |
| 2506 | case DENIED_HARD: |
| 2507 | throw new SecurityException("Not allowed to access cell info"); |
| 2508 | case DENIED_SOFT: |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2509 | try { |
| 2510 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2511 | } catch (RemoteException re) { |
| 2512 | // Drop without consequences |
| 2513 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2514 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2515 | } |
| 2516 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2517 | |
| 2518 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2519 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2520 | |
| 2521 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2522 | } |
| 2523 | |
| 2524 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2525 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2526 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2527 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2528 | |
| 2529 | final long identity = Binder.clearCallingIdentity(); |
| 2530 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2531 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2532 | } finally { |
| 2533 | Binder.restoreCallingIdentity(identity); |
| 2534 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2535 | } |
| 2536 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2537 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2538 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2539 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2540 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2541 | return null; |
| 2542 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2543 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2544 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2545 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2546 | return null; |
| 2547 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2548 | |
| 2549 | final long identity = Binder.clearCallingIdentity(); |
| 2550 | try { |
| 2551 | return phone.getImei(); |
| 2552 | } finally { |
| 2553 | Binder.restoreCallingIdentity(identity); |
| 2554 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2555 | } |
| 2556 | |
| 2557 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2558 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2559 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2560 | String tac = null; |
| 2561 | if (phone != null) { |
| 2562 | String imei = phone.getImei(); |
| 2563 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2564 | } |
| 2565 | return tac; |
| 2566 | } |
| 2567 | |
| 2568 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2569 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2570 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2571 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2572 | return null; |
| 2573 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2574 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2575 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2576 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2577 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2578 | return null; |
| 2579 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2580 | |
| 2581 | final long identity = Binder.clearCallingIdentity(); |
| 2582 | try { |
| 2583 | return phone.getMeid(); |
| 2584 | } finally { |
| 2585 | Binder.restoreCallingIdentity(identity); |
| 2586 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2587 | } |
| 2588 | |
| 2589 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2590 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2591 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2592 | String manufacturerCode = null; |
| 2593 | if (phone != null) { |
| 2594 | String meid = phone.getMeid(); |
| 2595 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2596 | } |
| 2597 | return manufacturerCode; |
| 2598 | } |
| 2599 | |
| 2600 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2601 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2602 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2603 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2604 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2605 | return null; |
| 2606 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2607 | int subId = phone.getSubId(); |
| 2608 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2609 | mApp, subId, callingPackage, callingFeatureId, |
| 2610 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2611 | return null; |
| 2612 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2613 | |
| 2614 | final long identity = Binder.clearCallingIdentity(); |
| 2615 | try { |
| 2616 | return phone.getDeviceSvn(); |
| 2617 | } finally { |
| 2618 | Binder.restoreCallingIdentity(identity); |
| 2619 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2620 | } |
| 2621 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2622 | @Override |
| 2623 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2624 | final long identity = Binder.clearCallingIdentity(); |
| 2625 | try { |
| 2626 | final Phone phone = getPhone(subId); |
| 2627 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2628 | } finally { |
| 2629 | Binder.restoreCallingIdentity(identity); |
| 2630 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2631 | } |
| 2632 | |
| 2633 | @Override |
| 2634 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2635 | final long identity = Binder.clearCallingIdentity(); |
| 2636 | try { |
| 2637 | final Phone phone = getPhone(subId); |
| 2638 | return phone == null ? null : phone.getCarrierName(); |
| 2639 | } finally { |
| 2640 | Binder.restoreCallingIdentity(identity); |
| 2641 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2642 | } |
| 2643 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2644 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2645 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2646 | final long identity = Binder.clearCallingIdentity(); |
| 2647 | try { |
| 2648 | final Phone phone = getPhone(subId); |
| 2649 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2650 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2651 | } finally { |
| 2652 | Binder.restoreCallingIdentity(identity); |
| 2653 | } |
| 2654 | } |
| 2655 | |
| 2656 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2657 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2658 | final long identity = Binder.clearCallingIdentity(); |
| 2659 | try { |
| 2660 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2661 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2662 | } finally { |
| 2663 | Binder.restoreCallingIdentity(identity); |
| 2664 | } |
| 2665 | } |
| 2666 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2667 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2668 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2669 | if (!isSubscriptionMccMnc) { |
| 2670 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2671 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2672 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2673 | if (phone == null) { |
| 2674 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2675 | } |
| 2676 | final long identity = Binder.clearCallingIdentity(); |
| 2677 | try { |
| 2678 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2679 | } finally { |
| 2680 | Binder.restoreCallingIdentity(identity); |
| 2681 | } |
| 2682 | } |
| 2683 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2684 | // |
| 2685 | // Internal helper methods. |
| 2686 | // |
| 2687 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2688 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2689 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2690 | * |
| 2691 | * @throws SecurityException if the caller does not have the required permission |
| 2692 | */ |
| 2693 | private void enforceModifyPermission() { |
| 2694 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2695 | } |
| 2696 | |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 2697 | /** |
| 2698 | * Make sure the caller is system. |
| 2699 | * |
| 2700 | * @throws SecurityException if the caller is not system. |
| 2701 | */ |
| 2702 | private void enforceSystemCaller() { |
| 2703 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 2704 | throw new SecurityException("Caller must be system"); |
| 2705 | } |
| 2706 | } |
| 2707 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 2708 | private void enforceActiveEmergencySessionPermission() { |
| 2709 | mApp.enforceCallingOrSelfPermission( |
| 2710 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 2711 | } |
| 2712 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2713 | /** |
| 2714 | * Make sure the caller has the CALL_PHONE permission. |
| 2715 | * |
| 2716 | * @throws SecurityException if the caller does not have the required permission |
| 2717 | */ |
| 2718 | private void enforceCallPermission() { |
| 2719 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2720 | } |
| 2721 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 2722 | private void enforceSettingsPermission() { |
| 2723 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2724 | } |
| 2725 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2726 | private String createTelUrl(String number) { |
| 2727 | if (TextUtils.isEmpty(number)) { |
| 2728 | return null; |
| 2729 | } |
| 2730 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2731 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2732 | } |
| 2733 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2734 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2735 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2736 | } |
| 2737 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2738 | private static void logv(String msg) { |
| 2739 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2740 | } |
| 2741 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2742 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2743 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2744 | } |
| 2745 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2746 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2747 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2748 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2749 | } |
| 2750 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2751 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2752 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2753 | final long identity = Binder.clearCallingIdentity(); |
| 2754 | try { |
| 2755 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2756 | if (phone == null) { |
| 2757 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2758 | } else { |
| 2759 | return phone.getPhoneType(); |
| 2760 | } |
| 2761 | } finally { |
| 2762 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2763 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2764 | } |
| 2765 | |
| 2766 | /** |
| 2767 | * Returns the CDMA ERI icon index to display |
| 2768 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2769 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2770 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 2771 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 2772 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2773 | } |
| 2774 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2775 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2776 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 2777 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2778 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2779 | mApp, subId, callingPackage, callingFeatureId, |
| 2780 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2781 | return -1; |
| 2782 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2783 | |
| 2784 | final long identity = Binder.clearCallingIdentity(); |
| 2785 | try { |
| 2786 | final Phone phone = getPhone(subId); |
| 2787 | if (phone != null) { |
| 2788 | return phone.getCdmaEriIconIndex(); |
| 2789 | } else { |
| 2790 | return -1; |
| 2791 | } |
| 2792 | } finally { |
| 2793 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2794 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2795 | } |
| 2796 | |
| 2797 | /** |
| 2798 | * Returns the CDMA ERI icon mode, |
| 2799 | * 0 - ON |
| 2800 | * 1 - FLASHING |
| 2801 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2802 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2803 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 2804 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 2805 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2806 | } |
| 2807 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2808 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2809 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 2810 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2811 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2812 | mApp, subId, callingPackage, callingFeatureId, |
| 2813 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2814 | return -1; |
| 2815 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2816 | |
| 2817 | final long identity = Binder.clearCallingIdentity(); |
| 2818 | try { |
| 2819 | final Phone phone = getPhone(subId); |
| 2820 | if (phone != null) { |
| 2821 | return phone.getCdmaEriIconMode(); |
| 2822 | } else { |
| 2823 | return -1; |
| 2824 | } |
| 2825 | } finally { |
| 2826 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2827 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2828 | } |
| 2829 | |
| 2830 | /** |
| 2831 | * Returns the CDMA ERI text, |
| 2832 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2833 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2834 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 2835 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 2836 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2837 | } |
| 2838 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2839 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2840 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 2841 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2842 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2843 | mApp, subId, callingPackage, callingFeatureId, |
| 2844 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2845 | return null; |
| 2846 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2847 | |
| 2848 | final long identity = Binder.clearCallingIdentity(); |
| 2849 | try { |
| 2850 | final Phone phone = getPhone(subId); |
| 2851 | if (phone != null) { |
| 2852 | return phone.getCdmaEriText(); |
| 2853 | } else { |
| 2854 | return null; |
| 2855 | } |
| 2856 | } finally { |
| 2857 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2858 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2859 | } |
| 2860 | |
| 2861 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2862 | * Returns the CDMA MDN. |
| 2863 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2864 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2865 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2866 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2867 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2868 | |
| 2869 | final long identity = Binder.clearCallingIdentity(); |
| 2870 | try { |
| 2871 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2872 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2873 | return phone.getLine1Number(); |
| 2874 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2875 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2876 | return null; |
| 2877 | } |
| 2878 | } finally { |
| 2879 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2880 | } |
| 2881 | } |
| 2882 | |
| 2883 | /** |
| 2884 | * Returns the CDMA MIN. |
| 2885 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2886 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2887 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2888 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2889 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2890 | |
| 2891 | final long identity = Binder.clearCallingIdentity(); |
| 2892 | try { |
| 2893 | final Phone phone = getPhone(subId); |
| 2894 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2895 | return phone.getCdmaMin(); |
| 2896 | } else { |
| 2897 | return null; |
| 2898 | } |
| 2899 | } finally { |
| 2900 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2901 | } |
| 2902 | } |
| 2903 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2904 | @Override |
| 2905 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2906 | INumberVerificationCallback callback, String callingPackage) { |
| 2907 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2908 | != PERMISSION_GRANTED) { |
| 2909 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2910 | } |
| 2911 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2912 | |
| 2913 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2914 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2915 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2916 | } |
| 2917 | |
| 2918 | if (range == null) { |
| 2919 | throw new NullPointerException("Range must be non-null"); |
| 2920 | } |
| 2921 | |
| 2922 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2923 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2924 | |
| 2925 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2926 | } |
| 2927 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2928 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2929 | * Returns true if CDMA provisioning needs to run. |
| 2930 | */ |
| 2931 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2932 | final long identity = Binder.clearCallingIdentity(); |
| 2933 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2934 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2935 | } finally { |
| 2936 | Binder.restoreCallingIdentity(identity); |
| 2937 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2938 | } |
| 2939 | |
| 2940 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2941 | * Sets the voice mail number of a given subId. |
| 2942 | */ |
| 2943 | @Override |
| 2944 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 2945 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2946 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2947 | |
| 2948 | final long identity = Binder.clearCallingIdentity(); |
| 2949 | try { |
| 2950 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2951 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2952 | return success; |
| 2953 | } finally { |
| 2954 | Binder.restoreCallingIdentity(identity); |
| 2955 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2956 | } |
| 2957 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2958 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2959 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2960 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 2961 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 2962 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2963 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2964 | throw new SecurityException("caller must be system dialer"); |
| 2965 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2966 | |
| 2967 | final long identity = Binder.clearCallingIdentity(); |
| 2968 | try { |
| 2969 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2970 | if (phoneAccountHandle == null) { |
| 2971 | return null; |
| 2972 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2973 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2974 | } finally { |
| 2975 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2976 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2977 | } |
| 2978 | |
| 2979 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2980 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 2981 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2982 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2983 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2984 | mApp, subId, callingPackage, callingFeatureId, |
| 2985 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2986 | return null; |
| 2987 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2988 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2989 | final long identity = Binder.clearCallingIdentity(); |
| 2990 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2991 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2992 | } finally { |
| 2993 | Binder.restoreCallingIdentity(identity); |
| 2994 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2995 | } |
| 2996 | |
| 2997 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2998 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2999 | VisualVoicemailSmsFilterSettings settings) { |
| 3000 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3001 | |
| 3002 | final long identity = Binder.clearCallingIdentity(); |
| 3003 | try { |
| 3004 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3005 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3006 | } finally { |
| 3007 | Binder.restoreCallingIdentity(identity); |
| 3008 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3009 | } |
| 3010 | |
| 3011 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3012 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3013 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3014 | |
| 3015 | final long identity = Binder.clearCallingIdentity(); |
| 3016 | try { |
| 3017 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3018 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3019 | } finally { |
| 3020 | Binder.restoreCallingIdentity(identity); |
| 3021 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3022 | } |
| 3023 | |
| 3024 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3025 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3026 | String callingPackage, int subId) { |
| 3027 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3028 | |
| 3029 | final long identity = Binder.clearCallingIdentity(); |
| 3030 | try { |
| 3031 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3032 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3033 | } finally { |
| 3034 | Binder.restoreCallingIdentity(identity); |
| 3035 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3036 | } |
| 3037 | |
| 3038 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3039 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3040 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3041 | |
| 3042 | final long identity = Binder.clearCallingIdentity(); |
| 3043 | try { |
| 3044 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3045 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3046 | } finally { |
| 3047 | Binder.restoreCallingIdentity(identity); |
| 3048 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3049 | } |
| 3050 | |
| 3051 | @Override |
Philip P. Moltmann | acc6364 | 2020-03-19 21:37:01 +0000 | [diff] [blame] | 3052 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3053 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3054 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3055 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3056 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3057 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3058 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | acc6364 | 2020-03-19 21:37:01 +0000 | [diff] [blame] | 3059 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3060 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3061 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3062 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3063 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3064 | * Sets the voice activation state of a given subId. |
| 3065 | */ |
| 3066 | @Override |
| 3067 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3068 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3069 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3070 | |
| 3071 | final long identity = Binder.clearCallingIdentity(); |
| 3072 | try { |
| 3073 | final Phone phone = getPhone(subId); |
| 3074 | if (phone != null) { |
| 3075 | phone.setVoiceActivationState(activationState); |
| 3076 | } else { |
| 3077 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3078 | } |
| 3079 | } finally { |
| 3080 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3081 | } |
| 3082 | } |
| 3083 | |
| 3084 | /** |
| 3085 | * Sets the data activation state of a given subId. |
| 3086 | */ |
| 3087 | @Override |
| 3088 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3089 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3090 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3091 | |
| 3092 | final long identity = Binder.clearCallingIdentity(); |
| 3093 | try { |
| 3094 | final Phone phone = getPhone(subId); |
| 3095 | if (phone != null) { |
| 3096 | phone.setDataActivationState(activationState); |
| 3097 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3098 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3099 | } |
| 3100 | } finally { |
| 3101 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3102 | } |
| 3103 | } |
| 3104 | |
| 3105 | /** |
| 3106 | * Returns the voice activation state of a given subId. |
| 3107 | */ |
| 3108 | @Override |
| 3109 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3110 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3111 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3112 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3113 | final long identity = Binder.clearCallingIdentity(); |
| 3114 | try { |
| 3115 | if (phone != null) { |
| 3116 | return phone.getVoiceActivationState(); |
| 3117 | } else { |
| 3118 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3119 | } |
| 3120 | } finally { |
| 3121 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3122 | } |
| 3123 | } |
| 3124 | |
| 3125 | /** |
| 3126 | * Returns the data activation state of a given subId. |
| 3127 | */ |
| 3128 | @Override |
| 3129 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3130 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3131 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3132 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3133 | final long identity = Binder.clearCallingIdentity(); |
| 3134 | try { |
| 3135 | if (phone != null) { |
| 3136 | return phone.getDataActivationState(); |
| 3137 | } else { |
| 3138 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3139 | } |
| 3140 | } finally { |
| 3141 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3142 | } |
| 3143 | } |
| 3144 | |
| 3145 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3146 | * Returns the unread count of voicemails for a subId |
| 3147 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3148 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3149 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3150 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3151 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3152 | mApp, subId, callingPackage, callingFeatureId, |
| 3153 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3154 | return 0; |
| 3155 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3156 | final long identity = Binder.clearCallingIdentity(); |
| 3157 | try { |
| 3158 | final Phone phone = getPhone(subId); |
| 3159 | if (phone != null) { |
| 3160 | return phone.getVoiceMessageCount(); |
| 3161 | } else { |
| 3162 | return 0; |
| 3163 | } |
| 3164 | } finally { |
| 3165 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3166 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3167 | } |
| 3168 | |
| 3169 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3170 | * returns true, if the device is in a state where both voice and data |
| 3171 | * are supported simultaneously. This can change based on location or network condition. |
| 3172 | */ |
| 3173 | @Override |
| 3174 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3175 | final long identity = Binder.clearCallingIdentity(); |
| 3176 | try { |
| 3177 | final Phone phone = getPhone(subId); |
| 3178 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3179 | } finally { |
| 3180 | Binder.restoreCallingIdentity(identity); |
| 3181 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3182 | } |
| 3183 | |
| 3184 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3185 | * Send the dialer code if called from the current default dialer or the caller has |
| 3186 | * carrier privilege. |
| 3187 | * @param inputCode The dialer code to send |
| 3188 | */ |
| 3189 | @Override |
| 3190 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3191 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3192 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3193 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3194 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3195 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3196 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3197 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3198 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3199 | |
| 3200 | final long identity = Binder.clearCallingIdentity(); |
| 3201 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3202 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3203 | } finally { |
| 3204 | Binder.restoreCallingIdentity(identity); |
| 3205 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3206 | } |
| 3207 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3208 | @Override |
| 3209 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3210 | TelephonyPermissions |
| 3211 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3212 | mApp, subId, "getNetworkSelectionMode"); |
| 3213 | final long identity = Binder.clearCallingIdentity(); |
| 3214 | try { |
| 3215 | if (!isActiveSubscription(subId)) { |
| 3216 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3217 | } |
| 3218 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3219 | } finally { |
| 3220 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3221 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3222 | } |
| 3223 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3224 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3225 | public boolean isInEmergencySmsMode() { |
| 3226 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3227 | final long identity = Binder.clearCallingIdentity(); |
| 3228 | try { |
| 3229 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3230 | if (phone.isInEmergencySmsMode()) { |
| 3231 | return true; |
| 3232 | } |
| 3233 | } |
| 3234 | } finally { |
| 3235 | Binder.restoreCallingIdentity(identity); |
| 3236 | } |
| 3237 | return false; |
| 3238 | } |
| 3239 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3240 | /** |
| 3241 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3242 | * @param subId The subscription to use to check the configuration. |
| 3243 | * @param c The callback that will be used to send the result. |
| 3244 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3245 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3246 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3247 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3248 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3249 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3250 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3251 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3252 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3253 | "IMS not available on device."); |
| 3254 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3255 | final long token = Binder.clearCallingIdentity(); |
| 3256 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3257 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3258 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3259 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3260 | } catch (ImsException e) { |
| 3261 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3262 | } finally { |
| 3263 | Binder.restoreCallingIdentity(token); |
| 3264 | } |
| 3265 | } |
| 3266 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3267 | /** |
| 3268 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3269 | * @param subId The subscription to use to check the configuration. |
| 3270 | * @param c The callback that will be used to send the result. |
| 3271 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3272 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3273 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3274 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3275 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3276 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3277 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3278 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3279 | final long token = Binder.clearCallingIdentity(); |
| 3280 | try { |
| 3281 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3282 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3283 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3284 | } catch (ImsException e) { |
| 3285 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3286 | + "is inactive, ignoring unregister."); |
| 3287 | // If the subscription is no longer active, just return, since the callback |
| 3288 | // will already have been removed internally. |
| 3289 | } finally { |
| 3290 | Binder.restoreCallingIdentity(token); |
| 3291 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3292 | } |
| 3293 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3294 | /** |
| 3295 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3296 | */ |
| 3297 | @Override |
| 3298 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3299 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3300 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3301 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3302 | "IMS not available on device."); |
| 3303 | } |
| 3304 | final long token = Binder.clearCallingIdentity(); |
| 3305 | try { |
| 3306 | Phone phone = getPhone(subId); |
| 3307 | if (phone == null) { |
| 3308 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3309 | + subId + "'"); |
| 3310 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3311 | } |
| 3312 | phone.getImsRegistrationState(regState -> { |
| 3313 | try { |
| 3314 | consumer.accept((regState == null) |
| 3315 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3316 | } catch (RemoteException e) { |
| 3317 | // Ignore if the remote process is no longer available to call back. |
| 3318 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3319 | } |
| 3320 | }); |
| 3321 | } finally { |
| 3322 | Binder.restoreCallingIdentity(token); |
| 3323 | } |
| 3324 | } |
| 3325 | |
| 3326 | /** |
| 3327 | * Get the transport type for the IMS service registration state. |
| 3328 | */ |
| 3329 | @Override |
| 3330 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3331 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3332 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3333 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3334 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3335 | "IMS not available on device."); |
| 3336 | } |
| 3337 | final long token = Binder.clearCallingIdentity(); |
| 3338 | try { |
| 3339 | Phone phone = getPhone(subId); |
| 3340 | if (phone == null) { |
| 3341 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3342 | + subId + "'"); |
| 3343 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3344 | } |
| 3345 | phone.getImsRegistrationTech(regTech -> { |
| 3346 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3347 | int regTechConverted = (regTech == null) |
| 3348 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3349 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3350 | regTechConverted); |
| 3351 | try { |
| 3352 | consumer.accept(regTechConverted); |
| 3353 | } catch (RemoteException e) { |
| 3354 | // Ignore if the remote process is no longer available to call back. |
| 3355 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3356 | } |
| 3357 | }); |
| 3358 | } finally { |
| 3359 | Binder.restoreCallingIdentity(token); |
| 3360 | } |
| 3361 | } |
| 3362 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3363 | /** |
| 3364 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3365 | * @param subId The subscription to use to check the configuration. |
| 3366 | * @param c The callback that will be used to send the result. |
| 3367 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3368 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3369 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3370 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3371 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3372 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3373 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3374 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3375 | "IMS not available on device."); |
| 3376 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3377 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3378 | final long token = Binder.clearCallingIdentity(); |
| 3379 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3380 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3381 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3382 | } catch (ImsException e) { |
| 3383 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3384 | } finally { |
| 3385 | Binder.restoreCallingIdentity(token); |
| 3386 | } |
| 3387 | } |
| 3388 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3389 | /** |
| 3390 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3391 | * @param subId The subscription to use to check the configuration. |
| 3392 | * @param c The callback that will be used to send the result. |
| 3393 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3394 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3395 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3396 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3397 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3398 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3399 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3400 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3401 | |
| 3402 | final long token = Binder.clearCallingIdentity(); |
| 3403 | try { |
| 3404 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3405 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3406 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3407 | } catch (ImsException e) { |
| 3408 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3409 | + "is inactive, ignoring unregister."); |
| 3410 | // If the subscription is no longer active, just return, since the callback |
| 3411 | // will already have been removed internally. |
| 3412 | } finally { |
| 3413 | Binder.restoreCallingIdentity(token); |
| 3414 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3415 | } |
| 3416 | |
| 3417 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3418 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3419 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3420 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3421 | final long token = Binder.clearCallingIdentity(); |
| 3422 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3423 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3424 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3425 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3426 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3427 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3428 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3429 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3430 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3431 | } finally { |
| 3432 | Binder.restoreCallingIdentity(token); |
| 3433 | } |
| 3434 | } |
| 3435 | |
| 3436 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3437 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3438 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3439 | final long token = Binder.clearCallingIdentity(); |
| 3440 | try { |
| 3441 | Phone phone = getPhone(subId); |
| 3442 | if (phone == null) return false; |
| 3443 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3444 | } catch (com.android.ims.ImsException e) { |
| 3445 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3446 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3447 | } finally { |
| 3448 | Binder.restoreCallingIdentity(token); |
| 3449 | } |
| 3450 | } |
| 3451 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3452 | /** |
| 3453 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3454 | * subscription. |
| 3455 | * @param subId The subscription to use to check the configuration. |
| 3456 | * @param callback The callback that will be used to send the result. |
| 3457 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3458 | * @param transportType The transport type of the MmTelFeature capability. |
| 3459 | */ |
| 3460 | @Override |
| 3461 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3462 | int transportType) { |
| 3463 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3464 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3465 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3466 | "IMS not available on device."); |
| 3467 | } |
| 3468 | final long token = Binder.clearCallingIdentity(); |
| 3469 | try { |
| 3470 | int slotId = getSlotIndex(subId); |
| 3471 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3472 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3473 | + subId + "'"); |
| 3474 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3475 | } |
| 3476 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3477 | transportType, aBoolean -> { |
| 3478 | try { |
| 3479 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3480 | } catch (RemoteException e) { |
| 3481 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3482 | + "running. Ignore"); |
| 3483 | } |
| 3484 | }); |
| 3485 | } finally { |
| 3486 | Binder.restoreCallingIdentity(token); |
| 3487 | } |
| 3488 | } |
| 3489 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3490 | /** |
| 3491 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3492 | * @param subId The subscription to use to check the configuration. |
| 3493 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3494 | @Override |
| 3495 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3496 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3497 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3498 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3499 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3500 | final long token = Binder.clearCallingIdentity(); |
| 3501 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3502 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3503 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3504 | } catch (ImsException e) { |
| 3505 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3506 | } finally { |
| 3507 | Binder.restoreCallingIdentity(token); |
| 3508 | } |
| 3509 | } |
| 3510 | |
| 3511 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3512 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3513 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3514 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3515 | final long identity = Binder.clearCallingIdentity(); |
| 3516 | try { |
| 3517 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3518 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3519 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3520 | } catch (ImsException e) { |
| 3521 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3522 | } finally { |
| 3523 | Binder.restoreCallingIdentity(identity); |
| 3524 | } |
| 3525 | } |
| 3526 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3527 | /** |
| 3528 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3529 | * @param subId The subscription to use to check the configuration. |
| 3530 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3531 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3532 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3533 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3534 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3535 | final long identity = Binder.clearCallingIdentity(); |
| 3536 | try { |
| 3537 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3538 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3539 | } catch (ImsException e) { |
| 3540 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3541 | } finally { |
| 3542 | Binder.restoreCallingIdentity(identity); |
| 3543 | } |
| 3544 | } |
| 3545 | |
| 3546 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3547 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3548 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3549 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3550 | final long identity = Binder.clearCallingIdentity(); |
| 3551 | try { |
| 3552 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3553 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3554 | } catch (ImsException e) { |
| 3555 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3556 | } finally { |
| 3557 | Binder.restoreCallingIdentity(identity); |
| 3558 | } |
| 3559 | } |
| 3560 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3561 | /** |
| 3562 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3563 | * @param subId The subscription to use to check the configuration. |
| 3564 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3565 | @Override |
| 3566 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3567 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3568 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3569 | final long identity = Binder.clearCallingIdentity(); |
| 3570 | try { |
| 3571 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3572 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3573 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3574 | } catch (ImsException e) { |
| 3575 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3576 | } finally { |
| 3577 | Binder.restoreCallingIdentity(identity); |
| 3578 | } |
| 3579 | } |
| 3580 | |
| 3581 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3582 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3583 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3584 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3585 | final long identity = Binder.clearCallingIdentity(); |
| 3586 | try { |
| 3587 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3588 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3589 | } catch (ImsException e) { |
| 3590 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3591 | } finally { |
| 3592 | Binder.restoreCallingIdentity(identity); |
| 3593 | } |
| 3594 | } |
| 3595 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3596 | /** |
| 3597 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3598 | * @param subId The subscription to use to check the configuration. |
| 3599 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3600 | @Override |
| 3601 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3602 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3603 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3604 | final long identity = Binder.clearCallingIdentity(); |
| 3605 | try { |
| 3606 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3607 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3608 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3609 | } catch (ImsException e) { |
| 3610 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3611 | } finally { |
| 3612 | Binder.restoreCallingIdentity(identity); |
| 3613 | } |
| 3614 | } |
| 3615 | |
| 3616 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3617 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3618 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3619 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3620 | final long identity = Binder.clearCallingIdentity(); |
| 3621 | try { |
| 3622 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3623 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3624 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3625 | } catch (ImsException e) { |
| 3626 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3627 | } finally { |
| 3628 | Binder.restoreCallingIdentity(identity); |
| 3629 | } |
| 3630 | } |
| 3631 | |
| 3632 | @Override |
| 3633 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3634 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3635 | "setVoWiFiNonPersistent"); |
| 3636 | final long identity = Binder.clearCallingIdentity(); |
| 3637 | try { |
| 3638 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3639 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3640 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3641 | } catch (ImsException e) { |
| 3642 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3643 | } finally { |
| 3644 | Binder.restoreCallingIdentity(identity); |
| 3645 | } |
| 3646 | } |
| 3647 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3648 | /** |
| 3649 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3650 | * @param subId The subscription to use to check the configuration. |
| 3651 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3652 | @Override |
| 3653 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3654 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3655 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3656 | final long identity = Binder.clearCallingIdentity(); |
| 3657 | try { |
| 3658 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3659 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3660 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3661 | } catch (ImsException e) { |
| 3662 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3663 | } finally { |
| 3664 | Binder.restoreCallingIdentity(identity); |
| 3665 | } |
| 3666 | } |
| 3667 | |
| 3668 | @Override |
| 3669 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3670 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3671 | "setVoWiFiModeSetting"); |
| 3672 | final long identity = Binder.clearCallingIdentity(); |
| 3673 | try { |
| 3674 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3675 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3676 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3677 | } catch (ImsException e) { |
| 3678 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3679 | } finally { |
| 3680 | Binder.restoreCallingIdentity(identity); |
| 3681 | } |
| 3682 | } |
| 3683 | |
| 3684 | @Override |
| 3685 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3686 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3687 | final long identity = Binder.clearCallingIdentity(); |
| 3688 | try { |
| 3689 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3690 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3691 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3692 | } catch (ImsException e) { |
| 3693 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3694 | } finally { |
| 3695 | Binder.restoreCallingIdentity(identity); |
| 3696 | } |
| 3697 | } |
| 3698 | |
| 3699 | @Override |
| 3700 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3701 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3702 | "setVoWiFiRoamingModeSetting"); |
| 3703 | final long identity = Binder.clearCallingIdentity(); |
| 3704 | try { |
| 3705 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3706 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3707 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3708 | } catch (ImsException e) { |
| 3709 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3710 | } finally { |
| 3711 | Binder.restoreCallingIdentity(identity); |
| 3712 | } |
| 3713 | } |
| 3714 | |
| 3715 | @Override |
| 3716 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3717 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3718 | "setRttCapabilityEnabled"); |
| 3719 | final long identity = Binder.clearCallingIdentity(); |
| 3720 | try { |
| 3721 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3722 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3723 | } catch (ImsException e) { |
| 3724 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3725 | } finally { |
| 3726 | Binder.restoreCallingIdentity(identity); |
| 3727 | } |
| 3728 | } |
| 3729 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3730 | /** |
| 3731 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3732 | * @param subId The subscription to use to check the configuration. |
| 3733 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3734 | @Override |
| 3735 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3736 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3737 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3738 | final long identity = Binder.clearCallingIdentity(); |
| 3739 | try { |
| 3740 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3741 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3742 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3743 | } catch (ImsException e) { |
| 3744 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3745 | } finally { |
| 3746 | Binder.restoreCallingIdentity(identity); |
| 3747 | } |
| 3748 | } |
| 3749 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3750 | @Override |
| 3751 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3752 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3753 | final long identity = Binder.clearCallingIdentity(); |
| 3754 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 3755 | if (!isImsAvailableOnDevice()) { |
| 3756 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3757 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 3758 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3759 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3760 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3761 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3762 | } catch (ImsException e) { |
| 3763 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3764 | } finally { |
| 3765 | Binder.restoreCallingIdentity(identity); |
| 3766 | } |
| 3767 | } |
| 3768 | |
| 3769 | @Override |
| 3770 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3771 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3772 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3773 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3774 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3775 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3776 | try { |
| 3777 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3778 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3779 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3780 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3781 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3782 | + "is inactive, ignoring unregister."); |
| 3783 | // If the subscription is no longer active, just return, since the callback will already |
| 3784 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3785 | } finally { |
| 3786 | Binder.restoreCallingIdentity(identity); |
| 3787 | } |
| 3788 | } |
| 3789 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3790 | |
| 3791 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 3792 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3793 | message); |
| 3794 | } |
| 3795 | |
| 3796 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 3797 | boolean isMmtelCapability) { |
| 3798 | Phone phone = getPhone(subId); |
| 3799 | if (phone == null) { |
| 3800 | loge("phone instance null for subid " + subId); |
| 3801 | return false; |
| 3802 | } |
| 3803 | if (isMmtelCapability) { |
| 3804 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3805 | return false; |
| 3806 | } |
| 3807 | } else { |
| 3808 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3809 | return false; |
| 3810 | } |
| 3811 | } |
| 3812 | return true; |
| 3813 | } |
| 3814 | |
| 3815 | @Override |
| 3816 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 3817 | boolean isProvisioned) { |
| 3818 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 3819 | |
| 3820 | final long identity = Binder.clearCallingIdentity(); |
| 3821 | try { |
| 3822 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3823 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3824 | return; |
| 3825 | } |
| 3826 | |
| 3827 | // this capability requires provisioning, route to the correct API. |
| 3828 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3829 | switch (capability) { |
| 3830 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3831 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3832 | ims.setEabProvisioned(isProvisioned); |
| 3833 | break; |
| 3834 | default: { |
| 3835 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3836 | + "rcs capability '" + capability + "', which does not require " |
| 3837 | + "provisioning."); |
| 3838 | } |
| 3839 | } |
| 3840 | } finally { |
| 3841 | Binder.restoreCallingIdentity(identity); |
| 3842 | } |
| 3843 | |
| 3844 | } |
| 3845 | |
| 3846 | |
| 3847 | @Override |
| 3848 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 3849 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 3850 | final long identity = Binder.clearCallingIdentity(); |
| 3851 | try { |
| 3852 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3853 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3854 | return true; |
| 3855 | } |
| 3856 | |
| 3857 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3858 | switch (capability) { |
| 3859 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3860 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3861 | return ims.isEabProvisionedOnDevice(); |
| 3862 | |
| 3863 | default: { |
| 3864 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 3865 | + "capability '" + capability + "', which does not require " |
| 3866 | + "provisioning."); |
| 3867 | } |
| 3868 | } |
| 3869 | |
| 3870 | } finally { |
| 3871 | Binder.restoreCallingIdentity(identity); |
| 3872 | } |
| 3873 | } |
| 3874 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3875 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3876 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3877 | boolean isProvisioned) { |
| 3878 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3879 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3880 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3881 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3882 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3883 | final long identity = Binder.clearCallingIdentity(); |
| 3884 | try { |
| 3885 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3886 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3887 | return; |
| 3888 | } |
| 3889 | |
| 3890 | // this capability requires provisioning, route to the correct API. |
| 3891 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3892 | switch (capability) { |
| 3893 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3894 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3895 | ims.setVolteProvisioned(isProvisioned); |
| 3896 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3897 | ims.setWfcProvisioned(isProvisioned); |
| 3898 | } |
| 3899 | break; |
| 3900 | } |
| 3901 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3902 | // There is currently no difference in VT provisioning type. |
| 3903 | ims.setVtProvisioned(isProvisioned); |
| 3904 | break; |
| 3905 | } |
| 3906 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3907 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3908 | // change the capability of the feature instead if needed. |
| 3909 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3910 | == isProvisioned) { |
| 3911 | // No change in provisioning. |
| 3912 | return; |
| 3913 | } |
| 3914 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3915 | try { |
| 3916 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3917 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3918 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3919 | + ", Exception" + e.getMessage()); |
| 3920 | } |
| 3921 | break; |
| 3922 | } |
| 3923 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3924 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3925 | + "MmTel capability '" + capability + "', which does not require " |
| 3926 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3927 | } |
| 3928 | } |
| 3929 | |
| 3930 | } finally { |
| 3931 | Binder.restoreCallingIdentity(identity); |
| 3932 | } |
| 3933 | } |
| 3934 | |
| 3935 | @Override |
| 3936 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3937 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3938 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3939 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3940 | } |
| 3941 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3942 | final long identity = Binder.clearCallingIdentity(); |
| 3943 | try { |
| 3944 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3945 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3946 | return true; |
| 3947 | } |
| 3948 | |
| 3949 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3950 | switch (capability) { |
| 3951 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3952 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3953 | return ims.isVolteProvisionedOnDevice(); |
| 3954 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3955 | return ims.isWfcProvisionedOnDevice(); |
| 3956 | } |
| 3957 | // This should never happen, since we are checking tech above to make sure it |
| 3958 | // is either LTE or IWLAN. |
| 3959 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3960 | + "capability."); |
| 3961 | } |
| 3962 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3963 | // There is currently no difference in VT provisioning type. |
| 3964 | return ims.isVtProvisionedOnDevice(); |
| 3965 | } |
| 3966 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3967 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3968 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3969 | } |
| 3970 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3971 | throw new IllegalArgumentException( |
| 3972 | "Tried to get provisioning for MmTel capability '" + capability |
| 3973 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3974 | } |
| 3975 | } |
| 3976 | |
| 3977 | } finally { |
| 3978 | Binder.restoreCallingIdentity(identity); |
| 3979 | } |
| 3980 | } |
| 3981 | |
| 3982 | @Override |
| 3983 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3984 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3985 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3986 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3987 | } |
| 3988 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3989 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3990 | return (provisionedBits & capability) > 0; |
| 3991 | } |
| 3992 | |
| 3993 | @Override |
| 3994 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3995 | boolean isProvisioned) { |
| 3996 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3997 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3998 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3999 | } |
| 4000 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4001 | "setProvisioningStatusForCapability"); |
| 4002 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4003 | // If the current provisioning status for capability already matches isProvisioned, |
| 4004 | // do nothing. |
| 4005 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4006 | return; |
| 4007 | } |
| 4008 | if (isProvisioned) { |
| 4009 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4010 | } else { |
| 4011 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4012 | } |
| 4013 | } |
| 4014 | |
| 4015 | /** |
| 4016 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4017 | * technology. The bitfield should mirror the bitfield defined by |
| 4018 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4019 | */ |
| 4020 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4021 | String key = getMmTelProvisioningKey(subId, tech); |
| 4022 | // Default is no capabilities are provisioned. |
| 4023 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4024 | } |
| 4025 | |
| 4026 | /** |
| 4027 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4028 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4029 | * technology specified. |
| 4030 | * |
| 4031 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4032 | */ |
| 4033 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4034 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4035 | String key = getMmTelProvisioningKey(subId, tech); |
| 4036 | editor.putInt(key, newField); |
| 4037 | editor.commit(); |
| 4038 | } |
| 4039 | |
| 4040 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4041 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4042 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4043 | } |
| 4044 | |
| 4045 | /** |
| 4046 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4047 | * carrier associated with the subscription id. |
| 4048 | */ |
| 4049 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4050 | int capability) { |
| 4051 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4052 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4053 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4054 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4055 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4056 | false); |
| 4057 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4058 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4059 | |
| 4060 | // First check to make sure that the capability requires provisioning. |
| 4061 | switch (capability) { |
| 4062 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4063 | // intentional fallthrough |
| 4064 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4065 | if (requireVoiceVtProvisioning) { |
| 4066 | // Voice and Video requires provisioning |
| 4067 | return true; |
| 4068 | } |
| 4069 | break; |
| 4070 | } |
| 4071 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4072 | if (requireUtProvisioning) { |
| 4073 | // UT requires provisioning |
| 4074 | return true; |
| 4075 | } |
| 4076 | break; |
| 4077 | } |
| 4078 | } |
| 4079 | return false; |
| 4080 | } |
| 4081 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4082 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4083 | int capability) { |
| 4084 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4085 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4086 | |
| 4087 | boolean requireRcsProvisioning = c.getBoolean( |
| 4088 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4089 | |
| 4090 | // First check to make sure that the capability requires provisioning. |
| 4091 | switch (capability) { |
| 4092 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4093 | // intentional fallthrough |
| 4094 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4095 | if (requireRcsProvisioning) { |
| 4096 | // OPTION or PRESENCE requires provisioning |
| 4097 | return true; |
| 4098 | } |
| 4099 | break; |
| 4100 | } |
| 4101 | } |
| 4102 | return false; |
| 4103 | } |
| 4104 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4105 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4106 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4107 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4108 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4109 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4110 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4111 | final long identity = Binder.clearCallingIdentity(); |
| 4112 | try { |
| 4113 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4114 | int slotId = getSlotIndex(subId); |
| 4115 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4116 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4117 | + subId + "' for key:" + key); |
| 4118 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4119 | } |
| 4120 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4121 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4122 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4123 | + subId + "' for key:" + key); |
| 4124 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4125 | } finally { |
| 4126 | Binder.restoreCallingIdentity(identity); |
| 4127 | } |
| 4128 | } |
| 4129 | |
| 4130 | @Override |
| 4131 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4132 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4133 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4134 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4135 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4136 | final long identity = Binder.clearCallingIdentity(); |
| 4137 | try { |
| 4138 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4139 | int slotId = getSlotIndex(subId); |
| 4140 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4141 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4142 | + subId + "' for key:" + key); |
| 4143 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4144 | } |
| 4145 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4146 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4147 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4148 | + subId + "' for key:" + key); |
| 4149 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4150 | } finally { |
| 4151 | Binder.restoreCallingIdentity(identity); |
| 4152 | } |
| 4153 | } |
| 4154 | |
| 4155 | @Override |
| 4156 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4157 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4158 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4159 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4160 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4161 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4162 | final long identity = Binder.clearCallingIdentity(); |
| 4163 | try { |
| 4164 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4165 | int slotId = getSlotIndex(subId); |
| 4166 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4167 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4168 | + subId + "' for key:" + key); |
| 4169 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4170 | } |
| 4171 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4172 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4173 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4174 | + "' for key:" + key); |
| 4175 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4176 | } finally { |
| 4177 | Binder.restoreCallingIdentity(identity); |
| 4178 | } |
| 4179 | } |
| 4180 | |
| 4181 | @Override |
| 4182 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4183 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4184 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4185 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4186 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4187 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 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, "setImsProvisioningString: called with an inactive subscription id '" |
| 4194 | + subId + "' for key:" + key); |
| 4195 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4196 | } |
| 4197 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
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, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4200 | + "' for key:" + key); |
| 4201 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4202 | } finally { |
| 4203 | Binder.restoreCallingIdentity(identity); |
| 4204 | } |
| 4205 | } |
| 4206 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4207 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4208 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4209 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4210 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4211 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4212 | } |
| 4213 | return slotId; |
| 4214 | } |
| 4215 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4216 | private int getSlotIndex(int subId) { |
| 4217 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4218 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4219 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4220 | } |
| 4221 | return slotId; |
| 4222 | } |
| 4223 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4224 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4225 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4226 | */ |
| 4227 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4228 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4229 | String callingFeatureId) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4230 | final int targetSdk = getTargetSdk(callingPackage); |
| 4231 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4232 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4233 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4234 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4235 | mApp, subId, callingPackage, callingFeatureId, |
| 4236 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4237 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4238 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4239 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4240 | final long identity = Binder.clearCallingIdentity(); |
| 4241 | try { |
| 4242 | final Phone phone = getPhone(subId); |
| 4243 | if (phone != null) { |
| 4244 | return phone.getServiceState().getDataNetworkType(); |
| 4245 | } else { |
| 4246 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4247 | } |
| 4248 | } finally { |
| 4249 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4250 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4251 | } |
| 4252 | |
| 4253 | /** |
| 4254 | * Returns the data network type |
| 4255 | */ |
| 4256 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4257 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4258 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4259 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4260 | } |
| 4261 | |
| 4262 | /** |
| 4263 | * Returns the data network type for a subId |
| 4264 | */ |
| 4265 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4266 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4267 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4268 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4269 | mApp, subId, callingPackage, callingFeatureId, |
| 4270 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4271 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4272 | } |
| 4273 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4274 | final long identity = Binder.clearCallingIdentity(); |
| 4275 | try { |
| 4276 | final Phone phone = getPhone(subId); |
| 4277 | if (phone != null) { |
| 4278 | return phone.getServiceState().getDataNetworkType(); |
| 4279 | } else { |
| 4280 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4281 | } |
| 4282 | } finally { |
| 4283 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4284 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4285 | } |
| 4286 | |
| 4287 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4288 | * Returns the Voice network type for a subId |
| 4289 | */ |
| 4290 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4291 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4292 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4293 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4294 | mApp, subId, callingPackage, callingFeatureId, |
| 4295 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4296 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4297 | } |
| 4298 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4299 | final long identity = Binder.clearCallingIdentity(); |
| 4300 | try { |
| 4301 | final Phone phone = getPhone(subId); |
| 4302 | if (phone != null) { |
| 4303 | return phone.getServiceState().getVoiceNetworkType(); |
| 4304 | } else { |
| 4305 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4306 | } |
| 4307 | } finally { |
| 4308 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4309 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4310 | } |
| 4311 | |
| 4312 | /** |
| 4313 | * @return true if a ICC card is present |
| 4314 | */ |
| 4315 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4316 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4317 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4318 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4319 | } |
| 4320 | |
| 4321 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4322 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4323 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4324 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4325 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4326 | final long identity = Binder.clearCallingIdentity(); |
| 4327 | try { |
| 4328 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4329 | if (phone != null) { |
| 4330 | return phone.getIccCard().hasIccCard(); |
| 4331 | } else { |
| 4332 | return false; |
| 4333 | } |
| 4334 | } finally { |
| 4335 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4336 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4337 | } |
| 4338 | |
| 4339 | /** |
| 4340 | * Return if the current radio is LTE on CDMA. This |
| 4341 | * is a tri-state return value as for a period of time |
| 4342 | * the mode may be unknown. |
| 4343 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4344 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4345 | * @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] | 4346 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4347 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4348 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4349 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4350 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4351 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4352 | } |
| 4353 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4354 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4355 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4356 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4357 | try { |
| 4358 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4359 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4360 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4361 | } |
| 4362 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4363 | final long identity = Binder.clearCallingIdentity(); |
| 4364 | try { |
| 4365 | final Phone phone = getPhone(subId); |
| 4366 | if (phone == null) { |
| 4367 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4368 | } else { |
| 4369 | return phone.getLteOnCdmaMode(); |
| 4370 | } |
| 4371 | } finally { |
| 4372 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4373 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4374 | } |
| 4375 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4376 | /** |
| 4377 | * {@hide} |
| 4378 | * Returns Default subId, 0 in the case of single standby. |
| 4379 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4380 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4381 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4382 | } |
| 4383 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4384 | private int getSlotForDefaultSubscription() { |
| 4385 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4386 | } |
| 4387 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4388 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4389 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4390 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4391 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4392 | private boolean isActiveSubscription(int subId) { |
| 4393 | return mSubscriptionController.isActiveSubId(subId); |
| 4394 | } |
| 4395 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4396 | /** |
| 4397 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4398 | */ |
| 4399 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4400 | final long identity = Binder.clearCallingIdentity(); |
| 4401 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4402 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4403 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4404 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4405 | } finally { |
| 4406 | Binder.restoreCallingIdentity(identity); |
| 4407 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4408 | } |
| 4409 | |
| 4410 | /** |
| 4411 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4412 | */ |
| 4413 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4414 | final long identity = Binder.clearCallingIdentity(); |
| 4415 | try { |
| 4416 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4417 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4418 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4419 | } finally { |
| 4420 | Binder.restoreCallingIdentity(identity); |
| 4421 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4422 | } |
| 4423 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4424 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4425 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4426 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4427 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4428 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4429 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4430 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4431 | if (phoneId == -1) { |
| 4432 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4433 | + " does not correspond to an active phone"); |
| 4434 | } |
| 4435 | return PhoneFactory.getPhone(phoneId); |
| 4436 | } |
| 4437 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4438 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4439 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4440 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4441 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4442 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4443 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4444 | if (DBG) { |
| 4445 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4446 | } |
| 4447 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4448 | p2); |
| 4449 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4450 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4451 | |
| 4452 | @Override |
| 4453 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4454 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4455 | enforceModifyPermission(); |
| 4456 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4457 | if (DBG) { |
| 4458 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4459 | } |
| 4460 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4461 | callingPackage, aid, p2); |
| 4462 | } |
| 4463 | |
| 4464 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4465 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4466 | final long identity = Binder.clearCallingIdentity(); |
| 4467 | try { |
| 4468 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4469 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4470 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4471 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4472 | if (bestComponent == null |
| 4473 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4474 | loge("The calling package is not allowed to access ISD-R."); |
| 4475 | throw new SecurityException( |
| 4476 | "The calling package is not allowed to access ISD-R."); |
| 4477 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4478 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4479 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4480 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4481 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4482 | null /* workSource */); |
| 4483 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4484 | return response; |
| 4485 | } finally { |
| 4486 | Binder.restoreCallingIdentity(identity); |
| 4487 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4488 | } |
| 4489 | |
| 4490 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4491 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4492 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4493 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4494 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4495 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4496 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4497 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4498 | @Override |
| 4499 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4500 | enforceModifyPermission(); |
| 4501 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4502 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4503 | channel); |
| 4504 | } |
| 4505 | |
| 4506 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4507 | final long identity = Binder.clearCallingIdentity(); |
| 4508 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4509 | if (channel < 0) { |
| 4510 | return false; |
| 4511 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4512 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4513 | null /* workSource */); |
| 4514 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4515 | return success; |
| 4516 | } finally { |
| 4517 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4518 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4519 | } |
| 4520 | |
| 4521 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4522 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4523 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4524 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4525 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4526 | if (DBG) { |
| 4527 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4528 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4529 | + p3 + " data=" + data); |
| 4530 | } |
| 4531 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4532 | command, p1, p2, p3, data); |
| 4533 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4534 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4535 | @Override |
| 4536 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4537 | int command, int p1, int p2, int p3, String data) { |
| 4538 | enforceModifyPermission(); |
| 4539 | if (DBG) { |
| 4540 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4541 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4542 | + p3 + " data=" + data); |
| 4543 | } |
| 4544 | return iccTransmitApduLogicalChannelWithPermission( |
| 4545 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4546 | data); |
| 4547 | } |
| 4548 | |
| 4549 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4550 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4551 | final long identity = Binder.clearCallingIdentity(); |
| 4552 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4553 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4554 | return ""; |
| 4555 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4556 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4557 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4558 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4559 | null /* workSource */); |
| 4560 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4561 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4562 | // Append the returned status code to the end of the response payload. |
| 4563 | String s = Integer.toHexString( |
| 4564 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4565 | if (response.payload != null) { |
| 4566 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4567 | } |
| 4568 | return s; |
| 4569 | } finally { |
| 4570 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4571 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4572 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4573 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4574 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4575 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4576 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4577 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4578 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4579 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4580 | if (DBG) { |
| 4581 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4582 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4583 | } |
| 4584 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4585 | cla, command, p1, p2, p3, data); |
| 4586 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4587 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4588 | @Override |
| 4589 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4590 | int command, int p1, int p2, int p3, String data) { |
| 4591 | enforceModifyPermission(); |
| 4592 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4593 | if (DBG) { |
| 4594 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4595 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4596 | + " data=" + data); |
| 4597 | } |
| 4598 | |
| 4599 | return iccTransmitApduBasicChannelWithPermission( |
| 4600 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4601 | p2, p3, data); |
| 4602 | } |
| 4603 | |
| 4604 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4605 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4606 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4607 | final long identity = Binder.clearCallingIdentity(); |
| 4608 | try { |
| 4609 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4610 | && TextUtils.equals(ISDR_AID, data)) { |
| 4611 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4612 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4613 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4614 | if (bestComponent == null |
| 4615 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4616 | loge("The calling package is not allowed to select ISD-R."); |
| 4617 | throw new SecurityException( |
| 4618 | "The calling package is not allowed to select ISD-R."); |
| 4619 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4620 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4621 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4622 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4623 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4624 | null /* workSource */); |
| 4625 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4626 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4627 | // Append the returned status code to the end of the response payload. |
| 4628 | String s = Integer.toHexString( |
| 4629 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4630 | if (response.payload != null) { |
| 4631 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4632 | } |
| 4633 | return s; |
| 4634 | } finally { |
| 4635 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4636 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4637 | } |
| 4638 | |
| 4639 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4640 | 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] | 4641 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4642 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4643 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4644 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4645 | final long identity = Binder.clearCallingIdentity(); |
| 4646 | try { |
| 4647 | if (DBG) { |
| 4648 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4649 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4650 | } |
| 4651 | |
| 4652 | IccIoResult response = |
| 4653 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4654 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4655 | subId); |
| 4656 | |
| 4657 | if (DBG) { |
| 4658 | log("Exchange SIM_IO [R]" + response); |
| 4659 | } |
| 4660 | |
| 4661 | byte[] result = null; |
| 4662 | int length = 2; |
| 4663 | if (response.payload != null) { |
| 4664 | length = 2 + response.payload.length; |
| 4665 | result = new byte[length]; |
| 4666 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4667 | } else { |
| 4668 | result = new byte[length]; |
| 4669 | } |
| 4670 | |
| 4671 | result[length - 1] = (byte) response.sw2; |
| 4672 | result[length - 2] = (byte) response.sw1; |
| 4673 | return result; |
| 4674 | } finally { |
| 4675 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4676 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4677 | } |
| 4678 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4679 | /** |
| 4680 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4681 | * on a particular subscription |
| 4682 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4683 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 4684 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4685 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4686 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4687 | return null; |
| 4688 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4689 | |
| 4690 | final long identity = Binder.clearCallingIdentity(); |
| 4691 | try { |
| 4692 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4693 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4694 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4695 | return null; |
| 4696 | } |
| 4697 | Object response = sendRequest( |
| 4698 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4699 | if (response instanceof String[]) { |
| 4700 | return (String[]) response; |
| 4701 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4702 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4703 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4704 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4705 | } finally { |
| 4706 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4707 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4708 | } |
| 4709 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4710 | /** |
| 4711 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 4712 | * subscription. |
| 4713 | * |
| 4714 | * @param subId the id of the subscription. |
| 4715 | * @param appType the uicc app type, must be USIM or SIM. |
| 4716 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 4717 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4718 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4719 | * @return number of fplmns that is successfully written to the SIM. |
| 4720 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4721 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 4722 | String callingFeatureId) { |
| 4723 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 4724 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4725 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 4726 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 4727 | } |
| 4728 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 4729 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4730 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 4731 | } |
| 4732 | if (fplmns == null) { |
| 4733 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 4734 | } |
| 4735 | for (String fplmn : fplmns) { |
| 4736 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 4737 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 4738 | } |
| 4739 | } |
| 4740 | final long identity = Binder.clearCallingIdentity(); |
| 4741 | try { |
| 4742 | Object response = sendRequest( |
| 4743 | CMD_SET_FORBIDDEN_PLMNS, |
| 4744 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 4745 | subId); |
| 4746 | return (int) response; |
| 4747 | } finally { |
| 4748 | Binder.restoreCallingIdentity(identity); |
| 4749 | } |
| 4750 | } |
| 4751 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4752 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4753 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4754 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4755 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4756 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4757 | final long identity = Binder.clearCallingIdentity(); |
| 4758 | try { |
| 4759 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4760 | if (response.payload == null) { |
| 4761 | return ""; |
| 4762 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4763 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4764 | // Append the returned status code to the end of the response payload. |
| 4765 | String s = Integer.toHexString( |
| 4766 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4767 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4768 | return s; |
| 4769 | } finally { |
| 4770 | Binder.restoreCallingIdentity(identity); |
| 4771 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4772 | } |
| 4773 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4774 | /** |
| 4775 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4776 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4777 | * |
| 4778 | * @param itemID the ID of the item to read |
| 4779 | * @return the NV item as a String, or null on error. |
| 4780 | */ |
| 4781 | @Override |
| 4782 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4783 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4784 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4785 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4786 | |
| 4787 | final long identity = Binder.clearCallingIdentity(); |
| 4788 | try { |
| 4789 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4790 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4791 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4792 | return value; |
| 4793 | } finally { |
| 4794 | Binder.restoreCallingIdentity(identity); |
| 4795 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4796 | } |
| 4797 | |
| 4798 | /** |
| 4799 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4800 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4801 | * |
| 4802 | * @param itemID the ID of the item to read |
| 4803 | * @param itemValue the value to write, as a String |
| 4804 | * @return true on success; false on any failure |
| 4805 | */ |
| 4806 | @Override |
| 4807 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4808 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4809 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4810 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4811 | |
| 4812 | final long identity = Binder.clearCallingIdentity(); |
| 4813 | try { |
| 4814 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4815 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4816 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4817 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4818 | return success; |
| 4819 | } finally { |
| 4820 | Binder.restoreCallingIdentity(identity); |
| 4821 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4822 | } |
| 4823 | |
| 4824 | /** |
| 4825 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4826 | * Used for device configuration by some CDMA operators. |
| 4827 | * |
| 4828 | * @param preferredRoamingList byte array containing the new PRL |
| 4829 | * @return true on success; false on any failure |
| 4830 | */ |
| 4831 | @Override |
| 4832 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4833 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4834 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4835 | |
| 4836 | final long identity = Binder.clearCallingIdentity(); |
| 4837 | try { |
| 4838 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4839 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4840 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4841 | return success; |
| 4842 | } finally { |
| 4843 | Binder.restoreCallingIdentity(identity); |
| 4844 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4845 | } |
| 4846 | |
| 4847 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4848 | * 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] | 4849 | * Used for device configuration by some CDMA operators. |
| 4850 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4851 | * @param slotIndex - device slot. |
| 4852 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4853 | * @return true on success; false on any failure |
| 4854 | */ |
| 4855 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4856 | public boolean resetModemConfig(int slotIndex) { |
| 4857 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4858 | if (phone != null) { |
| 4859 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4860 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4861 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4862 | final long identity = Binder.clearCallingIdentity(); |
| 4863 | try { |
| 4864 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4865 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4866 | return success; |
| 4867 | } finally { |
| 4868 | Binder.restoreCallingIdentity(identity); |
| 4869 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4870 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4871 | return false; |
| 4872 | } |
| 4873 | |
| 4874 | /** |
| 4875 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4876 | * |
| 4877 | * @param slotIndex - device slot. |
| 4878 | * |
| 4879 | * @return true on success; false on any failure |
| 4880 | */ |
| 4881 | @Override |
| 4882 | public boolean rebootModem(int slotIndex) { |
| 4883 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4884 | if (phone != null) { |
| 4885 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4886 | mApp, phone.getSubId(), "rebootModem"); |
| 4887 | |
| 4888 | final long identity = Binder.clearCallingIdentity(); |
| 4889 | try { |
| 4890 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4891 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4892 | return success; |
| 4893 | } finally { |
| 4894 | Binder.restoreCallingIdentity(identity); |
| 4895 | } |
| 4896 | } |
| 4897 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4898 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4899 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4900 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 4901 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4902 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4903 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4904 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4905 | return new String[0]; |
| 4906 | } |
| 4907 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4908 | final long identity = Binder.clearCallingIdentity(); |
| 4909 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4910 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4911 | } finally { |
| 4912 | Binder.restoreCallingIdentity(identity); |
| 4913 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4914 | } |
| 4915 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4916 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 4917 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 4918 | * {@link #disableIms(int)}. |
| 4919 | * @param slotIndex device slot. |
| 4920 | */ |
| 4921 | public void resetIms(int slotIndex) { |
| 4922 | enforceModifyPermission(); |
| 4923 | |
| 4924 | final long identity = Binder.clearCallingIdentity(); |
| 4925 | try { |
| 4926 | if (mImsResolver == null) { |
| 4927 | // may happen if the does not support IMS. |
| 4928 | return; |
| 4929 | } |
| 4930 | mImsResolver.disableIms(slotIndex); |
| 4931 | mImsResolver.enableIms(slotIndex); |
| 4932 | } finally { |
| 4933 | Binder.restoreCallingIdentity(identity); |
| 4934 | } |
| 4935 | } |
| 4936 | |
| 4937 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4938 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4939 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4940 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4941 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4942 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4943 | |
| 4944 | final long identity = Binder.clearCallingIdentity(); |
| 4945 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4946 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4947 | // may happen if the device does not support IMS. |
| 4948 | return; |
| 4949 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4950 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4951 | } finally { |
| 4952 | Binder.restoreCallingIdentity(identity); |
| 4953 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4954 | } |
| 4955 | |
| 4956 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4957 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4958 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4959 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4960 | public void disableIms(int slotId) { |
| 4961 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4962 | |
| 4963 | final long identity = Binder.clearCallingIdentity(); |
| 4964 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4965 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4966 | // may happen if the device does not support IMS. |
| 4967 | return; |
| 4968 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4969 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4970 | } finally { |
| 4971 | Binder.restoreCallingIdentity(identity); |
| 4972 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4973 | } |
| 4974 | |
| 4975 | /** |
| 4976 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4977 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4978 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4979 | */ |
| 4980 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4981 | IImsServiceFeatureCallback callback) { |
| 4982 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4983 | |
| 4984 | final long identity = Binder.clearCallingIdentity(); |
| 4985 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4986 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4987 | // may happen if the device does not support IMS. |
| 4988 | return null; |
| 4989 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4990 | return mImsResolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4991 | } finally { |
| 4992 | Binder.restoreCallingIdentity(identity); |
| 4993 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4994 | } |
| 4995 | |
| 4996 | /** |
| 4997 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4998 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4999 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 5000 | * listener for feature updates. |
| 5001 | */ |
| 5002 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 5003 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5004 | |
| 5005 | final long identity = Binder.clearCallingIdentity(); |
| 5006 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5007 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5008 | // may happen if the device does not support IMS. |
| 5009 | return null; |
| 5010 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5011 | return mImsResolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5012 | } finally { |
| 5013 | Binder.restoreCallingIdentity(identity); |
| 5014 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5015 | } |
| 5016 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5017 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5018 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5019 | */ |
| 5020 | public void unregisterImsFeatureCallback(int slotId, int featureType, |
| 5021 | IImsServiceFeatureCallback callback) { |
| 5022 | enforceModifyPermission(); |
| 5023 | |
| 5024 | final long identity = Binder.clearCallingIdentity(); |
| 5025 | try { |
| 5026 | if (mImsResolver == null) return; |
| 5027 | mImsResolver.unregisterImsFeatureCallback(slotId, featureType, callback); |
| 5028 | } finally { |
| 5029 | Binder.restoreCallingIdentity(identity); |
| 5030 | } |
| 5031 | } |
| 5032 | |
| 5033 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5034 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5035 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5036 | */ |
| 5037 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5038 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5039 | |
| 5040 | final long identity = Binder.clearCallingIdentity(); |
| 5041 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5042 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5043 | // may happen if the device does not support IMS. |
| 5044 | return null; |
| 5045 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5046 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5047 | } finally { |
| 5048 | Binder.restoreCallingIdentity(identity); |
| 5049 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5050 | } |
| 5051 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5052 | /** |
| 5053 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5054 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5055 | */ |
| 5056 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5057 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5058 | |
| 5059 | final long identity = Binder.clearCallingIdentity(); |
| 5060 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5061 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5062 | // may happen if the device does not support IMS. |
| 5063 | return null; |
| 5064 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5065 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5066 | } finally { |
| 5067 | Binder.restoreCallingIdentity(identity); |
| 5068 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5069 | } |
| 5070 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5071 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5072 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5073 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5074 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5075 | * @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] | 5076 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5077 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5078 | * @param packageName The name of the package that the current configuration will be replaced |
| 5079 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5080 | * @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] | 5081 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5082 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5083 | int[] featureTypes, String packageName) { |
| 5084 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5085 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5086 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5087 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5088 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5089 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5090 | final long identity = Binder.clearCallingIdentity(); |
| 5091 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5092 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5093 | // may happen if the device does not support IMS. |
| 5094 | return false; |
| 5095 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5096 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5097 | for (int featureType : featureTypes) { |
| 5098 | featureConfig.put(featureType, packageName); |
| 5099 | } |
| 5100 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5101 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5102 | } finally { |
| 5103 | Binder.restoreCallingIdentity(identity); |
| 5104 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5105 | } |
| 5106 | |
| 5107 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5108 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5109 | * |
| 5110 | * @param slotId The slot that the ImsService is associated with. |
| 5111 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5112 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5113 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5114 | * @return the package name of the ImsService configuration. |
| 5115 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5116 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5117 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5118 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5119 | TelephonyPermissions |
| 5120 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5121 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5122 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5123 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5124 | final long identity = Binder.clearCallingIdentity(); |
| 5125 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5126 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5127 | // may happen if the device does not support IMS. |
| 5128 | return ""; |
| 5129 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5130 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5131 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5132 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5133 | } finally { |
| 5134 | Binder.restoreCallingIdentity(identity); |
| 5135 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5136 | } |
| 5137 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5138 | /** |
| 5139 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5140 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5141 | * @param callback A callback with an integer containing the |
| 5142 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5143 | */ |
| 5144 | @Override |
| 5145 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5146 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5147 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5148 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5149 | "IMS not available on device."); |
| 5150 | } |
| 5151 | final long token = Binder.clearCallingIdentity(); |
| 5152 | try { |
| 5153 | int slotId = getSlotIndex(subId); |
| 5154 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5155 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5156 | + subId + "'"); |
| 5157 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5158 | } |
| 5159 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5160 | try { |
| 5161 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5162 | } catch (RemoteException e) { |
| 5163 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5164 | + "Ignore"); |
| 5165 | } |
| 5166 | }); |
| 5167 | } finally { |
| 5168 | Binder.restoreCallingIdentity(token); |
| 5169 | } |
| 5170 | } |
| 5171 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5172 | public void setImsRegistrationState(boolean registered) { |
| 5173 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5174 | |
| 5175 | final long identity = Binder.clearCallingIdentity(); |
| 5176 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5177 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5178 | } finally { |
| 5179 | Binder.restoreCallingIdentity(identity); |
| 5180 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5181 | } |
| 5182 | |
| 5183 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5184 | * Set the network selection mode to automatic. |
| 5185 | * |
| 5186 | */ |
| 5187 | @Override |
| 5188 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5189 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5190 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5191 | |
| 5192 | final long identity = Binder.clearCallingIdentity(); |
| 5193 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5194 | if (!isActiveSubscription(subId)) { |
| 5195 | return; |
| 5196 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5197 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 5198 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 5199 | } finally { |
| 5200 | Binder.restoreCallingIdentity(identity); |
| 5201 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5202 | } |
| 5203 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5204 | /** |
| 5205 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5206 | * |
| 5207 | * @param subId the id of the subscription. |
| 5208 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5209 | * the operator to attach to. |
| 5210 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5211 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5212 | * normal network selection next time. |
| 5213 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5214 | */ |
| 5215 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5216 | public boolean setNetworkSelectionModeManual( |
| 5217 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5218 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5219 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5220 | |
| 5221 | if (!isActiveSubscription(subId)) { |
| 5222 | return false; |
| 5223 | } |
| 5224 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5225 | final long identity = Binder.clearCallingIdentity(); |
| 5226 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5227 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5228 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5229 | if (DBG) { |
| 5230 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5231 | + " operator: " + operatorInfo); |
| 5232 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5233 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5234 | } finally { |
| 5235 | Binder.restoreCallingIdentity(identity); |
| 5236 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5237 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5238 | /** |
| 5239 | * Get the manual network selection |
| 5240 | * |
| 5241 | * @param subId the id of the subscription. |
| 5242 | * |
| 5243 | * @return the previously saved user selected PLMN |
| 5244 | */ |
| 5245 | @Override |
| 5246 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5247 | TelephonyPermissions |
| 5248 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5249 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5250 | |
| 5251 | final long identity = Binder.clearCallingIdentity(); |
| 5252 | try { |
| 5253 | if (!isActiveSubscription(subId)) { |
| 5254 | return ""; |
| 5255 | } |
| 5256 | |
| 5257 | final Phone phone = getPhone(subId); |
| 5258 | if (phone == null) { |
| 5259 | return ""; |
| 5260 | } |
| 5261 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5262 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5263 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5264 | } finally { |
| 5265 | Binder.restoreCallingIdentity(identity); |
| 5266 | } |
| 5267 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5268 | |
| 5269 | /** |
| 5270 | * Scans for available networks. |
| 5271 | */ |
| 5272 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5273 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5274 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5275 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5276 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5277 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5278 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5279 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5280 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5281 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5282 | .setCallingPid(Binder.getCallingPid()) |
| 5283 | .setCallingUid(Binder.getCallingUid()) |
| 5284 | .setMethod("getCellNetworkScanResults") |
| 5285 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5286 | .build()); |
| 5287 | switch (locationResult) { |
| 5288 | case DENIED_HARD: |
| 5289 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5290 | case DENIED_SOFT: |
| 5291 | return null; |
| 5292 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5293 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5294 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5295 | try { |
| 5296 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5297 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5298 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5299 | } finally { |
| 5300 | Binder.restoreCallingIdentity(identity); |
| 5301 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5302 | } |
| 5303 | |
| 5304 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5305 | * Get the call forwarding info, given the call forwarding reason. |
| 5306 | */ |
| 5307 | @Override |
| 5308 | public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) { |
| 5309 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5310 | long identity = Binder.clearCallingIdentity(); |
| 5311 | try { |
| 5312 | if (DBG) { |
| 5313 | log("getCallForwarding: subId " + subId |
| 5314 | + " callForwardingReason" + callForwardingReason); |
| 5315 | } |
| 5316 | return (CallForwardingInfo) sendRequest( |
| 5317 | CMD_GET_CALL_FORWARDING, callForwardingReason, subId); |
| 5318 | } finally { |
| 5319 | Binder.restoreCallingIdentity(identity); |
| 5320 | } |
| 5321 | } |
| 5322 | |
| 5323 | /** |
| 5324 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5325 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5326 | */ |
| 5327 | @Override |
| 5328 | public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) { |
| 5329 | enforceModifyPermission(); |
| 5330 | long identity = Binder.clearCallingIdentity(); |
| 5331 | try { |
| 5332 | if (DBG) { |
| 5333 | log("setCallForwarding: subId " + subId |
| 5334 | + " callForwardingInfo" + callForwardingInfo); |
| 5335 | } |
| 5336 | return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId); |
| 5337 | } finally { |
| 5338 | Binder.restoreCallingIdentity(identity); |
| 5339 | } |
| 5340 | } |
| 5341 | |
| 5342 | /** |
| 5343 | * Get the call forwarding info, given the call forwarding reason. |
| 5344 | */ |
| 5345 | @Override |
| 5346 | public int getCallWaitingStatus(int subId) { |
| 5347 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5348 | long identity = Binder.clearCallingIdentity(); |
| 5349 | try { |
| 5350 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 5351 | return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId); |
| 5352 | } finally { |
| 5353 | Binder.restoreCallingIdentity(identity); |
| 5354 | } |
| 5355 | } |
| 5356 | |
| 5357 | /** |
| 5358 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5359 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5360 | */ |
| 5361 | @Override |
| 5362 | public boolean setCallWaitingStatus(int subId, boolean isEnable) { |
| 5363 | enforceModifyPermission(); |
| 5364 | long identity = Binder.clearCallingIdentity(); |
| 5365 | try { |
| 5366 | if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable); |
| 5367 | return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId); |
| 5368 | } finally { |
| 5369 | Binder.restoreCallingIdentity(identity); |
| 5370 | } |
| 5371 | } |
| 5372 | |
| 5373 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5374 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5375 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5376 | * @param subId id of the subscription |
| 5377 | * @param request contains the radio access networks with bands/channels to scan |
| 5378 | * @param messenger callback messenger for scan results or errors |
| 5379 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5380 | * @return the id of the requested scan which can be used to stop the scan. |
| 5381 | */ |
| 5382 | @Override |
| 5383 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5384 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5385 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5386 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5387 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5388 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5389 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5390 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5391 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5392 | .setCallingPid(Binder.getCallingPid()) |
| 5393 | .setCallingUid(Binder.getCallingUid()) |
| 5394 | .setMethod("requestNetworkScan") |
| 5395 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5396 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5397 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5398 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5399 | if (e != null) { |
| 5400 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5401 | throw e; |
| 5402 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5403 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5404 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5405 | } |
| 5406 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5407 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5408 | int callingUid = Binder.getCallingUid(); |
| 5409 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5410 | final long identity = Binder.clearCallingIdentity(); |
| 5411 | try { |
| 5412 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5413 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5414 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5415 | } finally { |
| 5416 | Binder.restoreCallingIdentity(identity); |
| 5417 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5418 | } |
| 5419 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5420 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5421 | NetworkScanRequest request, int subId) { |
| 5422 | boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid()) |
| 5423 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5424 | boolean hasNetworkScanPermission = |
| 5425 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5426 | == PERMISSION_GRANTED; |
| 5427 | |
| 5428 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5429 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5430 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5431 | } |
| 5432 | |
| 5433 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5434 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5435 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5436 | return new SecurityException("Specific channels must not be" |
| 5437 | + " scanned without location access."); |
| 5438 | } |
| 5439 | } |
| 5440 | } |
| 5441 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5442 | return null; |
| 5443 | } |
| 5444 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5445 | /** |
| 5446 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5447 | * |
| 5448 | * @param subId id of the subscription |
| 5449 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5450 | */ |
| 5451 | @Override |
| 5452 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5453 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5454 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5455 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5456 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5457 | final long identity = Binder.clearCallingIdentity(); |
| 5458 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5459 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5460 | } finally { |
| 5461 | Binder.restoreCallingIdentity(identity); |
| 5462 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5463 | } |
| 5464 | |
| 5465 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5466 | * Get the calculated preferred network type. |
| 5467 | * Used for debugging incorrect network type. |
| 5468 | * |
| 5469 | * @return the preferred network type, defined in RILConstants.java. |
| 5470 | */ |
| 5471 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5472 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5473 | final Phone defaultPhone = getDefaultPhone(); |
| 5474 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5475 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5476 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5477 | } |
| 5478 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5479 | final long identity = Binder.clearCallingIdentity(); |
| 5480 | try { |
| 5481 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5482 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5483 | } finally { |
| 5484 | Binder.restoreCallingIdentity(identity); |
| 5485 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5486 | } |
| 5487 | |
| 5488 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5489 | * Get the preferred network type. |
| 5490 | * Used for device configuration by some CDMA operators. |
| 5491 | * |
| 5492 | * @return the preferred network type, defined in RILConstants.java. |
| 5493 | */ |
| 5494 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5495 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5496 | TelephonyPermissions |
| 5497 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5498 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5499 | |
| 5500 | final long identity = Binder.clearCallingIdentity(); |
| 5501 | try { |
| 5502 | if (DBG) log("getPreferredNetworkType"); |
| 5503 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5504 | int networkType = (result != null ? result[0] : -1); |
| 5505 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5506 | return networkType; |
| 5507 | } finally { |
| 5508 | Binder.restoreCallingIdentity(identity); |
| 5509 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5510 | } |
| 5511 | |
| 5512 | /** |
| 5513 | * Set the preferred network type. |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5514 | * |
| 5515 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5516 | * @return true on success; false on any failure. |
| 5517 | */ |
| 5518 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5519 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5520 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5521 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5522 | |
| 5523 | final long identity = Binder.clearCallingIdentity(); |
| 5524 | try { |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5525 | Settings.Global.putInt(mApp.getContentResolver(), |
| 5526 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5527 | |
| 5528 | Boolean success = (Boolean) sendRequest( |
| 5529 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 5530 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 5531 | return success; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5532 | } finally { |
| 5533 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5534 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5535 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5536 | |
| 5537 | /** |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5538 | * Get the allowed network types that store in the telephony provider. |
| 5539 | * |
| 5540 | * @param subId the id of the subscription. |
| 5541 | * @return allowedNetworkTypes the allowed network types. |
| 5542 | */ |
| 5543 | @Override |
| 5544 | public long getAllowedNetworkTypes(int subId) { |
| 5545 | TelephonyPermissions |
| 5546 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5547 | mApp, subId, "getAllowedNetworkTypes"); |
| 5548 | |
| 5549 | final long identity = Binder.clearCallingIdentity(); |
| 5550 | try { |
| 5551 | return SubscriptionManager.getLongSubscriptionProperty( |
| 5552 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5553 | } finally { |
| 5554 | Binder.restoreCallingIdentity(identity); |
| 5555 | } |
| 5556 | } |
| 5557 | |
| 5558 | /** |
| 5559 | * Set the allowed network types. |
| 5560 | * |
| 5561 | * @param subId the id of the subscription. |
| 5562 | * @param allowedNetworkTypes the allowed network types. |
| 5563 | * @return true on success; false on any failure. |
| 5564 | */ |
| 5565 | @Override |
| 5566 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 5567 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5568 | mApp, subId, "setAllowedNetworkTypes"); |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5569 | |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5570 | SubscriptionManager.setSubscriptionProperty(subId, |
| 5571 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 5572 | String.valueOf(allowedNetworkTypes)); |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5573 | |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5574 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 5575 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5576 | RILConstants.PREFERRED_NETWORK_MODE); |
| 5577 | return setPreferredNetworkType(subId, preferredNetworkMode); |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5578 | } |
| 5579 | |
| 5580 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame^] | 5581 | * Get the allowed network types for certain reason. |
| 5582 | * |
| 5583 | * @param subId the id of the subscription. |
| 5584 | * @param reason the reason the allowed network type change is taking place |
| 5585 | * @return the allowed network types. |
| 5586 | */ |
| 5587 | @Override |
| 5588 | public long getAllowedNetworkTypesForReason(int subId, |
| 5589 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
| 5590 | TelephonyPermissions |
| 5591 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5592 | mApp, subId, "getAllowedNetworkTypesForReason"); |
| 5593 | final long identity = Binder.clearCallingIdentity(); |
| 5594 | try { |
| 5595 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 5596 | } finally { |
| 5597 | Binder.restoreCallingIdentity(identity); |
| 5598 | } |
| 5599 | } |
| 5600 | |
| 5601 | /** |
| 5602 | * Get the effective allowed network types on the device. |
| 5603 | * This API will return an intersection of allowed network types for all reasons, |
| 5604 | * including the configuration done through setAllowedNetworkTypes |
| 5605 | * |
| 5606 | * @param subId the id of the subscription. |
| 5607 | * @return the allowed network types |
| 5608 | */ |
| 5609 | @Override |
| 5610 | public long getEffectiveAllowedNetworkTypes(int subId) { |
| 5611 | TelephonyPermissions |
| 5612 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5613 | mApp, subId, "getEffectiveAllowedNetworkTypes"); |
| 5614 | final long identity = Binder.clearCallingIdentity(); |
| 5615 | try { |
| 5616 | return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes(); |
| 5617 | } finally { |
| 5618 | Binder.restoreCallingIdentity(identity); |
| 5619 | } |
| 5620 | } |
| 5621 | |
| 5622 | /** |
| 5623 | * Set the allowed network types of the device and |
| 5624 | * provide the reason triggering the allowed network change. |
| 5625 | * |
| 5626 | * @param subId the id of the subscription. |
| 5627 | * @param reason the reason the allowed network type change is taking place |
| 5628 | * @param allowedNetworkTypes the allowed network types. |
| 5629 | * @return true on success; false on any failure. |
| 5630 | */ |
| 5631 | @Override |
| 5632 | public boolean setAllowedNetworkTypesForReason(int subId, |
| 5633 | @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) { |
| 5634 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5635 | mApp, subId, "setAllowedNetworkTypesForReason"); |
| 5636 | final long identity = Binder.clearCallingIdentity(); |
| 5637 | try { |
| 5638 | getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes); |
| 5639 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 5640 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5641 | RILConstants.PREFERRED_NETWORK_MODE); |
| 5642 | return setPreferredNetworkType(subId, preferredNetworkMode); |
| 5643 | } finally { |
| 5644 | Binder.restoreCallingIdentity(identity); |
| 5645 | } |
| 5646 | } |
| 5647 | |
| 5648 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5649 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5650 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5651 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 5652 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5653 | * @hide |
| 5654 | */ |
| 5655 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 5656 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5657 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5658 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5659 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5660 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5661 | if (phone != null) { |
| 5662 | return phone.hasMatchedTetherApnSetting(); |
| 5663 | } else { |
| 5664 | return false; |
| 5665 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5666 | } finally { |
| 5667 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5668 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5669 | } |
| 5670 | |
| 5671 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5672 | * Set mobile data enabled |
| 5673 | * Used by the user through settings etc to turn on/off mobile data |
| 5674 | * |
| 5675 | * @param enable {@code true} turn turn data on, else {@code false} |
| 5676 | */ |
| 5677 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5678 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5679 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5680 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5681 | |
| 5682 | final long identity = Binder.clearCallingIdentity(); |
| 5683 | try { |
| 5684 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5685 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5686 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5687 | if (phone != null) { |
| 5688 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5689 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5690 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5691 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5692 | } |
| 5693 | } finally { |
| 5694 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5695 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5696 | } |
| 5697 | |
| 5698 | /** |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 5699 | * Enable or disable always reporting signal strength changes from radio. |
| 5700 | * |
| 5701 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 5702 | */ |
| 5703 | @Override |
| 5704 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 5705 | enforceModifyPermission(); |
| 5706 | enforceSystemCaller(); |
| 5707 | |
| 5708 | final long identity = Binder.clearCallingIdentity(); |
| 5709 | final Phone phone = getPhone(subId); |
| 5710 | try { |
| 5711 | if (phone != null) { |
| 5712 | if (DBG) { |
| 5713 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 5714 | + " isEnable=" + isEnable); |
| 5715 | } |
| 5716 | phone.setAlwaysReportSignalStrength(isEnable); |
| 5717 | } else { |
| 5718 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 5719 | + subId); |
| 5720 | } |
| 5721 | } finally { |
| 5722 | Binder.restoreCallingIdentity(identity); |
| 5723 | } |
| 5724 | } |
| 5725 | |
| 5726 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5727 | * Get the user enabled state of Mobile Data. |
| 5728 | * |
| 5729 | * TODO: remove and use isUserDataEnabled. |
| 5730 | * This can't be removed now because some vendor codes |
| 5731 | * calls through ITelephony directly while they should |
| 5732 | * use TelephonyManager. |
| 5733 | * |
| 5734 | * @return true on enabled |
| 5735 | */ |
| 5736 | @Override |
| 5737 | public boolean getDataEnabled(int subId) { |
| 5738 | return isUserDataEnabled(subId); |
| 5739 | } |
| 5740 | |
| 5741 | /** |
| 5742 | * Get whether mobile data is enabled per user setting. |
| 5743 | * |
| 5744 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 5745 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5746 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 5747 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5748 | * |
| 5749 | * @return {@code true} if data is enabled else {@code false} |
| 5750 | */ |
| 5751 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5752 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5753 | try { |
| 5754 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 5755 | null); |
| 5756 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5757 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5758 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5759 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5760 | |
| 5761 | final long identity = Binder.clearCallingIdentity(); |
| 5762 | try { |
| 5763 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5764 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5765 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5766 | if (phone != null) { |
| 5767 | boolean retVal = phone.isUserDataEnabled(); |
| 5768 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5769 | return retVal; |
| 5770 | } else { |
| 5771 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5772 | return false; |
| 5773 | } |
| 5774 | } finally { |
| 5775 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5776 | } |
| 5777 | } |
| 5778 | |
| 5779 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5780 | * Checks if the device is capable of mobile data by considering whether whether the |
| 5781 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 5782 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5783 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5784 | * @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] | 5785 | */ |
| 5786 | @Override |
| 5787 | public boolean isDataEnabled(int subId) { |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5788 | enforceReadPrivilegedPermission("isDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5789 | |
| 5790 | final long identity = Binder.clearCallingIdentity(); |
| 5791 | try { |
| 5792 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5793 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5794 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5795 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5796 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5797 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5798 | return retVal; |
| 5799 | } else { |
| 5800 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5801 | return false; |
| 5802 | } |
| 5803 | } finally { |
| 5804 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5805 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5806 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5807 | |
Malcolm Chen | 6a13f2a | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 5808 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5809 | Phone phone) { |
| 5810 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5811 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5812 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5813 | || subController == null) return privilegeFromSim; |
| 5814 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5815 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 5816 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 5817 | |
| 5818 | final long identity = Binder.clearCallingIdentity(); |
| 5819 | try { |
| 5820 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5821 | SubscriptionManager subManager = (SubscriptionManager) |
| 5822 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5823 | for (String pkg : packages) { |
| 5824 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 5825 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5826 | } |
| 5827 | } |
| 5828 | return privilegeFromSim; |
| 5829 | } finally { |
| 5830 | Binder.restoreCallingIdentity(identity); |
| 5831 | } |
| 5832 | } |
| 5833 | |
| 5834 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 5835 | String pkgName) { |
| 5836 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5837 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5838 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5839 | || subController == null) return privilegeFromSim; |
| 5840 | |
| 5841 | final long identity = Binder.clearCallingIdentity(); |
| 5842 | try { |
| 5843 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5844 | SubscriptionManager subManager = (SubscriptionManager) |
| 5845 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5846 | return subManager.canManageSubscription(subInfo, pkgName) |
| 5847 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 5848 | } finally { |
| 5849 | Binder.restoreCallingIdentity(identity); |
| 5850 | } |
| 5851 | } |
| 5852 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5853 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5854 | public int getCarrierPrivilegeStatus(int subId) { |
| 5855 | final Phone phone = getPhone(subId); |
| 5856 | if (phone == null) { |
| 5857 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 5858 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5859 | } |
| 5860 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5861 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 5862 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5863 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5864 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5865 | |
| 5866 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5867 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | 6a13f2a | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 5868 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5869 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5870 | |
| 5871 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5872 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5873 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5874 | final Phone phone = getPhone(subId); |
| 5875 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5876 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5877 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5878 | } |
| 5879 | UiccProfile profile = |
| 5880 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 5881 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5882 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5883 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5884 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5885 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5886 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | 6a13f2a | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 5887 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5888 | } |
| 5889 | |
| 5890 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5891 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 5892 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5893 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5894 | } |
| 5895 | |
| 5896 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 5897 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5898 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5899 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5900 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5901 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5902 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5903 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5904 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5905 | } |
| 5906 | |
| 5907 | @Override |
| 5908 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5909 | if (TextUtils.isEmpty(pkgName)) |
| 5910 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5911 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5912 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5913 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 5914 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 5915 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5916 | continue; |
| 5917 | } |
| 5918 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5919 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5920 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5921 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5922 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 5923 | break; |
| 5924 | } |
| 5925 | } |
| 5926 | |
| 5927 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5928 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 5929 | |
| 5930 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 5931 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 5932 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 5933 | loge("phoneId " + phoneId + " is not valid."); |
| 5934 | return null; |
| 5935 | } |
| 5936 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5937 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5938 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5939 | return null ; |
| 5940 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5941 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5942 | } |
| 5943 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5944 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5945 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5946 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5947 | List<String> privilegedPackages = new ArrayList<>(); |
| 5948 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5949 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 5950 | // has UICC in that slot. |
| 5951 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5952 | if (card.hasCarrierPrivilegeRules()) { |
| 5953 | if (packages == null) { |
| 5954 | // Only check packages in user 0 for now |
| 5955 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5956 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 5957 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 5958 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 5959 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5960 | } |
| 5961 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 5962 | PackageInfo pkgInfo = packages.get(p); |
| 5963 | if (pkgInfo != null && pkgInfo.packageName != null |
| 5964 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5965 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5966 | privilegedPackages.add(pkgInfo.packageName); |
| 5967 | } |
| 5968 | } |
| 5969 | } |
| 5970 | } |
| 5971 | return privilegedPackages; |
| 5972 | } |
| 5973 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5974 | @Override |
| 5975 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5976 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 5977 | |
| 5978 | final long identity = Binder.clearCallingIdentity(); |
| 5979 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5980 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5981 | try { |
| 5982 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5983 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 5984 | } |
| 5985 | } finally { |
| 5986 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5987 | } |
| 5988 | return privilegedPackages; |
| 5989 | } |
| 5990 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5991 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5992 | final Phone phone = getPhone(subId); |
| 5993 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5994 | if (card == null) { |
| 5995 | loge("getIccId: No UICC"); |
| 5996 | return null; |
| 5997 | } |
| 5998 | String iccId = card.getIccId(); |
| 5999 | if (TextUtils.isEmpty(iccId)) { |
| 6000 | loge("getIccId: ICC ID is null or empty."); |
| 6001 | return null; |
| 6002 | } |
| 6003 | return iccId; |
| 6004 | } |
| 6005 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6006 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6007 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6008 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6009 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6010 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6011 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6012 | final long identity = Binder.clearCallingIdentity(); |
| 6013 | try { |
| 6014 | final String iccId = getIccId(subId); |
| 6015 | final Phone phone = getPhone(subId); |
| 6016 | if (phone == null) { |
| 6017 | return false; |
| 6018 | } |
| 6019 | final String subscriberId = phone.getSubscriberId(); |
| 6020 | |
| 6021 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6022 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6023 | + subscriberId + " to " + number); |
| 6024 | } |
| 6025 | |
| 6026 | if (TextUtils.isEmpty(iccId)) { |
| 6027 | return false; |
| 6028 | } |
| 6029 | |
| 6030 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6031 | |
| 6032 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6033 | if (alphaTag == null) { |
| 6034 | editor.remove(alphaTagPrefKey); |
| 6035 | } else { |
| 6036 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6037 | } |
| 6038 | |
| 6039 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6040 | // track all merged IMSIs based on line number |
| 6041 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6042 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6043 | if (number == null) { |
| 6044 | editor.remove(numberPrefKey); |
| 6045 | editor.remove(subscriberPrefKey); |
| 6046 | } else { |
| 6047 | editor.putString(numberPrefKey, number); |
| 6048 | editor.putString(subscriberPrefKey, subscriberId); |
| 6049 | } |
| 6050 | |
| 6051 | editor.commit(); |
| 6052 | return true; |
| 6053 | } finally { |
| 6054 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6055 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6056 | } |
| 6057 | |
| 6058 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6059 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6060 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6061 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6062 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6063 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6064 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6065 | return null; |
| 6066 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6067 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6068 | final long identity = Binder.clearCallingIdentity(); |
| 6069 | try { |
| 6070 | String iccId = getIccId(subId); |
| 6071 | if (iccId != null) { |
| 6072 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6073 | if (DBG_MERGE) { |
| 6074 | log("getLine1NumberForDisplay returning " |
| 6075 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6076 | } |
| 6077 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6078 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6079 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6080 | return null; |
| 6081 | } finally { |
| 6082 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6083 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6084 | } |
| 6085 | |
| 6086 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6087 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6088 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6089 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6090 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6091 | return null; |
| 6092 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6093 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6094 | final long identity = Binder.clearCallingIdentity(); |
| 6095 | try { |
| 6096 | String iccId = getIccId(subId); |
| 6097 | if (iccId != null) { |
| 6098 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6099 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6100 | } |
| 6101 | return null; |
| 6102 | } finally { |
| 6103 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6104 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6105 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6106 | |
| 6107 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6108 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6109 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6110 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6111 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6112 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6113 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6114 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6115 | return null; |
| 6116 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6117 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6118 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6119 | // the process, where TelephonyManager was instantiated. |
| 6120 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6121 | final long identity = Binder.clearCallingIdentity(); |
| 6122 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6123 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6124 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6125 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6126 | |
| 6127 | // Figure out what subscribers are currently active |
| 6128 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6129 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6130 | // Only consider subs which match the current subId |
| 6131 | // This logic can be simplified. See b/131189269 for progress. |
| 6132 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6133 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6134 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6135 | |
| 6136 | // First pass, find a number override for an active subscriber |
| 6137 | String mergeNumber = null; |
| 6138 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6139 | for (String key : prefs.keySet()) { |
| 6140 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6141 | final String subscriberId = (String) prefs.get(key); |
| 6142 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6143 | final String iccId = key.substring( |
| 6144 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6145 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6146 | mergeNumber = (String) prefs.get(numberKey); |
| 6147 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6148 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6149 | + " for active subscriber " + subscriberId); |
| 6150 | } |
| 6151 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6152 | break; |
| 6153 | } |
| 6154 | } |
| 6155 | } |
| 6156 | } |
| 6157 | |
| 6158 | // Shortcut when no active merged subscribers |
| 6159 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6160 | return null; |
| 6161 | } |
| 6162 | |
| 6163 | // Second pass, find all subscribers under that line override |
| 6164 | final ArraySet<String> result = new ArraySet<>(); |
| 6165 | for (String key : prefs.keySet()) { |
| 6166 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6167 | final String number = (String) prefs.get(key); |
| 6168 | if (mergeNumber.equals(number)) { |
| 6169 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6170 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6171 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6172 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6173 | result.add(subscriberId); |
| 6174 | } |
| 6175 | } |
| 6176 | } |
| 6177 | } |
| 6178 | |
| 6179 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6180 | Arrays.sort(resultArray); |
| 6181 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6182 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6183 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6184 | } |
| 6185 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6186 | } finally { |
| 6187 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6188 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6189 | } |
| 6190 | |
| 6191 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6192 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6193 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6194 | |
| 6195 | final long identity = Binder.clearCallingIdentity(); |
| 6196 | try { |
| 6197 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6198 | TelephonyManager.class); |
| 6199 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6200 | if (subscriberId == null) { |
| 6201 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6202 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6203 | + subId); |
| 6204 | } |
| 6205 | return null; |
| 6206 | } |
| 6207 | |
| 6208 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6209 | .getSubscriptionInfo(subId); |
| 6210 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6211 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6212 | if (groupUuid == null) { |
| 6213 | return new String[]{subscriberId}; |
| 6214 | } |
| 6215 | |
| 6216 | // Get all subscriberIds from the group. |
| 6217 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6218 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6219 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6220 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6221 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6222 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6223 | if (subscriberId != null) { |
| 6224 | mergedSubscriberIds.add(subscriberId); |
| 6225 | } |
| 6226 | } |
| 6227 | |
| 6228 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6229 | } finally { |
| 6230 | Binder.restoreCallingIdentity(identity); |
| 6231 | |
| 6232 | } |
| 6233 | } |
| 6234 | |
| 6235 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6236 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6237 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6238 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6239 | |
| 6240 | final long identity = Binder.clearCallingIdentity(); |
| 6241 | try { |
| 6242 | final Phone phone = getPhone(subId); |
| 6243 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6244 | } finally { |
| 6245 | Binder.restoreCallingIdentity(identity); |
| 6246 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6247 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6248 | |
| 6249 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6250 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6251 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6252 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6253 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6254 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6255 | |
| 6256 | final long identity = Binder.clearCallingIdentity(); |
| 6257 | try { |
| 6258 | final Phone phone = getPhone(subId); |
| 6259 | if (phone == null) { |
| 6260 | return false; |
| 6261 | } |
| 6262 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6263 | cdmaNonRoamingList); |
| 6264 | } finally { |
| 6265 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6266 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6267 | } |
| 6268 | |
| 6269 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6270 | @Deprecated |
| 6271 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6272 | enforceModifyPermission(); |
| 6273 | |
| 6274 | int returnValue = 0; |
| 6275 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6276 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6277 | if(result.exception == null) { |
| 6278 | if (result.result != null) { |
| 6279 | byte[] responseData = (byte[])(result.result); |
| 6280 | if(responseData.length > oemResp.length) { |
| 6281 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6282 | responseData.length + "bytes. Buffer Size is " + |
| 6283 | oemResp.length + "bytes."); |
| 6284 | } |
| 6285 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6286 | returnValue = responseData.length; |
| 6287 | } |
| 6288 | } else { |
| 6289 | CommandException ex = (CommandException) result.exception; |
| 6290 | returnValue = ex.getCommandError().ordinal(); |
| 6291 | if(returnValue > 0) returnValue *= -1; |
| 6292 | } |
| 6293 | } catch (RuntimeException e) { |
| 6294 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6295 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6296 | if(returnValue > 0) returnValue *= -1; |
| 6297 | } |
| 6298 | |
| 6299 | return returnValue; |
| 6300 | } |
| 6301 | |
| 6302 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6303 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6304 | try { |
| 6305 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6306 | } catch (RuntimeException e) { |
| 6307 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6308 | } |
| 6309 | } |
| 6310 | |
| 6311 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6312 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6313 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6314 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6315 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6316 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6317 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6318 | final long identity = Binder.clearCallingIdentity(); |
| 6319 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6320 | TelephonyPermissions |
| 6321 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6322 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6323 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6324 | } finally { |
| 6325 | Binder.restoreCallingIdentity(identity); |
| 6326 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6327 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6328 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6329 | |
| 6330 | @Override |
| 6331 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6332 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6333 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6334 | |
| 6335 | final long identity = Binder.clearCallingIdentity(); |
| 6336 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6337 | ImsManager.getInstance(defaultPhone.getContext(), |
| 6338 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6339 | } finally { |
| 6340 | Binder.restoreCallingIdentity(identity); |
| 6341 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6342 | } |
| 6343 | |
| 6344 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6345 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6346 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6347 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 6348 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6349 | return false; |
| 6350 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6351 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6352 | final long identity = Binder.clearCallingIdentity(); |
| 6353 | try { |
| 6354 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 6355 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 6356 | // In the long run, we may instead need to check if there exists a connection service |
| 6357 | // which can support video calling. |
| 6358 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6359 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6360 | return imsManager.isVtEnabledByPlatform() |
| 6361 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 6362 | && imsManager.isVtEnabledByUser(); |
| 6363 | } finally { |
| 6364 | Binder.restoreCallingIdentity(identity); |
| 6365 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6366 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 6367 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6368 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6369 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 6370 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6371 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6372 | mApp, subId, callingPackage, callingFeatureId, |
| 6373 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6374 | return false; |
| 6375 | } |
| 6376 | |
| 6377 | final long identity = Binder.clearCallingIdentity(); |
| 6378 | try { |
| 6379 | CarrierConfigManager configManager = |
| 6380 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6381 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6382 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 6383 | } finally { |
| 6384 | Binder.restoreCallingIdentity(identity); |
| 6385 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6386 | } |
| 6387 | |
| 6388 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6389 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6390 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6391 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6392 | return false; |
| 6393 | } |
| 6394 | |
| 6395 | final long identity = Binder.clearCallingIdentity(); |
| 6396 | try { |
| 6397 | CarrierConfigManager configManager = |
| 6398 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6399 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6400 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 6401 | } finally { |
| 6402 | Binder.restoreCallingIdentity(identity); |
| 6403 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6404 | } |
| 6405 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6406 | @Override |
| 6407 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6408 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 6409 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6410 | } |
| 6411 | |
| 6412 | @Override |
| 6413 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6414 | final long identity = Binder.clearCallingIdentity(); |
| 6415 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6416 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6417 | } finally { |
| 6418 | Binder.restoreCallingIdentity(identity); |
| 6419 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6420 | } |
| 6421 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6422 | /** |
| 6423 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 6424 | * support for the feature and device firmware support. |
| 6425 | * |
| 6426 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 6427 | */ |
| 6428 | @Override |
| 6429 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6430 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6431 | final Phone phone = getPhone(subscriptionId); |
| 6432 | if (phone == null) { |
| 6433 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 6434 | return false; |
| 6435 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6436 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6437 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6438 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 6439 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6440 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6441 | return isCarrierSupported && isDeviceSupported; |
| 6442 | } finally { |
| 6443 | Binder.restoreCallingIdentity(identity); |
| 6444 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 6445 | } |
| 6446 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6447 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 6448 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 6449 | * RTT setting, will return true if the device and carrier both support RTT. |
| 6450 | * 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] | 6451 | */ |
| 6452 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6453 | final long identity = Binder.clearCallingIdentity(); |
| 6454 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 6455 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 6456 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 6457 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 6458 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 6459 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 6460 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6461 | } finally { |
| 6462 | Binder.restoreCallingIdentity(identity); |
| 6463 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 6464 | } |
| 6465 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6466 | @Deprecated |
| 6467 | @Override |
| 6468 | public String getDeviceId(String callingPackage) { |
| 6469 | return getDeviceIdWithFeature(callingPackage, null); |
| 6470 | } |
| 6471 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6472 | /** |
| 6473 | * Returns the unique device ID of phone, for example, the IMEI for |
| 6474 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 6475 | * |
| 6476 | * <p>Requires Permission: |
| 6477 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 6478 | */ |
| 6479 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6480 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6481 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6482 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6483 | return null; |
| 6484 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6485 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 6486 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6487 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6488 | return null; |
| 6489 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6490 | |
| 6491 | final long identity = Binder.clearCallingIdentity(); |
| 6492 | try { |
| 6493 | return phone.getDeviceId(); |
| 6494 | } finally { |
| 6495 | Binder.restoreCallingIdentity(identity); |
| 6496 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6497 | } |
| 6498 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6499 | /** |
| 6500 | * {@hide} |
| 6501 | * Returns the IMS Registration Status on a particular subid |
| 6502 | * |
| 6503 | * @param subId |
| 6504 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6505 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6506 | Phone phone = getPhone(subId); |
| 6507 | if (phone != null) { |
| 6508 | return phone.isImsRegistered(); |
| 6509 | } else { |
| 6510 | return false; |
| 6511 | } |
| 6512 | } |
| 6513 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6514 | @Override |
| 6515 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6516 | final long identity = Binder.clearCallingIdentity(); |
| 6517 | try { |
| 6518 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 6519 | } finally { |
| 6520 | Binder.restoreCallingIdentity(identity); |
| 6521 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6522 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 6523 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6524 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6525 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6526 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6527 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6528 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6529 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6530 | } |
| 6531 | final long identity = Binder.clearCallingIdentity(); |
| 6532 | try { |
| 6533 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 6534 | } finally { |
| 6535 | Binder.restoreCallingIdentity(identity); |
| 6536 | } |
| 6537 | } |
| 6538 | |
| 6539 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6540 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 6541 | final long identity = Binder.clearCallingIdentity(); |
| 6542 | try { |
| 6543 | Phone phone = getPhone(subscriptionId); |
| 6544 | if (phone == null) { |
| 6545 | return null; |
| 6546 | } |
| 6547 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 6548 | } finally { |
| 6549 | Binder.restoreCallingIdentity(identity); |
| 6550 | } |
| 6551 | } |
| 6552 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6553 | /** |
| 6554 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6555 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6556 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6557 | final long identity = Binder.clearCallingIdentity(); |
| 6558 | try { |
| 6559 | Phone phone = getPhone(subId); |
| 6560 | if (phone != null) { |
| 6561 | return phone.isWifiCallingEnabled(); |
| 6562 | } else { |
| 6563 | return false; |
| 6564 | } |
| 6565 | } finally { |
| 6566 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6567 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6568 | } |
| 6569 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6570 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6571 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6572 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6573 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6574 | final long identity = Binder.clearCallingIdentity(); |
| 6575 | try { |
| 6576 | Phone phone = getPhone(subId); |
| 6577 | if (phone != null) { |
| 6578 | return phone.isVideoEnabled(); |
| 6579 | } else { |
| 6580 | return false; |
| 6581 | } |
| 6582 | } finally { |
| 6583 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6584 | } |
| 6585 | } |
| 6586 | |
| 6587 | /** |
| 6588 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 6589 | * defined in {@link ImsRegistrationImplBase}. |
| 6590 | */ |
| 6591 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6592 | final long identity = Binder.clearCallingIdentity(); |
| 6593 | try { |
| 6594 | Phone phone = getPhone(subId); |
| 6595 | if (phone != null) { |
| 6596 | return phone.getImsRegistrationTech(); |
| 6597 | } else { |
| 6598 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 6599 | } |
| 6600 | } finally { |
| 6601 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6602 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6603 | } |
| 6604 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6605 | @Override |
| 6606 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 6607 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6608 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 6609 | return; |
| 6610 | } |
| 6611 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6612 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6613 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6614 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6615 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 6616 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6617 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6618 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6619 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6620 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 6621 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6622 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6623 | // There has been issues when Sms raw table somehow stores orphan |
| 6624 | // fragments. They lead to garbled message when new fragments come |
| 6625 | // in and combined with those stale ones. In case this happens again, |
| 6626 | // user can reset all network settings which will clean up this table. |
| 6627 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6628 | // Clean up IMS settings as well here. |
| 6629 | int slotId = getSlotIndex(subId); |
| 6630 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6631 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 6632 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 6633 | |
| 6634 | // Erase modem config if erase modem on network setting is enabled. |
| 6635 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 6636 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 6637 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 6638 | sendEraseModemConfig(getDefaultPhone()); |
| 6639 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6640 | } finally { |
| 6641 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6642 | } |
| 6643 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6644 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6645 | private void cleanUpSmsRawTable(Context context) { |
| 6646 | ContentResolver resolver = context.getContentResolver(); |
| 6647 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 6648 | resolver.delete(uri, null, null); |
| 6649 | } |
| 6650 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6651 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6652 | public String getSimLocaleForSubscriber(int subId) { |
| 6653 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 6654 | final Phone phone = getPhone(subId); |
| 6655 | if (phone == null) { |
| 6656 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 6657 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6658 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6659 | final long identity = Binder.clearCallingIdentity(); |
| 6660 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6661 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6662 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 6663 | if (info == null) { |
| 6664 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 6665 | return null; |
| 6666 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6667 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 6668 | // preferences (EF-PL and EF-LI)... |
| 6669 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6670 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6671 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 6672 | if (localeFromDefaultSim != null) { |
| 6673 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 6674 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 6675 | + localeFromDefaultSim); |
| 6676 | return localeFromDefaultSim.toLanguageTag(); |
| 6677 | } else { |
| 6678 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6679 | } |
| 6680 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6681 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6682 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 6683 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 6684 | // the SIM and carrier preferences does not include a country we add the country |
| 6685 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 6686 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6687 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6688 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6689 | return mccLocale.toLanguageTag(); |
| 6690 | } |
| 6691 | |
| 6692 | if (DBG) log("No locale found - returning null"); |
| 6693 | return null; |
| 6694 | } finally { |
| 6695 | Binder.restoreCallingIdentity(identity); |
| 6696 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6697 | } |
| 6698 | |
| 6699 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6700 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6701 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6702 | } |
| 6703 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6704 | /** |
| 6705 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 6706 | */ |
| 6707 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6708 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6709 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6710 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6711 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6712 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6713 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6714 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6715 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6716 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 6717 | * representing the state of the modem. |
| 6718 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6719 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 6720 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6721 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6722 | */ |
| 6723 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6724 | public void requestModemActivityInfo(ResultReceiver result) { |
| 6725 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6726 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6727 | |
| 6728 | final long identity = Binder.clearCallingIdentity(); |
| 6729 | try { |
Shuo Qian | 1d931ee | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 6730 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6731 | } finally { |
| 6732 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6733 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6734 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6735 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6736 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 6737 | // less than total activity duration. |
| 6738 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 6739 | if (info == null) { |
| 6740 | return false; |
| 6741 | } |
| 6742 | int activityDurationMs = |
| 6743 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 6744 | int totalTxTimeMs = 0; |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6745 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6746 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 6747 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6748 | } |
| 6749 | return (info.isValid() |
| 6750 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 6751 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6752 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6753 | && (totalTxTimeMs <= activityDurationMs)); |
| 6754 | } |
| 6755 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6756 | /** |
| 6757 | * {@hide} |
| 6758 | * Returns the service state information on specified subscription. |
| 6759 | */ |
| 6760 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6761 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 6762 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6763 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6764 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6765 | return null; |
| 6766 | } |
| 6767 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6768 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 6769 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6770 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6771 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6772 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6773 | .setCallingPid(Binder.getCallingPid()) |
| 6774 | .setCallingUid(Binder.getCallingUid()) |
| 6775 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6776 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6777 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6778 | .build()); |
| 6779 | |
| 6780 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 6781 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6782 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6783 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6784 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6785 | .setCallingPid(Binder.getCallingPid()) |
| 6786 | .setCallingUid(Binder.getCallingUid()) |
| 6787 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6788 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6789 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6790 | .build()); |
| 6791 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 6792 | boolean hasFinePermission = |
| 6793 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6794 | boolean hasCoarsePermission = |
| 6795 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6796 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6797 | final long identity = Binder.clearCallingIdentity(); |
| 6798 | try { |
| 6799 | final Phone phone = getPhone(subId); |
| 6800 | if (phone == null) { |
| 6801 | return null; |
| 6802 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6803 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6804 | ServiceState ss = phone.getServiceState(); |
| 6805 | |
| 6806 | // Scrub out the location info in ServiceState depending on what level of access |
| 6807 | // the caller has. |
| 6808 | if (hasFinePermission) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 6809 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 6810 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6811 | } finally { |
| 6812 | Binder.restoreCallingIdentity(identity); |
| 6813 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6814 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6815 | |
| 6816 | /** |
| 6817 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 6818 | * |
| 6819 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6820 | * voicemail ringtone. |
| 6821 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 6822 | * PhoneAccount. |
| 6823 | */ |
| 6824 | @Override |
| 6825 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6826 | final long identity = Binder.clearCallingIdentity(); |
| 6827 | try { |
| 6828 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6829 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6830 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6831 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6832 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6833 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 6834 | } finally { |
| 6835 | Binder.restoreCallingIdentity(identity); |
| 6836 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6837 | } |
| 6838 | |
| 6839 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6840 | * Sets the per-account voicemail ringtone. |
| 6841 | * |
| 6842 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6843 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6844 | * |
| 6845 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6846 | * voicemail ringtone. |
| 6847 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 6848 | * PhoneAccount. |
| 6849 | */ |
| 6850 | @Override |
| 6851 | public void setVoicemailRingtoneUri(String callingPackage, |
| 6852 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6853 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6854 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6855 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6856 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6857 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6858 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6859 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6860 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6861 | |
| 6862 | final long identity = Binder.clearCallingIdentity(); |
| 6863 | try { |
| 6864 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6865 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6866 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6867 | } |
| 6868 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 6869 | } finally { |
| 6870 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6871 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6872 | } |
| 6873 | |
| 6874 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6875 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 6876 | * |
| 6877 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6878 | * voicemail vibration setting. |
| 6879 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 6880 | */ |
| 6881 | @Override |
| 6882 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6883 | final long identity = Binder.clearCallingIdentity(); |
| 6884 | try { |
| 6885 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6886 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6887 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6888 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6889 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6890 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 6891 | } finally { |
| 6892 | Binder.restoreCallingIdentity(identity); |
| 6893 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6894 | } |
| 6895 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6896 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6897 | * Sets the per-account voicemail vibration. |
| 6898 | * |
| 6899 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6900 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6901 | * |
| 6902 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6903 | * voicemail vibration setting. |
| 6904 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 6905 | * specific PhoneAccount. |
| 6906 | */ |
| 6907 | @Override |
| 6908 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 6909 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6910 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6911 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6912 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6913 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6914 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6915 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6916 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6917 | } |
| 6918 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6919 | final long identity = Binder.clearCallingIdentity(); |
| 6920 | try { |
| 6921 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6922 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6923 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6924 | } |
| 6925 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 6926 | } finally { |
| 6927 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6928 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6929 | } |
| 6930 | |
| 6931 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6932 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 6933 | * |
| 6934 | * @throws SecurityException if the caller does not have the required permission |
| 6935 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6936 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6937 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6938 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6939 | } |
| 6940 | |
| 6941 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6942 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 6943 | * permission. |
| 6944 | * |
| 6945 | * @throws SecurityException if the caller does not have the required permission |
| 6946 | */ |
| 6947 | private void enforceSendSmsPermission() { |
| 6948 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 6949 | } |
| 6950 | |
| 6951 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6952 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6953 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6954 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6955 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6956 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6957 | final long identity = Binder.clearCallingIdentity(); |
| 6958 | try { |
| 6959 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6960 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6961 | if (componentName == null) { |
| 6962 | throw new SecurityException( |
| 6963 | "Caller not current active visual voicemail package[null]"); |
| 6964 | } |
| 6965 | String vvmPackage = componentName.getPackageName(); |
| 6966 | if (!callingPackage.equals(vvmPackage)) { |
| 6967 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 6968 | + vvmPackage + "]"); |
| 6969 | } |
| 6970 | } finally { |
| 6971 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6972 | } |
| 6973 | } |
| 6974 | |
| 6975 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6976 | * Return the application ID for the app type. |
| 6977 | * |
| 6978 | * @param subId the subscription ID that this request applies to. |
| 6979 | * @param appType the uicc app type. |
| 6980 | * @return Application ID for specificied app type, or null if no uicc. |
| 6981 | */ |
| 6982 | @Override |
| 6983 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6984 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6985 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6986 | |
| 6987 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6988 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6989 | if (phone == null) { |
| 6990 | return null; |
| 6991 | } |
| 6992 | String aid = null; |
| 6993 | try { |
| 6994 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 6995 | .getApplicationByType(appType).getAid(); |
| 6996 | } catch (Exception e) { |
| 6997 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 6998 | } |
| 6999 | return aid; |
| 7000 | } finally { |
| 7001 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7002 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7003 | } |
| 7004 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7005 | /** |
| 7006 | * Return the Electronic Serial Number. |
| 7007 | * |
| 7008 | * @param subId the subscription ID that this request applies to. |
| 7009 | * @return ESN or null if error. |
| 7010 | */ |
| 7011 | @Override |
| 7012 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7013 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7014 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7015 | |
| 7016 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7017 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7018 | if (phone == null) { |
| 7019 | return null; |
| 7020 | } |
| 7021 | String esn = null; |
| 7022 | try { |
| 7023 | esn = phone.getEsn(); |
| 7024 | } catch (Exception e) { |
| 7025 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 7026 | } |
| 7027 | return esn; |
| 7028 | } finally { |
| 7029 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7030 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7031 | } |
| 7032 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7033 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7034 | * Return the Preferred Roaming List Version. |
| 7035 | * |
| 7036 | * @param subId the subscription ID that this request applies to. |
| 7037 | * @return PRLVersion or null if error. |
| 7038 | */ |
| 7039 | @Override |
| 7040 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7041 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7042 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7043 | |
| 7044 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7045 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7046 | if (phone == null) { |
| 7047 | return null; |
| 7048 | } |
| 7049 | String cdmaPrlVersion = null; |
| 7050 | try { |
| 7051 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7052 | } catch (Exception e) { |
| 7053 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7054 | } |
| 7055 | return cdmaPrlVersion; |
| 7056 | } finally { |
| 7057 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7058 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7059 | } |
| 7060 | |
| 7061 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7062 | * Get snapshot of Telephony histograms |
| 7063 | * @return List of Telephony histograms |
| 7064 | * @hide |
| 7065 | */ |
| 7066 | @Override |
| 7067 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7068 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7069 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7070 | |
| 7071 | final long identity = Binder.clearCallingIdentity(); |
| 7072 | try { |
| 7073 | return RIL.getTelephonyRILTimingHistograms(); |
| 7074 | } finally { |
| 7075 | Binder.restoreCallingIdentity(identity); |
| 7076 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7077 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7078 | |
| 7079 | /** |
| 7080 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7081 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7082 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7083 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7084 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7085 | * @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] | 7086 | */ |
| 7087 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7088 | @TelephonyManager.SetCarrierRestrictionResult |
| 7089 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7090 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7091 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7092 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7093 | if (carrierRestrictionRules == null) { |
| 7094 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7095 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7096 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7097 | final long identity = Binder.clearCallingIdentity(); |
| 7098 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7099 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7100 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7101 | } finally { |
| 7102 | Binder.restoreCallingIdentity(identity); |
| 7103 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7104 | } |
| 7105 | |
| 7106 | /** |
| 7107 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7108 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7109 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7110 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7111 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7112 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7113 | */ |
| 7114 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7115 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7116 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7117 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7118 | |
| 7119 | final long identity = Binder.clearCallingIdentity(); |
| 7120 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7121 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7122 | if (response instanceof CarrierRestrictionRules) { |
| 7123 | return (CarrierRestrictionRules) response; |
| 7124 | } |
| 7125 | // Response is an Exception of some kind, |
| 7126 | // which is signalled to the user as a NULL retval |
| 7127 | return null; |
| 7128 | } catch (Exception e) { |
| 7129 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7130 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7131 | } finally { |
| 7132 | Binder.restoreCallingIdentity(identity); |
| 7133 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7134 | } |
| 7135 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7136 | /** |
| 7137 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 7138 | * @param subId the subscription ID that this action applies to. |
| 7139 | * @param enabled control enable or disable metered apns. |
| 7140 | * {@hide} |
| 7141 | */ |
| 7142 | @Override |
| 7143 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 7144 | enforceModifyPermission(); |
| 7145 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7146 | |
| 7147 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7148 | if (phone == null) { |
| 7149 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 7150 | return; |
| 7151 | } |
| 7152 | try { |
| 7153 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7154 | } catch (Exception e) { |
| 7155 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7156 | } finally { |
| 7157 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7158 | } |
| 7159 | } |
| 7160 | |
| 7161 | /** |
| 7162 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7163 | * @param subId the subscription ID that this action applies to. |
| 7164 | * @param enabled control enable or disable radio. |
| 7165 | * {@hide} |
| 7166 | */ |
| 7167 | @Override |
| 7168 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7169 | enforceModifyPermission(); |
| 7170 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7171 | |
| 7172 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7173 | if (phone == null) { |
| 7174 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7175 | return; |
| 7176 | } |
| 7177 | try { |
| 7178 | phone.carrierActionSetRadioEnabled(enabled); |
| 7179 | } catch (Exception e) { |
| 7180 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7181 | } finally { |
| 7182 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7183 | } |
| 7184 | } |
| 7185 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7186 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7187 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7188 | * network status based on which carrier apps could apply actions accordingly, |
| 7189 | * enable/disable default url handler for example. |
| 7190 | * |
| 7191 | * @param subId the subscription ID that this action applies to. |
| 7192 | * @param report control start/stop reporting the default network status. |
| 7193 | * {@hide} |
| 7194 | */ |
| 7195 | @Override |
| 7196 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7197 | enforceModifyPermission(); |
| 7198 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7199 | |
| 7200 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7201 | if (phone == null) { |
| 7202 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7203 | return; |
| 7204 | } |
| 7205 | try { |
| 7206 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7207 | } catch (Exception e) { |
| 7208 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7209 | } finally { |
| 7210 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7211 | } |
| 7212 | } |
| 7213 | |
| 7214 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7215 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7216 | * @param subId the subscription ID that this action applies to. |
| 7217 | * {@hide} |
| 7218 | */ |
| 7219 | @Override |
| 7220 | public void carrierActionResetAll(int subId) { |
| 7221 | enforceModifyPermission(); |
| 7222 | final Phone phone = getPhone(subId); |
| 7223 | if (phone == null) { |
| 7224 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7225 | return; |
| 7226 | } |
| 7227 | try { |
| 7228 | phone.carrierActionResetAll(); |
| 7229 | } catch (Exception e) { |
| 7230 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7231 | } |
| 7232 | } |
| 7233 | |
| 7234 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7235 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7236 | * bug report is being generated. |
| 7237 | */ |
| 7238 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7239 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7240 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7241 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7242 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7243 | + Binder.getCallingPid() |
| 7244 | + ", uid=" + Binder.getCallingUid() |
| 7245 | + "without permission " |
| 7246 | + android.Manifest.permission.DUMP); |
| 7247 | return; |
| 7248 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7249 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7250 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7251 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7252 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 7253 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 7254 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 7255 | @NonNull String[] args) { |
| 7256 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 7257 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 7258 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7259 | } |
| 7260 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7261 | /** |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7262 | * Policy control of data connection. Usually used when data limit is passed. |
| 7263 | * @param enabled True if enabling the data, otherwise disabling. |
| 7264 | * @param subId Subscription index |
| 7265 | * {@hide} |
| 7266 | */ |
| 7267 | @Override |
| 7268 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 7269 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7270 | |
| 7271 | final long identity = Binder.clearCallingIdentity(); |
| 7272 | try { |
| 7273 | Phone phone = getPhone(subId); |
| 7274 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 7275 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7276 | } |
| 7277 | } finally { |
| 7278 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7279 | } |
| 7280 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7281 | |
| 7282 | /** |
| 7283 | * Get Client request stats |
| 7284 | * @return List of Client Request Stats |
| 7285 | * @hide |
| 7286 | */ |
| 7287 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7288 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7289 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7290 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7291 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7292 | return null; |
| 7293 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7294 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7295 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7296 | final long identity = Binder.clearCallingIdentity(); |
| 7297 | try { |
| 7298 | if (phone != null) { |
| 7299 | return phone.getClientRequestStats(); |
| 7300 | } |
| 7301 | |
| 7302 | return null; |
| 7303 | } finally { |
| 7304 | Binder.restoreCallingIdentity(identity); |
| 7305 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7306 | } |
| 7307 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7308 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7309 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7310 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7311 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7312 | |
| 7313 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7314 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7315 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7316 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7317 | * @param state State of SIM (power down, power up, pass through) |
| 7318 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7319 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7320 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7321 | * |
| 7322 | **/ |
| 7323 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7324 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7325 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7326 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7327 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7328 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7329 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7330 | final long identity = Binder.clearCallingIdentity(); |
| 7331 | try { |
| 7332 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7333 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7334 | } |
| 7335 | } finally { |
| 7336 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7337 | } |
| 7338 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7339 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7340 | private boolean isUssdApiAllowed(int subId) { |
| 7341 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7342 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7343 | if (configManager == null) { |
| 7344 | return false; |
| 7345 | } |
| 7346 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 7347 | if (pb == null) { |
| 7348 | return false; |
| 7349 | } |
| 7350 | return pb.getBoolean( |
| 7351 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 7352 | } |
| 7353 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7354 | /** |
| 7355 | * Check if phone is in emergency callback mode |
| 7356 | * @return true if phone is in emergency callback mode |
| 7357 | * @param subId sub id |
| 7358 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 7359 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7360 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7361 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7362 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7363 | |
| 7364 | final long identity = Binder.clearCallingIdentity(); |
| 7365 | try { |
| 7366 | if (phone != null) { |
| 7367 | return phone.isInEcm(); |
| 7368 | } else { |
| 7369 | return false; |
| 7370 | } |
| 7371 | } finally { |
| 7372 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7373 | } |
| 7374 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7375 | |
| 7376 | /** |
| 7377 | * Get the current signal strength information for the given subscription. |
| 7378 | * Because this information is not updated when the device is in a low power state |
| 7379 | * it should not be relied-upon to be current. |
| 7380 | * @param subId Subscription index |
| 7381 | * @return the most recent cached signal strength info from the modem |
| 7382 | */ |
| 7383 | @Override |
| 7384 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7385 | final long identity = Binder.clearCallingIdentity(); |
| 7386 | try { |
| 7387 | Phone p = getPhone(subId); |
| 7388 | if (p == null) { |
| 7389 | return null; |
| 7390 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7391 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7392 | return p.getSignalStrength(); |
| 7393 | } finally { |
| 7394 | Binder.restoreCallingIdentity(identity); |
| 7395 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7396 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7397 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7398 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7399 | * Get the current modem radio state for the given slot. |
| 7400 | * @param slotIndex slot index. |
| 7401 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7402 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7403 | * @return the current radio power state from the modem |
| 7404 | */ |
| 7405 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7406 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7407 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7408 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7409 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 7410 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7411 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7412 | } |
| 7413 | |
| 7414 | final long identity = Binder.clearCallingIdentity(); |
| 7415 | try { |
| 7416 | return phone.getRadioPowerState(); |
| 7417 | } finally { |
| 7418 | Binder.restoreCallingIdentity(identity); |
| 7419 | } |
| 7420 | } |
| 7421 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7422 | } |
| 7423 | |
| 7424 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7425 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 7426 | * |
| 7427 | * <p>Requires one of the following permissions: |
| 7428 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 7429 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 7430 | * privileges. |
| 7431 | * |
| 7432 | * @param subId subscription id |
| 7433 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 7434 | * {@code false}. |
| 7435 | */ |
| 7436 | @Override |
| 7437 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7438 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7439 | null /* message */); |
| 7440 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7441 | boolean isEnabled = false; |
| 7442 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7443 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7444 | Phone phone = getPhone(subId); |
| 7445 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7446 | } catch (Exception e) { |
| 7447 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 7448 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7449 | } finally { |
| 7450 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7451 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7452 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7453 | } |
| 7454 | |
| 7455 | |
| 7456 | /** |
| 7457 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 7458 | * |
| 7459 | * <p> Requires permission: |
| 7460 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 7461 | * privileges. |
| 7462 | * |
| 7463 | * @param subId subscription id |
| 7464 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 7465 | */ |
| 7466 | @Override |
| 7467 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7468 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7469 | mApp, subId, "setDataRoamingEnabled"); |
| 7470 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7471 | final long identity = Binder.clearCallingIdentity(); |
| 7472 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7473 | Phone phone = getPhone(subId); |
| 7474 | if (phone != null) { |
| 7475 | phone.setDataRoamingEnabled(isEnabled); |
| 7476 | } |
| 7477 | } finally { |
| 7478 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7479 | } |
| 7480 | } |
| 7481 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7482 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7483 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 7484 | TelephonyPermissions |
| 7485 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7486 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 7487 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7488 | boolean isAllowed = true; |
| 7489 | final long identity = Binder.clearCallingIdentity(); |
| 7490 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7491 | Phone phone = getPhone(subId); |
| 7492 | if (phone != null) { |
| 7493 | isAllowed = phone.isCspPlmnEnabled(); |
| 7494 | } |
| 7495 | } finally { |
| 7496 | Binder.restoreCallingIdentity(identity); |
| 7497 | } |
| 7498 | return isAllowed; |
| 7499 | } |
| 7500 | |
| 7501 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7502 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 7503 | // Verify that tha callingPackage belongs to the calling UID |
| 7504 | mApp.getSystemService(AppOpsManager.class) |
| 7505 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 7506 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7507 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7508 | try { |
| 7509 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7510 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7511 | } catch (SecurityException e) { |
| 7512 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 7513 | // has carrier privileges on an active UICC |
| 7514 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 7515 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7516 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7517 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7518 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7519 | |
| 7520 | final long identity = Binder.clearCallingIdentity(); |
| 7521 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7522 | UiccController uiccController = UiccController.getInstance(); |
| 7523 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7524 | if (hasReadPermission) { |
| 7525 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7526 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7527 | |
| 7528 | // Remove private info if the caller doesn't have access |
| 7529 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 7530 | for (UiccCardInfo cardInfo : cardInfos) { |
| 7531 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 7532 | // is available |
| 7533 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 7534 | if (card == null || card.getUiccProfile() == null) { |
| 7535 | // assume no access if the card or profile is unavailable |
| 7536 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7537 | continue; |
| 7538 | } |
| 7539 | UiccProfile profile = card.getUiccProfile(); |
| 7540 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 7541 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7542 | filteredInfos.add(cardInfo); |
| 7543 | } else { |
| 7544 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7545 | } |
| 7546 | } |
| 7547 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7548 | } finally { |
| 7549 | Binder.restoreCallingIdentity(identity); |
| 7550 | } |
| 7551 | } |
| 7552 | |
| 7553 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7554 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7555 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7556 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7557 | final long identity = Binder.clearCallingIdentity(); |
| 7558 | try { |
| 7559 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 7560 | if (slots == null) { |
| 7561 | Rlog.i(LOG_TAG, "slots is null."); |
| 7562 | return null; |
| 7563 | } |
| 7564 | |
| 7565 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 7566 | for (int i = 0; i < slots.length; i++) { |
| 7567 | UiccSlot slot = slots[i]; |
| 7568 | if (slot == null) { |
| 7569 | continue; |
| 7570 | } |
| 7571 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7572 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7573 | UiccCard card = slot.getUiccCard(); |
| 7574 | if (card != null) { |
| 7575 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7576 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 7577 | cardId = slot.getEid(); |
| 7578 | if (TextUtils.isEmpty(cardId)) { |
| 7579 | cardId = slot.getIccId(); |
| 7580 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7581 | } |
| 7582 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 7583 | if (cardId != null) { |
| 7584 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 7585 | // if cardId is an EID, it's all digits so this is fine |
| 7586 | cardId = IccUtils.stripTrailingFs(cardId); |
| 7587 | } |
| 7588 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7589 | int cardState = 0; |
| 7590 | switch (slot.getCardState()) { |
| 7591 | case CARDSTATE_ABSENT: |
| 7592 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 7593 | break; |
| 7594 | case CARDSTATE_PRESENT: |
| 7595 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 7596 | break; |
| 7597 | case CARDSTATE_ERROR: |
| 7598 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 7599 | break; |
| 7600 | case CARDSTATE_RESTRICTED: |
| 7601 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 7602 | break; |
| 7603 | default: |
| 7604 | break; |
| 7605 | |
| 7606 | } |
| 7607 | |
| 7608 | infos[i] = new UiccSlotInfo( |
| 7609 | slot.isActive(), |
| 7610 | slot.isEuicc(), |
| 7611 | cardId, |
| 7612 | cardState, |
| 7613 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 7614 | slot.isExtendedApduSupported(), |
| 7615 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7616 | } |
| 7617 | return infos; |
| 7618 | } finally { |
| 7619 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 7620 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7621 | } |
| 7622 | |
| 7623 | @Override |
| 7624 | public boolean switchSlots(int[] physicalSlots) { |
| 7625 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7626 | |
| 7627 | final long identity = Binder.clearCallingIdentity(); |
| 7628 | try { |
| 7629 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 7630 | } finally { |
| 7631 | Binder.restoreCallingIdentity(identity); |
| 7632 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7633 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7634 | |
| 7635 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7636 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7637 | final long identity = Binder.clearCallingIdentity(); |
| 7638 | try { |
| 7639 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 7640 | } finally { |
| 7641 | Binder.restoreCallingIdentity(identity); |
| 7642 | } |
| 7643 | } |
| 7644 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7645 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 7646 | * A test API to reload the UICC profile. |
| 7647 | * |
| 7648 | * <p>Requires that the calling app has permission |
| 7649 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7650 | * @hide |
| 7651 | */ |
| 7652 | @Override |
| 7653 | public void refreshUiccProfile(int subId) { |
| 7654 | enforceModifyPermission(); |
| 7655 | |
| 7656 | final long identity = Binder.clearCallingIdentity(); |
| 7657 | try { |
| 7658 | Phone phone = getPhone(subId); |
| 7659 | if (phone == null) { |
| 7660 | return; |
| 7661 | } |
| 7662 | UiccCard uiccCard = phone.getUiccCard(); |
| 7663 | if (uiccCard == null) { |
| 7664 | return; |
| 7665 | } |
| 7666 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7667 | if (uiccProfile == null) { |
| 7668 | return; |
| 7669 | } |
| 7670 | uiccProfile.refresh(); |
| 7671 | } finally { |
| 7672 | Binder.restoreCallingIdentity(identity); |
| 7673 | } |
| 7674 | } |
| 7675 | |
| 7676 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7677 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 7678 | */ |
| 7679 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7680 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7681 | } |
| 7682 | |
| 7683 | /** |
| 7684 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 7685 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 7686 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 7687 | */ |
| 7688 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 7689 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7690 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7691 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7692 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 7693 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 7694 | return isDataRoamingEnabled; |
| 7695 | } |
| 7696 | |
| 7697 | /** |
| 7698 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 7699 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 7700 | */ |
| 7701 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7702 | List<Integer> list = TelephonyProperties.default_network(); |
| 7703 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 7704 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 7705 | return list.get(phoneId); |
| 7706 | } |
| 7707 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7708 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7709 | |
| 7710 | @Override |
| 7711 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7712 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7713 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7714 | |
| 7715 | final long identity = Binder.clearCallingIdentity(); |
| 7716 | try { |
| 7717 | final Phone phone = getPhone(subId); |
| 7718 | if (phone == null) { |
| 7719 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 7720 | return; |
| 7721 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7722 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 7723 | carrierPrivilegeRules, apn); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7724 | } finally { |
| 7725 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7726 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7727 | } |
| 7728 | |
| 7729 | @Override |
| 7730 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7731 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7732 | |
| 7733 | final long identity = Binder.clearCallingIdentity(); |
| 7734 | try { |
| 7735 | final Phone phone = getPhone(subId); |
| 7736 | if (phone == null) { |
| 7737 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 7738 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 7739 | } |
| 7740 | return phone.getCarrierIdListVersion(); |
| 7741 | } finally { |
| 7742 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7743 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7744 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7745 | |
| 7746 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7747 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 7748 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7749 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7750 | mApp, subId, callingPackage, callingFeatureId, |
| 7751 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7752 | return -1; |
| 7753 | } |
| 7754 | |
| 7755 | final long identity = Binder.clearCallingIdentity(); |
| 7756 | try { |
| 7757 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 7758 | } finally { |
| 7759 | Binder.restoreCallingIdentity(identity); |
| 7760 | } |
| 7761 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7762 | |
| 7763 | @Override |
| 7764 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 7765 | TelephonyPermissions |
| 7766 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7767 | mApp, subId, "getCdmaRoamingMode"); |
| 7768 | |
| 7769 | final long identity = Binder.clearCallingIdentity(); |
| 7770 | try { |
| 7771 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 7772 | } finally { |
| 7773 | Binder.restoreCallingIdentity(identity); |
| 7774 | } |
| 7775 | } |
| 7776 | |
| 7777 | @Override |
| 7778 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 7779 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7780 | mApp, subId, "setCdmaRoamingMode"); |
| 7781 | |
| 7782 | final long identity = Binder.clearCallingIdentity(); |
| 7783 | try { |
| 7784 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 7785 | } finally { |
| 7786 | Binder.restoreCallingIdentity(identity); |
| 7787 | } |
| 7788 | } |
| 7789 | |
| 7790 | @Override |
| 7791 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 7792 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7793 | mApp, subId, "setCdmaSubscriptionMode"); |
| 7794 | |
| 7795 | final long identity = Binder.clearCallingIdentity(); |
| 7796 | try { |
| 7797 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 7798 | } finally { |
| 7799 | Binder.restoreCallingIdentity(identity); |
| 7800 | } |
| 7801 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 7802 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7803 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7804 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7805 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7806 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7807 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 7808 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7809 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7810 | } |
| 7811 | final long identity = Binder.clearCallingIdentity(); |
| 7812 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7813 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 7814 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7815 | if (phone.getEmergencyNumberTracker() != null |
| 7816 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 7817 | emergencyNumberListInternal.put( |
| 7818 | phone.getSubId(), |
| 7819 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 7820 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7821 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7822 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7823 | } finally { |
| 7824 | Binder.restoreCallingIdentity(identity); |
| 7825 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7826 | } |
| 7827 | |
| 7828 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7829 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7830 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7831 | if (!exactMatch) { |
| 7832 | TelephonyPermissions |
| 7833 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7834 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7835 | } |
| 7836 | final long identity = Binder.clearCallingIdentity(); |
| 7837 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7838 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7839 | if (phone.getEmergencyNumberTracker() != null |
| 7840 | && phone.getEmergencyNumberTracker() != null) { |
| 7841 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 7842 | number, exactMatch)) { |
| 7843 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7844 | } |
| 7845 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7846 | } |
| 7847 | return false; |
| 7848 | } finally { |
| 7849 | Binder.restoreCallingIdentity(identity); |
| 7850 | } |
| 7851 | } |
| 7852 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 7853 | /** |
| 7854 | * Update emergency number list for test mode. |
| 7855 | */ |
| 7856 | @Override |
| 7857 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 7858 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7859 | "updateEmergencyNumberListTestMode"); |
| 7860 | |
| 7861 | final long identity = Binder.clearCallingIdentity(); |
| 7862 | try { |
| 7863 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7864 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7865 | if (tracker != null) { |
| 7866 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 7867 | } |
| 7868 | } |
| 7869 | } finally { |
| 7870 | Binder.restoreCallingIdentity(identity); |
| 7871 | } |
| 7872 | } |
| 7873 | |
| 7874 | /** |
| 7875 | * Get the full emergency number list for test mode. |
| 7876 | */ |
| 7877 | @Override |
| 7878 | public List<String> getEmergencyNumberListTestMode() { |
| 7879 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7880 | "getEmergencyNumberListTestMode"); |
| 7881 | |
| 7882 | final long identity = Binder.clearCallingIdentity(); |
| 7883 | try { |
| 7884 | Set<String> emergencyNumbers = new HashSet<>(); |
| 7885 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7886 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7887 | if (tracker != null) { |
| 7888 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 7889 | emergencyNumbers.add(num.getNumber()); |
| 7890 | } |
| 7891 | } |
| 7892 | } |
| 7893 | return new ArrayList<>(emergencyNumbers); |
| 7894 | } finally { |
| 7895 | Binder.restoreCallingIdentity(identity); |
| 7896 | } |
| 7897 | } |
| 7898 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7899 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7900 | public int getEmergencyNumberDbVersion(int subId) { |
| 7901 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 7902 | |
| 7903 | final long identity = Binder.clearCallingIdentity(); |
| 7904 | try { |
| 7905 | final Phone phone = getPhone(subId); |
| 7906 | if (phone == null) { |
| 7907 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 7908 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 7909 | } |
| 7910 | return phone.getEmergencyNumberDbVersion(); |
| 7911 | } finally { |
| 7912 | Binder.restoreCallingIdentity(identity); |
| 7913 | } |
| 7914 | } |
| 7915 | |
| 7916 | @Override |
| 7917 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 7918 | enforceModifyPermission(); |
| 7919 | |
| 7920 | final long identity = Binder.clearCallingIdentity(); |
| 7921 | try { |
| 7922 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7923 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7924 | if (tracker != null) { |
| 7925 | tracker.updateOtaEmergencyNumberDatabase(); |
| 7926 | } |
| 7927 | } |
| 7928 | } finally { |
| 7929 | Binder.restoreCallingIdentity(identity); |
| 7930 | } |
| 7931 | } |
| 7932 | |
| 7933 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 7934 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7935 | enforceActiveEmergencySessionPermission(); |
| 7936 | |
| 7937 | final long identity = Binder.clearCallingIdentity(); |
| 7938 | try { |
| 7939 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7940 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7941 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 7942 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 7943 | } |
| 7944 | } |
| 7945 | } finally { |
| 7946 | Binder.restoreCallingIdentity(identity); |
| 7947 | } |
| 7948 | } |
| 7949 | |
| 7950 | @Override |
| 7951 | public void resetOtaEmergencyNumberDbFilePath() { |
| 7952 | enforceActiveEmergencySessionPermission(); |
| 7953 | |
| 7954 | final long identity = Binder.clearCallingIdentity(); |
| 7955 | try { |
| 7956 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7957 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7958 | if (tracker != null) { |
| 7959 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7960 | } |
| 7961 | } |
| 7962 | } finally { |
| 7963 | Binder.restoreCallingIdentity(identity); |
| 7964 | } |
| 7965 | } |
| 7966 | |
| 7967 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7968 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 7969 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 7970 | Phone phone = getPhone(subId); |
| 7971 | if (phone == null) { |
| 7972 | return null; |
| 7973 | } |
| 7974 | final long identity = Binder.clearCallingIdentity(); |
| 7975 | try { |
| 7976 | UiccProfile profile = UiccController.getInstance() |
| 7977 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 7978 | if (profile != null) { |
| 7979 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 7980 | } |
| 7981 | } finally { |
| 7982 | Binder.restoreCallingIdentity(identity); |
| 7983 | } |
| 7984 | return null; |
| 7985 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 7986 | |
| 7987 | /** |
| 7988 | * Enable or disable a modem stack. |
| 7989 | */ |
| 7990 | @Override |
| 7991 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 7992 | enforceModifyPermission(); |
| 7993 | |
| 7994 | final long identity = Binder.clearCallingIdentity(); |
| 7995 | try { |
| 7996 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7997 | if (phone == null) { |
| 7998 | return false; |
| 7999 | } else { |
| 8000 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 8001 | } |
| 8002 | } finally { |
| 8003 | Binder.restoreCallingIdentity(identity); |
| 8004 | } |
| 8005 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8006 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8007 | /** |
| 8008 | * Whether a modem stack is enabled or not. |
| 8009 | */ |
| 8010 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8011 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 8012 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8013 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8014 | if (phone == null) return false; |
| 8015 | |
| 8016 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8017 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 8018 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8019 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8020 | } |
| 8021 | |
| 8022 | final long identity = Binder.clearCallingIdentity(); |
| 8023 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8024 | try { |
| 8025 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 8026 | } catch (NoSuchElementException ex) { |
| 8027 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 8028 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8029 | } finally { |
| 8030 | Binder.restoreCallingIdentity(identity); |
| 8031 | } |
| 8032 | } |
| 8033 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8034 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8035 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8036 | enforceModifyPermission(); |
| 8037 | |
| 8038 | final long identity = Binder.clearCallingIdentity(); |
| 8039 | try { |
| 8040 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8041 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8042 | .commit(); |
| 8043 | } finally { |
| 8044 | Binder.restoreCallingIdentity(identity); |
| 8045 | } |
| 8046 | } |
| 8047 | |
| 8048 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8049 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8050 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8051 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8052 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8053 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8054 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8055 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8056 | |
| 8057 | final long identity = Binder.clearCallingIdentity(); |
| 8058 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8059 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8060 | } finally { |
| 8061 | Binder.restoreCallingIdentity(identity); |
| 8062 | } |
| 8063 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8064 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8065 | @TelephonyManager.IsMultiSimSupportedResult |
| 8066 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8067 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8068 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8069 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8070 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8071 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8072 | } |
| 8073 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8074 | // supported by the modem, indicate that it is restricted. |
| 8075 | PhoneCapability staticCapability = |
| 8076 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8077 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8078 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8079 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8080 | } |
Sarah Chin | 7caee49 | 2020-02-18 20:49:02 +0000 | [diff] [blame] | 8081 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8082 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8083 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8084 | } |
| 8085 | // Check if support of multiple SIMs is restricted by carrier |
| 8086 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8087 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8088 | } |
| 8089 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8090 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8091 | } |
| 8092 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8093 | /** |
| 8094 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8095 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8096 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8097 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8098 | * @param numOfSims number of active sims we want to switch to |
| 8099 | */ |
| 8100 | @Override |
| 8101 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8102 | if (numOfSims == 1) { |
| 8103 | enforceModifyPermission(); |
| 8104 | } else { |
| 8105 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8106 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8107 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8108 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8109 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8110 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8111 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8112 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8113 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8114 | return; |
| 8115 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8116 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8117 | } finally { |
| 8118 | Binder.restoreCallingIdentity(identity); |
| 8119 | } |
| 8120 | } |
| 8121 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8122 | @Override |
| 8123 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8124 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8125 | Phone phone = getPhone(subId); |
| 8126 | if (phone == null) { |
| 8127 | return false; |
| 8128 | } |
| 8129 | final long identity = Binder.clearCallingIdentity(); |
| 8130 | try { |
| 8131 | UiccCard uiccCard = phone.getUiccCard(); |
| 8132 | if (uiccCard == null) { |
| 8133 | return false; |
| 8134 | } |
| 8135 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8136 | if (uiccProfile == null) { |
| 8137 | return false; |
| 8138 | } |
| 8139 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8140 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8141 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8142 | } |
| 8143 | return false; |
| 8144 | } finally { |
| 8145 | Binder.restoreCallingIdentity(identity); |
| 8146 | } |
| 8147 | } |
| 8148 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8149 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8150 | * Get whether making changes to modem configurations will trigger reboot. |
| 8151 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8152 | */ |
| 8153 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8154 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8155 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8156 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8157 | mApp, subId, callingPackage, callingFeatureId, |
| 8158 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8159 | return false; |
| 8160 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8161 | final long identity = Binder.clearCallingIdentity(); |
| 8162 | try { |
| 8163 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8164 | } finally { |
| 8165 | Binder.restoreCallingIdentity(identity); |
| 8166 | } |
| 8167 | } |
| 8168 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8169 | private void updateModemStateMetrics() { |
| 8170 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8171 | // TODO: check the state for each modem if the api is ready. |
| 8172 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8173 | } |
| 8174 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8175 | @Override |
| 8176 | public int[] getSlotsMapping() { |
| 8177 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8178 | |
| 8179 | final long identity = Binder.clearCallingIdentity(); |
| 8180 | try { |
| 8181 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8182 | // All logical slots should have a mapping to a physical slot. |
| 8183 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8184 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8185 | for (int i = 0; i < slotInfos.length; i++) { |
| 8186 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8187 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8188 | } |
| 8189 | } |
| 8190 | return logicalSlotsMapping; |
| 8191 | } finally { |
| 8192 | Binder.restoreCallingIdentity(identity); |
| 8193 | } |
| 8194 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8195 | |
| 8196 | /** |
| 8197 | * Get the IRadio HAL Version |
| 8198 | */ |
| 8199 | @Override |
| 8200 | public int getRadioHalVersion() { |
| 8201 | Phone phone = getDefaultPhone(); |
| 8202 | if (phone == null) return -1; |
| 8203 | HalVersion hv = phone.getHalVersion(); |
| 8204 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8205 | return hv.major * 100 + hv.minor; |
| 8206 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8207 | |
| 8208 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8209 | * Get the current calling package name. |
| 8210 | * @return the current calling package name |
| 8211 | */ |
| 8212 | @Override |
| 8213 | public String getCurrentPackageName() { |
| 8214 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8215 | } |
| 8216 | |
| 8217 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8218 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8219 | * corresponding network requests on a subId. |
| 8220 | * |
| 8221 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8222 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8223 | * 2) APN is un-metered for this subscription, or |
| 8224 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8225 | * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8226 | * |
| 8227 | * @return whether data is allowed for a apn type. |
| 8228 | * |
| 8229 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8230 | */ |
| 8231 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8232 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8233 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8234 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8235 | |
| 8236 | // Now that all security checks passes, perform the operation as ourselves. |
| 8237 | final long identity = Binder.clearCallingIdentity(); |
| 8238 | try { |
| 8239 | Phone phone = getPhone(subId); |
| 8240 | if (phone == null) return false; |
| 8241 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8242 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8243 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8244 | } finally { |
| 8245 | Binder.restoreCallingIdentity(identity); |
| 8246 | } |
| 8247 | } |
| 8248 | |
| 8249 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8250 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8251 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8252 | |
| 8253 | // Now that all security checks passes, perform the operation as ourselves. |
| 8254 | final long identity = Binder.clearCallingIdentity(); |
| 8255 | try { |
| 8256 | Phone phone = getPhone(subId); |
| 8257 | if (phone == null) return true; // By default return true. |
| 8258 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8259 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8260 | } finally { |
| 8261 | Binder.restoreCallingIdentity(identity); |
| 8262 | } |
| 8263 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8264 | |
| 8265 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 8266 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 8267 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 8268 | enforceModifyPermission(); |
| 8269 | long token = Binder.clearCallingIdentity(); |
| 8270 | try { |
| 8271 | Phone phone = getPhone(subscriptionId); |
| 8272 | if (phone == null) { |
| 8273 | try { |
| 8274 | if (resultCallback != null) { |
| 8275 | resultCallback.accept(false); |
| 8276 | } |
| 8277 | } catch (RemoteException e) { |
| 8278 | // ignore |
| 8279 | } |
| 8280 | return; |
| 8281 | } |
| 8282 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 8283 | Pair.create(specifiers, (x) -> { |
| 8284 | try { |
| 8285 | if (resultCallback != null) { |
| 8286 | resultCallback.accept(x); |
| 8287 | } |
| 8288 | } catch (RemoteException e) { |
| 8289 | // ignore |
| 8290 | } |
| 8291 | }); |
| 8292 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 8293 | } finally { |
| 8294 | Binder.restoreCallingIdentity(token); |
| 8295 | } |
| 8296 | } |
| 8297 | |
| 8298 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8299 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 8300 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8301 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 8302 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 8303 | if (iccRecords == null) { |
| 8304 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 8305 | return false; |
| 8306 | } |
| 8307 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 8308 | } |
| 8309 | |
| 8310 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8311 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 8312 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8313 | if (callingPackage == null) { |
| 8314 | callingPackage = getCurrentPackageName(); |
| 8315 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8316 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 8317 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8318 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 8319 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8320 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 8321 | } |
| 8322 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 8323 | Intent intent = new Intent(); |
| 8324 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 8325 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 8326 | // Bring up choose default SMS subscription dialog right now |
| 8327 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 8328 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 8329 | mApp.startActivity(intent); |
| 8330 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8331 | |
| 8332 | @Override |
| 8333 | public String getMmsUAProfUrl(int subId) { |
| 8334 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8335 | final long identity = Binder.clearCallingIdentity(); |
| 8336 | try { |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 8337 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8338 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8339 | } finally { |
| 8340 | Binder.restoreCallingIdentity(identity); |
| 8341 | } |
| 8342 | } |
| 8343 | |
| 8344 | @Override |
| 8345 | public String getMmsUserAgent(int subId) { |
| 8346 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8347 | final long identity = Binder.clearCallingIdentity(); |
| 8348 | try { |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 8349 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8350 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8351 | } finally { |
| 8352 | Binder.restoreCallingIdentity(identity); |
| 8353 | } |
| 8354 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8355 | |
| 8356 | @Override |
| 8357 | public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) { |
| 8358 | enforceModifyPermission(); |
| 8359 | |
| 8360 | // Now that all security checks passes, perform the operation as ourselves. |
| 8361 | final long identity = Binder.clearCallingIdentity(); |
| 8362 | try { |
| 8363 | Phone phone = getPhone(subId); |
| 8364 | if (phone == null) return false; |
| 8365 | |
| 8366 | return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow); |
| 8367 | } finally { |
| 8368 | Binder.restoreCallingIdentity(identity); |
| 8369 | } |
| 8370 | } |
| 8371 | |
| 8372 | @Override |
| 8373 | public boolean isDataAllowedInVoiceCall(int subId) { |
| 8374 | enforceReadPrivilegedPermission("isDataAllowedInVoiceCall"); |
| 8375 | |
| 8376 | // Now that all security checks passes, perform the operation as ourselves. |
| 8377 | final long identity = Binder.clearCallingIdentity(); |
| 8378 | try { |
| 8379 | Phone phone = getPhone(subId); |
| 8380 | if (phone == null) return false; |
| 8381 | |
| 8382 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 8383 | } finally { |
| 8384 | Binder.restoreCallingIdentity(identity); |
| 8385 | } |
| 8386 | } |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8387 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8388 | @Override |
| 8389 | public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) { |
| 8390 | enforceModifyPermission(); |
| 8391 | |
| 8392 | // Now that all security checks passes, perform the operation as ourselves. |
| 8393 | final long identity = Binder.clearCallingIdentity(); |
| 8394 | try { |
| 8395 | Phone phone = getPhone(subId); |
| 8396 | if (phone == null) return false; |
| 8397 | |
| 8398 | return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow); |
| 8399 | } finally { |
| 8400 | Binder.restoreCallingIdentity(identity); |
| 8401 | } |
| 8402 | } |
| 8403 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8404 | /** |
| 8405 | * Updates whether conference event pacakge handling is enabled. |
| 8406 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 8407 | * otherwise. |
| 8408 | */ |
| 8409 | @Override |
| 8410 | public void setCepEnabled(boolean isCepEnabled) { |
| 8411 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 8412 | |
| 8413 | final long identity = Binder.clearCallingIdentity(); |
| 8414 | try { |
| 8415 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 8416 | for (Phone phone : PhoneFactory.getPhones()) { |
| 8417 | Phone defaultPhone = phone.getImsPhone(); |
| 8418 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 8419 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 8420 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 8421 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 8422 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 8423 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 8424 | + imsPhone.getMsisdn()); |
| 8425 | } |
| 8426 | } |
| 8427 | } finally { |
| 8428 | Binder.restoreCallingIdentity(identity); |
| 8429 | } |
| 8430 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 8431 | |
| 8432 | /** |
| 8433 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 8434 | * |
| 8435 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 8436 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 8437 | * before being read. |
| 8438 | */ |
| 8439 | @Override |
| 8440 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 8441 | isCompressed) { |
| 8442 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8443 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
| 8444 | try { |
| 8445 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 8446 | if (configBinder == null) { |
| 8447 | Rlog.e(LOG_TAG, "null result for getImsConfig"); |
| 8448 | } else { |
| 8449 | configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed); |
| 8450 | } |
| 8451 | } catch (RemoteException e) { |
| 8452 | Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage()); |
| 8453 | } |
| 8454 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8455 | |
| 8456 | @Override |
| 8457 | public boolean isIccLockEnabled(int subId) { |
| 8458 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 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 && phone.getIccCard() != null) { |
| 8465 | return phone.getIccCard().getIccLockEnabled(); |
| 8466 | } else { |
| 8467 | return false; |
| 8468 | } |
| 8469 | } finally { |
| 8470 | Binder.restoreCallingIdentity(identity); |
| 8471 | } |
| 8472 | } |
| 8473 | |
| 8474 | /** |
| 8475 | * Set the ICC pin lock enabled or disabled. |
| 8476 | * |
| 8477 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 8478 | * three cases: |
| 8479 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 8480 | * successfully. |
| 8481 | * - Positive number and zero for remaining password attempts. |
| 8482 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 8483 | * |
| 8484 | */ |
| 8485 | @Override |
| 8486 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 8487 | enforceModifyPermission(); |
| 8488 | |
| 8489 | Phone phone = getPhone(subId); |
| 8490 | if (phone == null) { |
| 8491 | return 0; |
| 8492 | } |
| 8493 | // Now that all security checks passes, perform the operation as ourselves. |
| 8494 | final long identity = Binder.clearCallingIdentity(); |
| 8495 | try { |
| 8496 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 8497 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 8498 | return attemptsRemaining; |
| 8499 | |
| 8500 | } catch (Exception e) { |
| 8501 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 8502 | } finally { |
| 8503 | Binder.restoreCallingIdentity(identity); |
| 8504 | } |
| 8505 | return 0; |
| 8506 | } |
| 8507 | |
| 8508 | /** |
| 8509 | * Change the ICC password used in ICC pin lock. |
| 8510 | * |
| 8511 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 8512 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 8513 | * - Positive number and zero for remaining password attempts. |
| 8514 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 8515 | * |
| 8516 | */ |
| 8517 | @Override |
| 8518 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 8519 | enforceModifyPermission(); |
| 8520 | |
| 8521 | Phone phone = getPhone(subId); |
| 8522 | if (phone == null) { |
| 8523 | return 0; |
| 8524 | } |
| 8525 | // Now that all security checks passes, perform the operation as ourselves. |
| 8526 | final long identity = Binder.clearCallingIdentity(); |
| 8527 | try { |
| 8528 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 8529 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 8530 | return attemptsRemaining; |
| 8531 | |
| 8532 | } catch (Exception e) { |
| 8533 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 8534 | } finally { |
| 8535 | Binder.restoreCallingIdentity(identity); |
| 8536 | } |
| 8537 | return 0; |
| 8538 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 8539 | |
| 8540 | /** |
| 8541 | * Request for receiving user activity notification |
| 8542 | */ |
| 8543 | @Override |
| 8544 | public void requestUserActivityNotification() { |
| 8545 | if (!mNotifyUserActivity.get() |
| 8546 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 8547 | mNotifyUserActivity.set(true); |
| 8548 | } |
| 8549 | } |
| 8550 | |
| 8551 | /** |
| 8552 | * Called when userActivity is signalled in the power manager. |
| 8553 | * This is safe to call from any thread, with any window manager locks held or not. |
| 8554 | */ |
| 8555 | @Override |
| 8556 | public void userActivity() { |
| 8557 | // *************************************** |
| 8558 | // * Inherited from PhoneWindowManager * |
| 8559 | // *************************************** |
| 8560 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 8561 | // WITH ITS LOCKS HELD. |
| 8562 | // |
| 8563 | // This code must be VERY careful about the locks |
| 8564 | // it acquires. |
| 8565 | // In fact, the current code acquires way too many, |
| 8566 | // and probably has lurking deadlocks. |
| 8567 | |
| 8568 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 8569 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 8570 | } |
| 8571 | |
| 8572 | if (mNotifyUserActivity.getAndSet(false)) { |
| 8573 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 8574 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 8575 | } |
| 8576 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 8577 | |
| 8578 | @Override |
| 8579 | public boolean canConnectTo5GInDsdsMode() { |
| 8580 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 8581 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 8582 | } |