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; |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 38 | import android.net.NetworkStats; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 39 | import android.net.Uri; |
| 40 | import android.os.AsyncResult; |
| 41 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 42 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 43 | import android.os.Bundle; |
| 44 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 45 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 46 | import android.os.Looper; |
| 47 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 48 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 49 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 50 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 51 | import android.os.PersistableBundle; |
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; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 67 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 68 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 69 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 70 | import android.telephony.CellIdentityCdma; |
| 71 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 72 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 73 | import android.telephony.CellInfoGsm; |
| 74 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 75 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 76 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 77 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 78 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 79 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 80 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 81 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 82 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 83 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 84 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 85 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 86 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 87 | import android.telephony.SignalStrength; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 88 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 89 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 90 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 91 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 92 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 93 | import android.telephony.TelephonyScanManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 94 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 95 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 96 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 97 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 98 | import android.telephony.data.ApnSetting; |
| 99 | import android.telephony.emergency.EmergencyNumber; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 100 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 101 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 102 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 103 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 104 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 105 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 106 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 107 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 108 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 109 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 110 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 111 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 112 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 113 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 114 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 115 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 116 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 117 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 118 | import android.util.Pair; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 119 | import android.util.Slog; |
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; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 123 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 124 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 126 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 127 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.CommandException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 130 | import com.android.internal.telephony.HalVersion; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 132 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 134 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 140 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 149 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 150 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 152 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 156 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 157 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 160 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 162 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 164 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 167 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 168 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 170 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 171 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 172 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 173 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 174 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 175 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 176 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 177 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 178 | import java.io.FileDescriptor; |
| 179 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 180 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 181 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 182 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 183 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 184 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 185 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 186 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 187 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 188 | import java.util.Set; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 189 | |
| 190 | /** |
| 191 | * Implementation of the ITelephony interface. |
| 192 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 193 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 194 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 195 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 196 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 197 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 198 | |
| 199 | // Message codes used with mMainThreadHandler |
| 200 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 201 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 202 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 203 | private static final int CMD_OPEN_CHANNEL = 9; |
| 204 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 205 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 206 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 207 | private static final int CMD_NV_READ_ITEM = 13; |
| 208 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 209 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 210 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 211 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 212 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 213 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 214 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 215 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 216 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 217 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 218 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 219 | private static final int CMD_SEND_ENVELOPE = 25; |
| 220 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 221 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 222 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 223 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 224 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 225 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 226 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 227 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 228 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 229 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 230 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 231 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 232 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 233 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 234 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 235 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 236 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 237 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 238 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 239 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 240 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 241 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 242 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 243 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 244 | private static final int CMD_SWITCH_SLOTS = 50; |
| 245 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 246 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 247 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 248 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 249 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 250 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 251 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 252 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 253 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 254 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 255 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 256 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 257 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 258 | private static final int CMD_MODEM_REBOOT = 64; |
| 259 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 260 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 261 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 262 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 263 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 264 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 265 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 266 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 267 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 268 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 269 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 270 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 271 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 272 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 273 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 274 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 275 | // Parameters of select command. |
| 276 | private static final int SELECT_COMMAND = 0xA4; |
| 277 | private static final int SELECT_P1 = 0x04; |
| 278 | private static final int SELECT_P2 = 0; |
| 279 | private static final int SELECT_P3 = 0x10; |
| 280 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 281 | /** The singleton instance. */ |
| 282 | private static PhoneInterfaceManager sInstance; |
| 283 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 284 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 285 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 286 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 287 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 288 | private AppOpsManager mAppOps; |
| 289 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 290 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 291 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 292 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 293 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 294 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 295 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 296 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 297 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 298 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 299 | // String to store multi SIM allowed |
| 300 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 301 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 302 | // The AID of ISD-R. |
| 303 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 304 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 305 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 306 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 307 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 308 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 309 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 310 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 311 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 312 | */ |
| 313 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 314 | "reset_network_erase_modem_config_enabled"; |
| 315 | |
| 316 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 317 | * A request object to use for transmitting data to an ICC. |
| 318 | */ |
| 319 | private static final class IccAPDUArgument { |
| 320 | public int channel, cla, command, p1, p2, p3; |
| 321 | public String data; |
| 322 | |
| 323 | public IccAPDUArgument(int channel, int cla, int command, |
| 324 | int p1, int p2, int p3, String data) { |
| 325 | this.channel = channel; |
| 326 | this.cla = cla; |
| 327 | this.command = command; |
| 328 | this.p1 = p1; |
| 329 | this.p2 = p2; |
| 330 | this.p3 = p3; |
| 331 | this.data = data; |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 336 | * A request object to use for transmitting data to an ICC. |
| 337 | */ |
| 338 | private static final class ManualNetworkSelectionArgument { |
| 339 | public OperatorInfo operatorInfo; |
| 340 | public boolean persistSelection; |
| 341 | |
| 342 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 343 | this.operatorInfo = operatorInfo; |
| 344 | this.persistSelection = persistSelection; |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 349 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 350 | * request after sending. The main thread will notify the request when it is complete. |
| 351 | */ |
| 352 | private static final class MainThreadRequest { |
| 353 | /** The argument to use for the request */ |
| 354 | public Object argument; |
| 355 | /** The result of the request that is run on the main thread */ |
| 356 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 357 | // The subscriber id that this request applies to. Defaults to |
| 358 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 359 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 360 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 361 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 362 | public Phone phone; |
| 363 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 364 | public WorkSource workSource; |
| 365 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 366 | public MainThreadRequest(Object argument) { |
| 367 | this.argument = argument; |
| 368 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 369 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 370 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 371 | this.argument = argument; |
| 372 | if (phone != null) { |
| 373 | this.phone = phone; |
| 374 | } |
| 375 | this.workSource = workSource; |
| 376 | } |
| 377 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 378 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 379 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 380 | if (subId != null) { |
| 381 | this.subId = subId; |
| 382 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 383 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 384 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 387 | private static final class IncomingThirdPartyCallArgs { |
| 388 | public final ComponentName component; |
| 389 | public final String callId; |
| 390 | public final String callerDisplayName; |
| 391 | |
| 392 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 393 | String callerDisplayName) { |
| 394 | this.component = component; |
| 395 | this.callId = callId; |
| 396 | this.callerDisplayName = callerDisplayName; |
| 397 | } |
| 398 | } |
| 399 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 400 | /** |
| 401 | * A handler that processes messages on the main thread in the phone process. Since many |
| 402 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 403 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 404 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 405 | * on, which will be notified when the operation completes and will contain the result of the |
| 406 | * request. |
| 407 | * |
| 408 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 409 | * note that request.result must be set to something non-null for the calling thread to |
| 410 | * unblock. |
| 411 | */ |
| 412 | private final class MainThreadHandler extends Handler { |
| 413 | @Override |
| 414 | public void handleMessage(Message msg) { |
| 415 | MainThreadRequest request; |
| 416 | Message onCompleted; |
| 417 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 418 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 419 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 420 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 421 | |
| 422 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 423 | case CMD_HANDLE_USSD_REQUEST: { |
| 424 | request = (MainThreadRequest) msg.obj; |
| 425 | final Phone phone = getPhoneFromRequest(request); |
| 426 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 427 | String ussdRequest = ussdObject.first; |
| 428 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 429 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 430 | if (!isUssdApiAllowed(request.subId)) { |
| 431 | // Carrier does not support use of this API, return failure. |
| 432 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 433 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 434 | Bundle returnData = new Bundle(); |
| 435 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 436 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 437 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 438 | request.result = true; |
| 439 | notifyRequester(request); |
| 440 | return; |
| 441 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 442 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 443 | try { |
| 444 | request.result = phone != null |
| 445 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 446 | } catch (CallStateException cse) { |
| 447 | request.result = false; |
| 448 | } |
| 449 | // Wake up the requesting thread |
| 450 | notifyRequester(request); |
| 451 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 452 | } |
| 453 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 454 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 455 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 456 | final Phone phone = getPhoneFromRequest(request); |
| 457 | request.result = phone != null ? |
| 458 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 459 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 460 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 461 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 462 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 463 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 464 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 465 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 466 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 467 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 468 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 469 | if (uiccCard == null) { |
| 470 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 471 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 472 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 473 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 474 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 475 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 476 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 477 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 478 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 479 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 480 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 481 | break; |
| 482 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 483 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 484 | ar = (AsyncResult) msg.obj; |
| 485 | request = (MainThreadRequest) ar.userObj; |
| 486 | if (ar.exception == null && ar.result != null) { |
| 487 | request.result = ar.result; |
| 488 | } else { |
| 489 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 490 | if (ar.result == null) { |
| 491 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 492 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 493 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 494 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 495 | } else { |
| 496 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 497 | } |
| 498 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 499 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 500 | break; |
| 501 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 502 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 503 | request = (MainThreadRequest) msg.obj; |
| 504 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 505 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 506 | if (uiccCard == null) { |
| 507 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 508 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 509 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 510 | } else { |
| 511 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 512 | request); |
| 513 | uiccCard.iccTransmitApduBasicChannel( |
| 514 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 515 | iccArgument.p3, iccArgument.data, onCompleted); |
| 516 | } |
| 517 | break; |
| 518 | |
| 519 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 520 | ar = (AsyncResult) msg.obj; |
| 521 | request = (MainThreadRequest) ar.userObj; |
| 522 | if (ar.exception == null && ar.result != null) { |
| 523 | request.result = ar.result; |
| 524 | } else { |
| 525 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 526 | if (ar.result == null) { |
| 527 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 528 | } else if (ar.exception instanceof CommandException) { |
| 529 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 530 | ar.exception); |
| 531 | } else { |
| 532 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 533 | } |
| 534 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 535 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 536 | break; |
| 537 | |
| 538 | case CMD_EXCHANGE_SIM_IO: |
| 539 | request = (MainThreadRequest) msg.obj; |
| 540 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 541 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 542 | if (uiccCard == null) { |
| 543 | loge("iccExchangeSimIO: No UICC"); |
| 544 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 545 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 546 | } else { |
| 547 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 548 | request); |
| 549 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 550 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 551 | iccArgument.data, onCompleted); |
| 552 | } |
| 553 | break; |
| 554 | |
| 555 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 556 | ar = (AsyncResult) msg.obj; |
| 557 | request = (MainThreadRequest) ar.userObj; |
| 558 | if (ar.exception == null && ar.result != null) { |
| 559 | request.result = ar.result; |
| 560 | } else { |
| 561 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 562 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 563 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 564 | break; |
| 565 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 566 | case CMD_SEND_ENVELOPE: |
| 567 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 568 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 569 | if (uiccCard == null) { |
| 570 | loge("sendEnvelopeWithStatus: No UICC"); |
| 571 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 572 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 573 | } else { |
| 574 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 575 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 576 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 577 | break; |
| 578 | |
| 579 | case EVENT_SEND_ENVELOPE_DONE: |
| 580 | ar = (AsyncResult) msg.obj; |
| 581 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 582 | if (ar.exception == null && ar.result != null) { |
| 583 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 584 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 585 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 586 | if (ar.result == null) { |
| 587 | loge("sendEnvelopeWithStatus: Empty response"); |
| 588 | } else if (ar.exception instanceof CommandException) { |
| 589 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 590 | ar.exception); |
| 591 | } else { |
| 592 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 593 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 594 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 595 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 596 | break; |
| 597 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 598 | case CMD_OPEN_CHANNEL: |
| 599 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 600 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 601 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 602 | if (uiccCard == null) { |
| 603 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 604 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 605 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 606 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 607 | } else { |
| 608 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 609 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 610 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 611 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 612 | break; |
| 613 | |
| 614 | case EVENT_OPEN_CHANNEL_DONE: |
| 615 | ar = (AsyncResult) msg.obj; |
| 616 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 617 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 618 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 619 | int[] result = (int[]) ar.result; |
| 620 | int channelId = result[0]; |
| 621 | byte[] selectResponse = null; |
| 622 | if (result.length > 1) { |
| 623 | selectResponse = new byte[result.length - 1]; |
| 624 | for (int i = 1; i < result.length; ++i) { |
| 625 | selectResponse[i - 1] = (byte) result[i]; |
| 626 | } |
| 627 | } |
| 628 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 629 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 630 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 631 | if (ar.result == null) { |
| 632 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 633 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 634 | if (ar.exception != null) { |
| 635 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 636 | } |
| 637 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 638 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 639 | if (ar.exception instanceof CommandException) { |
| 640 | CommandException.Error error = |
| 641 | ((CommandException) (ar.exception)).getCommandError(); |
| 642 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 643 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 644 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 645 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 646 | } |
| 647 | } |
| 648 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 649 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 650 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 651 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 652 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 653 | break; |
| 654 | |
| 655 | case CMD_CLOSE_CHANNEL: |
| 656 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 657 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 658 | if (uiccCard == null) { |
| 659 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 660 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 661 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 662 | } else { |
| 663 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 664 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 665 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 666 | break; |
| 667 | |
| 668 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 669 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 670 | break; |
| 671 | |
| 672 | case CMD_NV_READ_ITEM: |
| 673 | request = (MainThreadRequest) msg.obj; |
| 674 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 675 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 676 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 677 | break; |
| 678 | |
| 679 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 680 | ar = (AsyncResult) msg.obj; |
| 681 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 682 | if (ar.exception == null && ar.result != null) { |
| 683 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 684 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 685 | request.result = ""; |
| 686 | if (ar.result == null) { |
| 687 | loge("nvReadItem: Empty response"); |
| 688 | } else if (ar.exception instanceof CommandException) { |
| 689 | loge("nvReadItem: CommandException: " + |
| 690 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 691 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 692 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 693 | } |
| 694 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 695 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 696 | break; |
| 697 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 698 | case CMD_NV_WRITE_ITEM: |
| 699 | request = (MainThreadRequest) msg.obj; |
| 700 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 701 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 702 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 703 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 704 | break; |
| 705 | |
| 706 | case EVENT_NV_WRITE_ITEM_DONE: |
| 707 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 708 | break; |
| 709 | |
| 710 | case CMD_NV_WRITE_CDMA_PRL: |
| 711 | request = (MainThreadRequest) msg.obj; |
| 712 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 713 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 714 | break; |
| 715 | |
| 716 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 717 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 718 | break; |
| 719 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 720 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 721 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 722 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 723 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 724 | break; |
| 725 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 726 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 727 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 728 | break; |
| 729 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 730 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 731 | request = (MainThreadRequest) msg.obj; |
| 732 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 733 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 734 | break; |
| 735 | |
| 736 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 737 | ar = (AsyncResult) msg.obj; |
| 738 | request = (MainThreadRequest) ar.userObj; |
| 739 | if (ar.exception == null && ar.result != null) { |
| 740 | request.result = ar.result; // Integer |
| 741 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 742 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 743 | if (ar.result == null) { |
| 744 | loge("getPreferredNetworkType: Empty response"); |
| 745 | } else if (ar.exception instanceof CommandException) { |
| 746 | loge("getPreferredNetworkType: CommandException: " + |
| 747 | ar.exception); |
| 748 | } else { |
| 749 | loge("getPreferredNetworkType: Unknown exception"); |
| 750 | } |
| 751 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 752 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 753 | break; |
| 754 | |
| 755 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 756 | request = (MainThreadRequest) msg.obj; |
| 757 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 758 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 759 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 760 | break; |
| 761 | |
| 762 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 763 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 764 | break; |
| 765 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 766 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 767 | request = (MainThreadRequest)msg.obj; |
| 768 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 769 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 770 | break; |
| 771 | |
| 772 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 773 | ar = (AsyncResult)msg.obj; |
| 774 | request = (MainThreadRequest)ar.userObj; |
| 775 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 776 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 777 | break; |
| 778 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 779 | case CMD_SET_VOICEMAIL_NUMBER: |
| 780 | request = (MainThreadRequest) msg.obj; |
| 781 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 782 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 783 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 784 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 785 | break; |
| 786 | |
| 787 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 788 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 789 | break; |
| 790 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 791 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 792 | request = (MainThreadRequest) msg.obj; |
| 793 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 794 | request); |
| 795 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 796 | break; |
| 797 | |
| 798 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 799 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 800 | break; |
| 801 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 802 | case CMD_PERFORM_NETWORK_SCAN: |
| 803 | request = (MainThreadRequest) msg.obj; |
| 804 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 805 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 806 | break; |
| 807 | |
| 808 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 809 | ar = (AsyncResult) msg.obj; |
| 810 | request = (MainThreadRequest) ar.userObj; |
| 811 | CellNetworkScanResult cellScanResult; |
| 812 | if (ar.exception == null && ar.result != null) { |
| 813 | cellScanResult = new CellNetworkScanResult( |
| 814 | CellNetworkScanResult.STATUS_SUCCESS, |
| 815 | (List<OperatorInfo>) ar.result); |
| 816 | } else { |
| 817 | if (ar.result == null) { |
| 818 | loge("getCellNetworkScanResults: Empty response"); |
| 819 | } |
| 820 | if (ar.exception != null) { |
| 821 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 822 | } |
| 823 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 824 | if (ar.exception instanceof CommandException) { |
| 825 | CommandException.Error error = |
| 826 | ((CommandException) (ar.exception)).getCommandError(); |
| 827 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 828 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 829 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 830 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 831 | } |
| 832 | } |
| 833 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 834 | } |
| 835 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 836 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 837 | break; |
| 838 | |
| 839 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 840 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 841 | ManualNetworkSelectionArgument selArg = |
| 842 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 843 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 844 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 845 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 846 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 847 | break; |
| 848 | |
| 849 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 850 | ar = (AsyncResult) msg.obj; |
| 851 | request = (MainThreadRequest) ar.userObj; |
| 852 | if (ar.exception == null) { |
| 853 | request.result = true; |
| 854 | } else { |
| 855 | request.result = false; |
| 856 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 857 | } |
| 858 | notifyRequester(request); |
| 859 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 860 | break; |
| 861 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 862 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 863 | request = (MainThreadRequest) msg.obj; |
| 864 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 865 | if (defaultPhone != null) { |
| 866 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
| 867 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 868 | break; |
| 869 | |
| 870 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 871 | ar = (AsyncResult) msg.obj; |
| 872 | request = (MainThreadRequest) ar.userObj; |
| 873 | if (ar.exception == null && ar.result != null) { |
| 874 | request.result = ar.result; |
| 875 | } else { |
| 876 | if (ar.result == null) { |
| 877 | loge("queryModemActivityInfo: Empty response"); |
| 878 | } else if (ar.exception instanceof CommandException) { |
| 879 | loge("queryModemActivityInfo: CommandException: " + |
| 880 | ar.exception); |
| 881 | } else { |
| 882 | loge("queryModemActivityInfo: Unknown exception"); |
| 883 | } |
| 884 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 885 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 886 | if (request.result == null) { |
Peter Collingbourne | c00e902 | 2019-11-26 09:56:26 -0800 | [diff] [blame] | 887 | request.result = new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 888 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 889 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 890 | break; |
| 891 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 892 | case CMD_SET_ALLOWED_CARRIERS: |
| 893 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 894 | CarrierRestrictionRules argument = |
| 895 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 896 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 897 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 898 | break; |
| 899 | |
| 900 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 901 | ar = (AsyncResult) msg.obj; |
| 902 | request = (MainThreadRequest) ar.userObj; |
| 903 | if (ar.exception == null && ar.result != null) { |
| 904 | request.result = ar.result; |
| 905 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 906 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 907 | if (ar.exception instanceof CommandException) { |
| 908 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 909 | CommandException.Error error = |
| 910 | ((CommandException) (ar.exception)).getCommandError(); |
| 911 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 912 | request.result = |
| 913 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 914 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 915 | } else { |
| 916 | loge("setAllowedCarriers: Unknown exception"); |
| 917 | } |
| 918 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 919 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 920 | break; |
| 921 | |
| 922 | case CMD_GET_ALLOWED_CARRIERS: |
| 923 | request = (MainThreadRequest) msg.obj; |
| 924 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 925 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 926 | break; |
| 927 | |
| 928 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 929 | ar = (AsyncResult) msg.obj; |
| 930 | request = (MainThreadRequest) ar.userObj; |
| 931 | if (ar.exception == null && ar.result != null) { |
| 932 | request.result = ar.result; |
| 933 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 934 | request.result = new IllegalStateException( |
| 935 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 936 | if (ar.result == null) { |
| 937 | loge("getAllowedCarriers: Empty response"); |
| 938 | } else if (ar.exception instanceof CommandException) { |
| 939 | loge("getAllowedCarriers: CommandException: " + |
| 940 | ar.exception); |
| 941 | } else { |
| 942 | loge("getAllowedCarriers: Unknown exception"); |
| 943 | } |
| 944 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 945 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 946 | break; |
| 947 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 948 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 949 | ar = (AsyncResult) msg.obj; |
| 950 | request = (MainThreadRequest) ar.userObj; |
| 951 | if (ar.exception == null && ar.result != null) { |
| 952 | request.result = ar.result; |
| 953 | } else { |
| 954 | request.result = new IllegalArgumentException( |
| 955 | "Failed to retrieve Forbidden Plmns"); |
| 956 | if (ar.result == null) { |
| 957 | loge("getForbiddenPlmns: Empty response"); |
| 958 | } else { |
| 959 | loge("getForbiddenPlmns: Unknown exception"); |
| 960 | } |
| 961 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 962 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 963 | break; |
| 964 | |
| 965 | case CMD_GET_FORBIDDEN_PLMNS: |
| 966 | request = (MainThreadRequest) msg.obj; |
| 967 | uiccCard = getUiccCardFromRequest(request); |
| 968 | if (uiccCard == null) { |
| 969 | loge("getForbiddenPlmns() UiccCard is null"); |
| 970 | request.result = new IllegalArgumentException( |
| 971 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 972 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 973 | break; |
| 974 | } |
| 975 | Integer appType = (Integer) request.argument; |
| 976 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 977 | if (uiccApp == null) { |
| 978 | loge("getForbiddenPlmns() no app with specified type -- " |
| 979 | + appType); |
| 980 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 981 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 982 | break; |
| 983 | } else { |
| 984 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 985 | + " specified type -- " + appType); |
| 986 | } |
| 987 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 988 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 989 | onCompleted); |
| 990 | break; |
| 991 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 992 | case CMD_SWITCH_SLOTS: |
| 993 | request = (MainThreadRequest) msg.obj; |
| 994 | int[] physicalSlots = (int[]) request.argument; |
| 995 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 996 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 997 | break; |
| 998 | |
| 999 | case EVENT_SWITCH_SLOTS_DONE: |
| 1000 | ar = (AsyncResult) msg.obj; |
| 1001 | request = (MainThreadRequest) ar.userObj; |
| 1002 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1003 | notifyRequester(request); |
| 1004 | break; |
| 1005 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1006 | request = (MainThreadRequest) msg.obj; |
| 1007 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1008 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1009 | break; |
| 1010 | |
| 1011 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1012 | ar = (AsyncResult) msg.obj; |
| 1013 | request = (MainThreadRequest) ar.userObj; |
| 1014 | if (ar.exception != null) { |
| 1015 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1016 | } else { |
| 1017 | int mode = ((int[]) ar.result)[0]; |
| 1018 | if (mode == 0) { |
| 1019 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1020 | } else { |
| 1021 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1022 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1023 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1024 | notifyRequester(request); |
| 1025 | break; |
| 1026 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1027 | request = (MainThreadRequest) msg.obj; |
| 1028 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1029 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1030 | break; |
| 1031 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1032 | ar = (AsyncResult) msg.obj; |
| 1033 | request = (MainThreadRequest) ar.userObj; |
| 1034 | if (ar.exception != null) { |
| 1035 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1036 | } else { |
| 1037 | request.result = ((int[]) ar.result)[0]; |
| 1038 | } |
| 1039 | notifyRequester(request); |
| 1040 | break; |
| 1041 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1042 | request = (MainThreadRequest) msg.obj; |
| 1043 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1044 | int mode = (int) request.argument; |
| 1045 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1046 | break; |
| 1047 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1048 | ar = (AsyncResult) msg.obj; |
| 1049 | request = (MainThreadRequest) ar.userObj; |
| 1050 | request.result = ar.exception == null; |
| 1051 | notifyRequester(request); |
| 1052 | break; |
| 1053 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1054 | request = (MainThreadRequest) msg.obj; |
| 1055 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1056 | int subscriptionMode = (int) request.argument; |
| 1057 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1058 | break; |
| 1059 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1060 | ar = (AsyncResult) msg.obj; |
| 1061 | request = (MainThreadRequest) ar.userObj; |
| 1062 | request.result = ar.exception == null; |
| 1063 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1064 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1065 | case CMD_GET_ALL_CELL_INFO: |
| 1066 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1067 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1068 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1069 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1070 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1071 | ar = (AsyncResult) msg.obj; |
| 1072 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1073 | // If a timeout occurs, the response will be null |
| 1074 | request.result = (ar.exception == null && ar.result != null) |
| 1075 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1076 | synchronized (request) { |
| 1077 | request.notifyAll(); |
| 1078 | } |
| 1079 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1080 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1081 | request = (MainThreadRequest) msg.obj; |
| 1082 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1083 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1084 | break; |
| 1085 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1086 | ar = (AsyncResult) msg.obj; |
| 1087 | request = (MainThreadRequest) ar.userObj; |
| 1088 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1089 | try { |
| 1090 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1091 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1092 | cb.onError( |
| 1093 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1094 | ar.exception.getClass().getName(), |
| 1095 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1096 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1097 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1098 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1099 | } else { |
| 1100 | // use the result as returned |
| 1101 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1102 | } |
| 1103 | } catch (RemoteException re) { |
| 1104 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1105 | } |
| 1106 | break; |
| 1107 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1108 | request = (MainThreadRequest) msg.obj; |
| 1109 | WorkSource ws = (WorkSource) request.argument; |
| 1110 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1111 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1112 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1113 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1114 | ar = (AsyncResult) msg.obj; |
| 1115 | request = (MainThreadRequest) ar.userObj; |
| 1116 | if (ar.exception == null) { |
| 1117 | request.result = ar.result; |
| 1118 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1119 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1120 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1121 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | synchronized (request) { |
| 1125 | request.notifyAll(); |
| 1126 | } |
| 1127 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1128 | case CMD_MODEM_REBOOT: |
| 1129 | request = (MainThreadRequest) msg.obj; |
| 1130 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1131 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1132 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1133 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1134 | handleNullReturnEvent(msg, "rebootModem"); |
| 1135 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1136 | case CMD_REQUEST_ENABLE_MODEM: |
| 1137 | request = (MainThreadRequest) msg.obj; |
| 1138 | boolean enable = (boolean) request.argument; |
| 1139 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1140 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1141 | PhoneConfigurationManager.getInstance() |
| 1142 | .enablePhone(request.phone, enable, onCompleted); |
| 1143 | break; |
| 1144 | case EVENT_ENABLE_MODEM_DONE: |
| 1145 | ar = (AsyncResult) msg.obj; |
| 1146 | request = (MainThreadRequest) ar.userObj; |
| 1147 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1148 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1149 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1150 | if ((boolean) request.result) { |
| 1151 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1152 | updateModemStateMetrics(); |
| 1153 | } else { |
| 1154 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1155 | + ar.exception); |
| 1156 | } |
| 1157 | notifyRequester(request); |
| 1158 | break; |
| 1159 | case CMD_GET_MODEM_STATUS: |
| 1160 | request = (MainThreadRequest) msg.obj; |
| 1161 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1162 | PhoneConfigurationManager.getInstance() |
| 1163 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1164 | break; |
| 1165 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1166 | ar = (AsyncResult) msg.obj; |
| 1167 | request = (MainThreadRequest) ar.userObj; |
| 1168 | int id = request.phone.getPhoneId(); |
| 1169 | if (ar.exception == null && ar.result != null) { |
| 1170 | request.result = ar.result; |
| 1171 | //update the cache as modem status has changed |
| 1172 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1173 | (boolean) request.result); |
| 1174 | } else { |
| 1175 | // Return true if modem status cannot be retrieved. For most cases, |
| 1176 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1177 | // and disable modem are not supported. Modem is always on. |
| 1178 | // TODO: this should be fixed in R to support a third |
| 1179 | // status UNKNOWN b/131631629 |
| 1180 | request.result = true; |
| 1181 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1182 | + ar.exception); |
| 1183 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1184 | notifyRequester(request); |
| 1185 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1186 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1187 | ar = (AsyncResult) msg.obj; |
| 1188 | request = (MainThreadRequest) ar.userObj; |
| 1189 | if (ar.exception == null && ar.result != null) { |
| 1190 | request.result = ar.result; |
| 1191 | } else { |
| 1192 | request.result = -1; |
| 1193 | loge("Failed to set Forbidden Plmns"); |
| 1194 | if (ar.result == null) { |
| 1195 | loge("setForbidenPlmns: Empty response"); |
| 1196 | } else if (ar.exception != null) { |
| 1197 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1198 | request.result = -1; |
| 1199 | } else { |
| 1200 | loge("setForbiddenPlmns: Unknown exception"); |
| 1201 | } |
| 1202 | } |
| 1203 | notifyRequester(request); |
| 1204 | break; |
| 1205 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1206 | request = (MainThreadRequest) msg.obj; |
| 1207 | uiccCard = getUiccCardFromRequest(request); |
| 1208 | if (uiccCard == null) { |
| 1209 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1210 | request.result = -1; |
| 1211 | notifyRequester(request); |
| 1212 | break; |
| 1213 | } |
| 1214 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1215 | (Pair<Integer, List<String>>) request.argument; |
| 1216 | appType = setFplmnsArgs.first; |
| 1217 | List<String> fplmns = setFplmnsArgs.second; |
| 1218 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1219 | if (uiccApp == null) { |
| 1220 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1221 | request.result = -1; |
| 1222 | loge("Failed to get UICC App"); |
| 1223 | notifyRequester(request); |
| 1224 | } else { |
| 1225 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1226 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1227 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1228 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1229 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1230 | case CMD_ERASE_MODEM_CONFIG: |
| 1231 | request = (MainThreadRequest) msg.obj; |
| 1232 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1233 | defaultPhone.eraseModemConfig(onCompleted); |
| 1234 | break; |
| 1235 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1236 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1237 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1238 | |
| 1239 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1240 | request = (MainThreadRequest) msg.obj; |
| 1241 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1242 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1243 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1244 | changed.first, changed.second, onCompleted); |
| 1245 | break; |
| 1246 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1247 | ar = (AsyncResult) msg.obj; |
| 1248 | request = (MainThreadRequest) ar.userObj; |
| 1249 | if (ar.exception == null) { |
| 1250 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1251 | } else { |
| 1252 | request.result = msg.arg1; |
| 1253 | } |
| 1254 | notifyRequester(request); |
| 1255 | break; |
| 1256 | |
| 1257 | case CMD_SET_ICC_LOCK_ENABLED: |
| 1258 | request = (MainThreadRequest) msg.obj; |
| 1259 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1260 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1261 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1262 | enabled.first, enabled.second, onCompleted); |
| 1263 | break; |
| 1264 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1265 | ar = (AsyncResult) msg.obj; |
| 1266 | request = (MainThreadRequest) ar.userObj; |
| 1267 | if (ar.exception == null) { |
| 1268 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1269 | } else { |
| 1270 | request.result = msg.arg1; |
| 1271 | } |
| 1272 | notifyRequester(request); |
| 1273 | break; |
| 1274 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1275 | default: |
| 1276 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1277 | break; |
| 1278 | } |
| 1279 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1280 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1281 | private void notifyRequester(MainThreadRequest request) { |
| 1282 | synchronized (request) { |
| 1283 | request.notifyAll(); |
| 1284 | } |
| 1285 | } |
| 1286 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1287 | private void handleNullReturnEvent(Message msg, String command) { |
| 1288 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1289 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1290 | if (ar.exception == null) { |
| 1291 | request.result = true; |
| 1292 | } else { |
| 1293 | request.result = false; |
| 1294 | if (ar.exception instanceof CommandException) { |
| 1295 | loge(command + ": CommandException: " + ar.exception); |
| 1296 | } else { |
| 1297 | loge(command + ": Unknown exception"); |
| 1298 | } |
| 1299 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1300 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1301 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1302 | } |
| 1303 | |
| 1304 | /** |
| 1305 | * Posts the specified command to be executed on the main thread, |
| 1306 | * waits for the request to complete, and returns the result. |
| 1307 | * @see #sendRequestAsync |
| 1308 | */ |
| 1309 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1310 | return sendRequest( |
| 1311 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1312 | } |
| 1313 | |
| 1314 | /** |
| 1315 | * Posts the specified command to be executed on the main thread, |
| 1316 | * waits for the request to complete, and returns the result. |
| 1317 | * @see #sendRequestAsync |
| 1318 | */ |
| 1319 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1320 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1321 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | /** |
| 1325 | * Posts the specified command to be executed on the main thread, |
| 1326 | * waits for the request to complete, and returns the result. |
| 1327 | * @see #sendRequestAsync |
| 1328 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1329 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1330 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1331 | } |
| 1332 | |
| 1333 | /** |
| 1334 | * Posts the specified command to be executed on the main thread, |
| 1335 | * waits for the request to complete, and returns the result. |
| 1336 | * @see #sendRequestAsync |
| 1337 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1338 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1339 | return sendRequest(command, argument, subId, null, workSource); |
| 1340 | } |
| 1341 | |
| 1342 | /** |
| 1343 | * Posts the specified command to be executed on the main thread, |
| 1344 | * waits for the request to complete, and returns the result. |
| 1345 | * @see #sendRequestAsync |
| 1346 | */ |
| 1347 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1348 | return sendRequest( |
| 1349 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1350 | } |
| 1351 | |
| 1352 | /** |
| 1353 | * Posts the specified command to be executed on the main thread, |
| 1354 | * waits for the request to complete, and returns the result. |
| 1355 | * @see #sendRequestAsync |
| 1356 | */ |
| 1357 | private Object sendRequest( |
| 1358 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1359 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1360 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1361 | } |
| 1362 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1363 | MainThreadRequest request = null; |
| 1364 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1365 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1366 | } else if (phone != null) { |
| 1367 | request = new MainThreadRequest(argument, phone, workSource); |
| 1368 | } else { |
| 1369 | request = new MainThreadRequest(argument, subId, workSource); |
| 1370 | } |
| 1371 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1372 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1373 | msg.sendToTarget(); |
| 1374 | |
| 1375 | // Wait for the request to complete |
| 1376 | synchronized (request) { |
| 1377 | while (request.result == null) { |
| 1378 | try { |
| 1379 | request.wait(); |
| 1380 | } catch (InterruptedException e) { |
| 1381 | // Do nothing, go back and wait until the request is complete |
| 1382 | } |
| 1383 | } |
| 1384 | } |
| 1385 | return request.result; |
| 1386 | } |
| 1387 | |
| 1388 | /** |
| 1389 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1390 | * Posts the specified command to be executed on the main thread, and |
| 1391 | * returns immediately. |
| 1392 | * @see #sendRequest |
| 1393 | */ |
| 1394 | private void sendRequestAsync(int command) { |
| 1395 | mMainThreadHandler.sendEmptyMessage(command); |
| 1396 | } |
| 1397 | |
| 1398 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1399 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1400 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1401 | */ |
| 1402 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1403 | sendRequestAsync(command, argument, null, null); |
| 1404 | } |
| 1405 | |
| 1406 | /** |
| 1407 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1408 | * @see {@link #sendRequest(int,Object)} |
| 1409 | */ |
| 1410 | private void sendRequestAsync( |
| 1411 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1412 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1413 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1414 | msg.sendToTarget(); |
| 1415 | } |
| 1416 | |
| 1417 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1418 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1419 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1420 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1421 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1422 | synchronized (PhoneInterfaceManager.class) { |
| 1423 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1424 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1425 | } else { |
| 1426 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1427 | } |
| 1428 | return sInstance; |
| 1429 | } |
| 1430 | } |
| 1431 | |
| 1432 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1433 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1434 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1435 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1436 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1437 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1438 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1439 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1440 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1441 | mTelephonySharedPreferences = |
| 1442 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1443 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1444 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1445 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1446 | publish(); |
| 1447 | } |
| 1448 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1449 | private Phone getDefaultPhone() { |
| 1450 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1451 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1452 | } |
| 1453 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1454 | private void publish() { |
| 1455 | if (DBG) log("publish: " + this); |
| 1456 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 1457 | TelephonyFrameworkInitializer |
| 1458 | .getTelephonyServiceManager() |
| 1459 | .getTelephonyServiceRegisterer() |
| 1460 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1461 | } |
| 1462 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1463 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1464 | if (request.phone != null) { |
| 1465 | return request.phone; |
| 1466 | } else { |
| 1467 | return getPhoneFromSubId(request.subId); |
| 1468 | } |
| 1469 | } |
| 1470 | |
| 1471 | private Phone getPhoneFromSubId(int subId) { |
| 1472 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1473 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1474 | } |
| 1475 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1476 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1477 | Phone phone = getPhoneFromRequest(request); |
| 1478 | return phone == null ? null : |
| 1479 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1480 | } |
| 1481 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1482 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1483 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1484 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1485 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1486 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1487 | private void sendEraseModemConfig(Phone phone) { |
| 1488 | if (phone != null) { |
| 1489 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 1490 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 1491 | final long identity = Binder.clearCallingIdentity(); |
| 1492 | try { |
| 1493 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 1494 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 1495 | } finally { |
| 1496 | Binder.restoreCallingIdentity(identity); |
| 1497 | } |
| 1498 | } |
| 1499 | } |
| 1500 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 1501 | private boolean isImsAvailableOnDevice() { |
| 1502 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 1503 | if (pm == null) { |
| 1504 | // For some reason package manger is not available.. This will fail internally anyway, |
| 1505 | // so do not throw error and allow. |
| 1506 | return true; |
| 1507 | } |
| 1508 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 1509 | } |
| 1510 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1511 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1512 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1513 | } |
| 1514 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1515 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1516 | if (DBG) log("dial: " + number); |
| 1517 | // No permission check needed here: This is just a wrapper around the |
| 1518 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1519 | // the UI before it does anything. |
| 1520 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1521 | final long identity = Binder.clearCallingIdentity(); |
| 1522 | try { |
| 1523 | String url = createTelUrl(number); |
| 1524 | if (url == null) { |
| 1525 | return; |
| 1526 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1527 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1528 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1529 | PhoneConstants.State state = mCM.getState(subId); |
| 1530 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1531 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1532 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1533 | mApp.startActivity(intent); |
| 1534 | } |
| 1535 | } finally { |
| 1536 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1537 | } |
| 1538 | } |
| 1539 | |
| 1540 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1541 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1542 | } |
| 1543 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1544 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1545 | if (DBG) log("call: " + number); |
| 1546 | |
| 1547 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1548 | // need to do a permission check since we're calling startActivity() |
| 1549 | // from the context of the phone app. |
| 1550 | enforceCallPermission(); |
| 1551 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 1552 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1553 | != AppOpsManager.MODE_ALLOWED) { |
| 1554 | return; |
| 1555 | } |
| 1556 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1557 | final long identity = Binder.clearCallingIdentity(); |
| 1558 | try { |
| 1559 | String url = createTelUrl(number); |
| 1560 | if (url == null) { |
| 1561 | return; |
| 1562 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1563 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1564 | boolean isValid = false; |
| 1565 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1566 | if (slist != null) { |
| 1567 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1568 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1569 | isValid = true; |
| 1570 | break; |
| 1571 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1572 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1573 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1574 | if (!isValid) { |
| 1575 | return; |
| 1576 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1577 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1578 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1579 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1580 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1581 | mApp.startActivity(intent); |
| 1582 | } finally { |
| 1583 | Binder.restoreCallingIdentity(identity); |
| 1584 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1585 | } |
| 1586 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1587 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1588 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1589 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1590 | } |
| 1591 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1592 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1593 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1594 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1595 | } |
| 1596 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1597 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1598 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1599 | |
| 1600 | final long identity = Binder.clearCallingIdentity(); |
| 1601 | try { |
| 1602 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1603 | checkSimPin.start(); |
| 1604 | return checkSimPin.unlockSim(null, pin); |
| 1605 | } finally { |
| 1606 | Binder.restoreCallingIdentity(identity); |
| 1607 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1608 | } |
| 1609 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1610 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1611 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1612 | |
| 1613 | final long identity = Binder.clearCallingIdentity(); |
| 1614 | try { |
| 1615 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1616 | checkSimPuk.start(); |
| 1617 | return checkSimPuk.unlockSim(puk, pin); |
| 1618 | } finally { |
| 1619 | Binder.restoreCallingIdentity(identity); |
| 1620 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1621 | } |
| 1622 | |
| 1623 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1624 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1625 | * a synchronous one. |
| 1626 | */ |
| 1627 | private static class UnlockSim extends Thread { |
| 1628 | |
| 1629 | private final IccCard mSimCard; |
| 1630 | |
| 1631 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1632 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1633 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1634 | |
| 1635 | // For replies from SimCard interface |
| 1636 | private Handler mHandler; |
| 1637 | |
| 1638 | // For async handler to identify request type |
| 1639 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1640 | |
| 1641 | public UnlockSim(IccCard simCard) { |
| 1642 | mSimCard = simCard; |
| 1643 | } |
| 1644 | |
| 1645 | @Override |
| 1646 | public void run() { |
| 1647 | Looper.prepare(); |
| 1648 | synchronized (UnlockSim.this) { |
| 1649 | mHandler = new Handler() { |
| 1650 | @Override |
| 1651 | public void handleMessage(Message msg) { |
| 1652 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1653 | switch (msg.what) { |
| 1654 | case SUPPLY_PIN_COMPLETE: |
| 1655 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1656 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1657 | mRetryCount = msg.arg1; |
| 1658 | if (ar.exception != null) { |
| 1659 | if (ar.exception instanceof CommandException && |
| 1660 | ((CommandException)(ar.exception)).getCommandError() |
| 1661 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1662 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1663 | } else { |
| 1664 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1665 | } |
| 1666 | } else { |
| 1667 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1668 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1669 | mDone = true; |
| 1670 | UnlockSim.this.notifyAll(); |
| 1671 | } |
| 1672 | break; |
| 1673 | } |
| 1674 | } |
| 1675 | }; |
| 1676 | UnlockSim.this.notifyAll(); |
| 1677 | } |
| 1678 | Looper.loop(); |
| 1679 | } |
| 1680 | |
| 1681 | /* |
| 1682 | * Use PIN or PUK to unlock SIM card |
| 1683 | * |
| 1684 | * If PUK is null, unlock SIM card with PIN |
| 1685 | * |
| 1686 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1687 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1688 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1689 | |
| 1690 | while (mHandler == null) { |
| 1691 | try { |
| 1692 | wait(); |
| 1693 | } catch (InterruptedException e) { |
| 1694 | Thread.currentThread().interrupt(); |
| 1695 | } |
| 1696 | } |
| 1697 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1698 | |
| 1699 | if (puk == null) { |
| 1700 | mSimCard.supplyPin(pin, callback); |
| 1701 | } else { |
| 1702 | mSimCard.supplyPuk(puk, pin, callback); |
| 1703 | } |
| 1704 | |
| 1705 | while (!mDone) { |
| 1706 | try { |
| 1707 | Log.d(LOG_TAG, "wait for done"); |
| 1708 | wait(); |
| 1709 | } catch (InterruptedException e) { |
| 1710 | // Restore the interrupted status |
| 1711 | Thread.currentThread().interrupt(); |
| 1712 | } |
| 1713 | } |
| 1714 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1715 | int[] resultArray = new int[2]; |
| 1716 | resultArray[0] = mResult; |
| 1717 | resultArray[1] = mRetryCount; |
| 1718 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1719 | } |
| 1720 | } |
| 1721 | |
| 1722 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1723 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1724 | |
| 1725 | } |
| 1726 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1727 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1728 | // No permission check needed here: this call is harmless, and it's |
| 1729 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1730 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1731 | final long identity = Binder.clearCallingIdentity(); |
| 1732 | try { |
| 1733 | final Phone phone = getPhone(subId); |
| 1734 | if (phone != null) { |
| 1735 | phone.updateServiceLocation(); |
| 1736 | } |
| 1737 | } finally { |
| 1738 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1739 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1740 | } |
| 1741 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1742 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1743 | @Override |
| 1744 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1745 | return isRadioOnWithFeature(callingPackage, null); |
| 1746 | } |
| 1747 | |
| 1748 | |
| 1749 | @Override |
| 1750 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 1751 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 1752 | callingFeatureId); |
| 1753 | } |
| 1754 | |
| 1755 | @Deprecated |
| 1756 | @Override |
| 1757 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 1758 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1759 | } |
| 1760 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1761 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1762 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 1763 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1764 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1765 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1766 | return false; |
| 1767 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1768 | |
| 1769 | final long identity = Binder.clearCallingIdentity(); |
| 1770 | try { |
| 1771 | return isRadioOnForSubscriber(subId); |
| 1772 | } finally { |
| 1773 | Binder.restoreCallingIdentity(identity); |
| 1774 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1775 | } |
| 1776 | |
| 1777 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1778 | final long identity = Binder.clearCallingIdentity(); |
| 1779 | try { |
| 1780 | final Phone phone = getPhone(subId); |
| 1781 | if (phone != null) { |
| 1782 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1783 | } else { |
| 1784 | return false; |
| 1785 | } |
| 1786 | } finally { |
| 1787 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1788 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1789 | } |
| 1790 | |
| 1791 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1792 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1793 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1794 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1795 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1796 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1797 | |
| 1798 | final long identity = Binder.clearCallingIdentity(); |
| 1799 | try { |
| 1800 | final Phone phone = getPhone(subId); |
| 1801 | if (phone != null) { |
| 1802 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1803 | } |
| 1804 | } finally { |
| 1805 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1806 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1807 | } |
| 1808 | |
| 1809 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1810 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1811 | } |
| 1812 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1813 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1814 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1815 | |
| 1816 | final long identity = Binder.clearCallingIdentity(); |
| 1817 | try { |
| 1818 | final Phone phone = getPhone(subId); |
| 1819 | if (phone == null) { |
| 1820 | return false; |
| 1821 | } |
| 1822 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1823 | toggleRadioOnOffForSubscriber(subId); |
| 1824 | } |
| 1825 | return true; |
| 1826 | } finally { |
| 1827 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1828 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1829 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1830 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1831 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 1832 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1833 | /* |
| 1834 | * If any of the Radios are available, it will need to be |
| 1835 | * shutdown. So return true if any Radio is available. |
| 1836 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1837 | final long identity = Binder.clearCallingIdentity(); |
| 1838 | try { |
| 1839 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1840 | Phone phone = PhoneFactory.getPhone(i); |
| 1841 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1842 | } |
| 1843 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1844 | return false; |
| 1845 | } finally { |
| 1846 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1847 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1848 | } |
| 1849 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1850 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1851 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1852 | enforceModifyPermission(); |
| 1853 | |
| 1854 | final long identity = Binder.clearCallingIdentity(); |
| 1855 | try { |
| 1856 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1857 | logv("Shutting down Phone " + i); |
| 1858 | shutdownRadioUsingPhoneId(i); |
| 1859 | } |
| 1860 | } finally { |
| 1861 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1862 | } |
| 1863 | } |
| 1864 | |
| 1865 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1866 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1867 | if (phone != null && phone.isRadioAvailable()) { |
| 1868 | phone.shutdownRadio(); |
| 1869 | } |
| 1870 | } |
| 1871 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1872 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 1873 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1874 | |
| 1875 | final long identity = Binder.clearCallingIdentity(); |
| 1876 | try { |
| 1877 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1878 | if (defaultPhone != null) { |
| 1879 | defaultPhone.setRadioPower(turnOn); |
| 1880 | return true; |
| 1881 | } else { |
| 1882 | loge("There's no default phone."); |
| 1883 | return false; |
| 1884 | } |
| 1885 | } finally { |
| 1886 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1887 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1888 | } |
| 1889 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1890 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1891 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1892 | |
| 1893 | final long identity = Binder.clearCallingIdentity(); |
| 1894 | try { |
| 1895 | final Phone phone = getPhone(subId); |
| 1896 | if (phone != null) { |
| 1897 | phone.setRadioPower(turnOn); |
| 1898 | return true; |
| 1899 | } else { |
| 1900 | return false; |
| 1901 | } |
| 1902 | } finally { |
| 1903 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1904 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1905 | } |
| 1906 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1907 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1908 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1909 | public boolean enableDataConnectivity() { |
| 1910 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1911 | |
| 1912 | final long identity = Binder.clearCallingIdentity(); |
| 1913 | try { |
| 1914 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1915 | final Phone phone = getPhone(subId); |
| 1916 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1917 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1918 | return true; |
| 1919 | } else { |
| 1920 | return false; |
| 1921 | } |
| 1922 | } finally { |
| 1923 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1924 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1925 | } |
| 1926 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1927 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1928 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1929 | public boolean disableDataConnectivity() { |
| 1930 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1931 | |
| 1932 | final long identity = Binder.clearCallingIdentity(); |
| 1933 | try { |
| 1934 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1935 | final Phone phone = getPhone(subId); |
| 1936 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1937 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1938 | return true; |
| 1939 | } else { |
| 1940 | return false; |
| 1941 | } |
| 1942 | } finally { |
| 1943 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1944 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1945 | } |
| 1946 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1947 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1948 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1949 | final long identity = Binder.clearCallingIdentity(); |
| 1950 | try { |
| 1951 | final Phone phone = getPhone(subId); |
| 1952 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 1953 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1954 | } else { |
| 1955 | return false; |
| 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 | |
| 1962 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1963 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1964 | } |
| 1965 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1966 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1967 | enforceCallPermission(); |
| 1968 | |
| 1969 | final long identity = Binder.clearCallingIdentity(); |
| 1970 | try { |
| 1971 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1972 | return; |
| 1973 | } |
| 1974 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 1975 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 1976 | } finally { |
| 1977 | Binder.restoreCallingIdentity(identity); |
| 1978 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1979 | }; |
| 1980 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1981 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1982 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1983 | |
| 1984 | final long identity = Binder.clearCallingIdentity(); |
| 1985 | try { |
| 1986 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1987 | return false; |
| 1988 | } |
| 1989 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 1990 | } finally { |
| 1991 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1992 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1993 | } |
| 1994 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1995 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1996 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1997 | } |
| 1998 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1999 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2000 | final long identity = Binder.clearCallingIdentity(); |
| 2001 | try { |
| 2002 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2003 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2004 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2005 | } finally { |
| 2006 | Binder.restoreCallingIdentity(identity); |
| 2007 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2008 | } |
| 2009 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2010 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2011 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2012 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2013 | } |
| 2014 | |
| 2015 | @Override |
| 2016 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2017 | final long identity = Binder.clearCallingIdentity(); |
| 2018 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2019 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2020 | if (phone != null) { |
| 2021 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2022 | } else { |
| 2023 | return PhoneConstantConversions.convertDataState( |
| 2024 | PhoneConstants.DataState.DISCONNECTED); |
| 2025 | } |
| 2026 | } finally { |
| 2027 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2028 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2029 | } |
| 2030 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2031 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2032 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2033 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2034 | } |
| 2035 | |
| 2036 | @Override |
| 2037 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2038 | final long identity = Binder.clearCallingIdentity(); |
| 2039 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2040 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2041 | if (phone != null) { |
| 2042 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2043 | } else { |
| 2044 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2045 | } |
| 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 | } |
| 2050 | |
| 2051 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2052 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2053 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2054 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2055 | |
| 2056 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2057 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2058 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2059 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2060 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2061 | .setCallingPid(Binder.getCallingPid()) |
| 2062 | .setCallingUid(Binder.getCallingUid()) |
| 2063 | .setMethod("getCellLocation") |
| 2064 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2065 | .build()); |
| 2066 | switch (locationResult) { |
| 2067 | case DENIED_HARD: |
| 2068 | throw new SecurityException("Not allowed to access cell location"); |
| 2069 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2070 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2071 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2072 | } |
| 2073 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2074 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2075 | final long identity = Binder.clearCallingIdentity(); |
| 2076 | try { |
| 2077 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2078 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2079 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2080 | } finally { |
| 2081 | Binder.restoreCallingIdentity(identity); |
| 2082 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2083 | } |
| 2084 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2085 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2086 | public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage, |
| 2087 | String callingFeatureId) { |
Jack Yu | 1e81ccd | 2019-09-26 11:48:33 -0700 | [diff] [blame] | 2088 | if (!TextUtils.isEmpty(callingPackage)) { |
| 2089 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2090 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2091 | callingFeatureId, "getNetworkCountryIsoForPhone")) { |
Jack Yu | 1e81ccd | 2019-09-26 11:48:33 -0700 | [diff] [blame] | 2092 | return ""; |
| 2093 | } |
| 2094 | } |
| 2095 | |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2096 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2097 | // registered cell info, so return a NULL country instead. |
| 2098 | final long identity = Binder.clearCallingIdentity(); |
| 2099 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2100 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2101 | // Get default phone in this case. |
| 2102 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2103 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2104 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 2105 | // Todo: fix this when we can get the actual cellular network info when the device |
| 2106 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2107 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2108 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(), |
| 2109 | mApp.getFeatureId())) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2110 | return ""; |
| 2111 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2112 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2113 | if (phone != null) { |
| 2114 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2115 | EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2116 | if (sst != null) { |
| 2117 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2118 | if (lt != null) { |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2119 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) { |
| 2120 | return lt.getCurrentCountry(); |
| 2121 | } else if (emergencyNumberTracker != null) { |
| 2122 | return emergencyNumberTracker.getEmergencyCountryIso(); |
| 2123 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2124 | } |
| 2125 | } |
| 2126 | } |
| 2127 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2128 | } finally { |
| 2129 | Binder.restoreCallingIdentity(identity); |
| 2130 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2131 | } |
| 2132 | |
| 2133 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2134 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2135 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2136 | } |
| 2137 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2138 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2139 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2140 | mApp.enforceCallingOrSelfPermission( |
| 2141 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2142 | |
| 2143 | final long identity = Binder.clearCallingIdentity(); |
| 2144 | try { |
| 2145 | final Phone phone = getPhone(subId); |
| 2146 | if (phone != null) { |
| 2147 | phone.enableLocationUpdates(); |
| 2148 | } |
| 2149 | } finally { |
| 2150 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2151 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2152 | } |
| 2153 | |
| 2154 | @Override |
| 2155 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2156 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2157 | } |
| 2158 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2159 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2160 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2161 | mApp.enforceCallingOrSelfPermission( |
| 2162 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2163 | |
| 2164 | final long identity = Binder.clearCallingIdentity(); |
| 2165 | try { |
| 2166 | final Phone phone = getPhone(subId); |
| 2167 | if (phone != null) { |
| 2168 | phone.disableLocationUpdates(); |
| 2169 | } |
| 2170 | } finally { |
| 2171 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2172 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2173 | } |
| 2174 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2175 | /** |
| 2176 | * Returns the target SDK version number for a given package name. |
| 2177 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2178 | * This call MUST be invoked before clearing the calling UID. |
| 2179 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2180 | * @return target SDK if the package is found or INT_MAX. |
| 2181 | */ |
| 2182 | private int getTargetSdk(String packageName) { |
| 2183 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2184 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 0150f0e | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2185 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2186 | if (ai != null) return ai.targetSdkVersion; |
| 2187 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2188 | loge("Failed to get package info for pkg=" |
| 2189 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2190 | } |
| 2191 | return Integer.MAX_VALUE; |
| 2192 | } |
| 2193 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2194 | @Override |
| 2195 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2196 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2197 | String callingFeatureId) { |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2198 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2199 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2200 | throw new SecurityException( |
| 2201 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2202 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2203 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2204 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2205 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2206 | return null; |
| 2207 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2208 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2209 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2210 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2211 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2212 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2213 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2214 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2215 | for (CellInfo ci : info) { |
| 2216 | if (ci instanceof CellInfoGsm) { |
| 2217 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2218 | } else if (ci instanceof CellInfoWcdma) { |
| 2219 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2220 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2221 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2222 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2223 | } |
| 2224 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2225 | private List<CellInfo> getCachedCellInfo() { |
| 2226 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2227 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2228 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2229 | if (info != null) cellInfos.addAll(info); |
| 2230 | } |
| 2231 | return cellInfos; |
| 2232 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2233 | |
| 2234 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2235 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2236 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2237 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2238 | |
| 2239 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2240 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2241 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2242 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2243 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2244 | .setCallingPid(Binder.getCallingPid()) |
| 2245 | .setCallingUid(Binder.getCallingUid()) |
| 2246 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2247 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2248 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2249 | .build()); |
| 2250 | switch (locationResult) { |
| 2251 | case DENIED_HARD: |
| 2252 | throw new SecurityException("Not allowed to access cell info"); |
| 2253 | case DENIED_SOFT: |
| 2254 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2255 | } |
| 2256 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2257 | final int targetSdk = getTargetSdk(callingPackage); |
| 2258 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2259 | return getCachedCellInfo(); |
| 2260 | } |
| 2261 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2262 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2263 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2264 | final long identity = Binder.clearCallingIdentity(); |
| 2265 | try { |
| 2266 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2267 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2268 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2269 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2270 | if (info != null) cellInfos.addAll(info); |
| 2271 | } |
| 2272 | return cellInfos; |
| 2273 | } finally { |
| 2274 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2275 | } |
| 2276 | } |
| 2277 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2278 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2279 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2280 | String callingFeatureId) { |
| 2281 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2282 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2283 | } |
| 2284 | |
| 2285 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2286 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2287 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2288 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2289 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2290 | } |
| 2291 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2292 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2293 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2294 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2295 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2296 | |
| 2297 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2298 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2299 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2300 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2301 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2302 | .setCallingPid(Binder.getCallingPid()) |
| 2303 | .setCallingUid(Binder.getCallingUid()) |
| 2304 | .setMethod("requestCellInfoUpdate") |
| 2305 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2306 | .build()); |
| 2307 | switch (locationResult) { |
| 2308 | case DENIED_HARD: |
| 2309 | throw new SecurityException("Not allowed to access cell info"); |
| 2310 | case DENIED_SOFT: |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2311 | try { |
| 2312 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2313 | } catch (RemoteException re) { |
| 2314 | // Drop without consequences |
| 2315 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2316 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2317 | } |
| 2318 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2319 | |
| 2320 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2321 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2322 | |
| 2323 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2324 | } |
| 2325 | |
| 2326 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2327 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2328 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2329 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2330 | |
| 2331 | final long identity = Binder.clearCallingIdentity(); |
| 2332 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2333 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2334 | } finally { |
| 2335 | Binder.restoreCallingIdentity(identity); |
| 2336 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2337 | } |
| 2338 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2339 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2340 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2341 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2342 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2343 | return null; |
| 2344 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2345 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2346 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2347 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2348 | return null; |
| 2349 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2350 | |
| 2351 | final long identity = Binder.clearCallingIdentity(); |
| 2352 | try { |
| 2353 | return phone.getImei(); |
| 2354 | } finally { |
| 2355 | Binder.restoreCallingIdentity(identity); |
| 2356 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2357 | } |
| 2358 | |
| 2359 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2360 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2361 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2362 | String tac = null; |
| 2363 | if (phone != null) { |
| 2364 | String imei = phone.getImei(); |
| 2365 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2366 | } |
| 2367 | return tac; |
| 2368 | } |
| 2369 | |
| 2370 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2371 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2372 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2373 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2374 | return null; |
| 2375 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2376 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2377 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2378 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2379 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2380 | return null; |
| 2381 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2382 | |
| 2383 | final long identity = Binder.clearCallingIdentity(); |
| 2384 | try { |
| 2385 | return phone.getMeid(); |
| 2386 | } finally { |
| 2387 | Binder.restoreCallingIdentity(identity); |
| 2388 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2389 | } |
| 2390 | |
| 2391 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2392 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2393 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2394 | String manufacturerCode = null; |
| 2395 | if (phone != null) { |
| 2396 | String meid = phone.getMeid(); |
| 2397 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2398 | } |
| 2399 | return manufacturerCode; |
| 2400 | } |
| 2401 | |
| 2402 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2403 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2404 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2405 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2406 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2407 | return null; |
| 2408 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2409 | int subId = phone.getSubId(); |
| 2410 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2411 | mApp, subId, callingPackage, callingFeatureId, |
| 2412 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2413 | return null; |
| 2414 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2415 | |
| 2416 | final long identity = Binder.clearCallingIdentity(); |
| 2417 | try { |
| 2418 | return phone.getDeviceSvn(); |
| 2419 | } finally { |
| 2420 | Binder.restoreCallingIdentity(identity); |
| 2421 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2422 | } |
| 2423 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2424 | @Override |
| 2425 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2426 | final long identity = Binder.clearCallingIdentity(); |
| 2427 | try { |
| 2428 | final Phone phone = getPhone(subId); |
| 2429 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2430 | } finally { |
| 2431 | Binder.restoreCallingIdentity(identity); |
| 2432 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2433 | } |
| 2434 | |
| 2435 | @Override |
| 2436 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2437 | final long identity = Binder.clearCallingIdentity(); |
| 2438 | try { |
| 2439 | final Phone phone = getPhone(subId); |
| 2440 | return phone == null ? null : phone.getCarrierName(); |
| 2441 | } finally { |
| 2442 | Binder.restoreCallingIdentity(identity); |
| 2443 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2444 | } |
| 2445 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2446 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2447 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2448 | final long identity = Binder.clearCallingIdentity(); |
| 2449 | try { |
| 2450 | final Phone phone = getPhone(subId); |
| 2451 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2452 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2453 | } finally { |
| 2454 | Binder.restoreCallingIdentity(identity); |
| 2455 | } |
| 2456 | } |
| 2457 | |
| 2458 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2459 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2460 | final long identity = Binder.clearCallingIdentity(); |
| 2461 | try { |
| 2462 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2463 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2464 | } finally { |
| 2465 | Binder.restoreCallingIdentity(identity); |
| 2466 | } |
| 2467 | } |
| 2468 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2469 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2470 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2471 | if (!isSubscriptionMccMnc) { |
| 2472 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2473 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2474 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2475 | if (phone == null) { |
| 2476 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2477 | } |
| 2478 | final long identity = Binder.clearCallingIdentity(); |
| 2479 | try { |
| 2480 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2481 | } finally { |
| 2482 | Binder.restoreCallingIdentity(identity); |
| 2483 | } |
| 2484 | } |
| 2485 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2486 | // |
| 2487 | // Internal helper methods. |
| 2488 | // |
| 2489 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2490 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2491 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2492 | * |
| 2493 | * @throws SecurityException if the caller does not have the required permission |
| 2494 | */ |
| 2495 | private void enforceModifyPermission() { |
| 2496 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2497 | } |
| 2498 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 2499 | private void enforceActiveEmergencySessionPermission() { |
| 2500 | mApp.enforceCallingOrSelfPermission( |
| 2501 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 2502 | } |
| 2503 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2504 | /** |
| 2505 | * Make sure the caller has the CALL_PHONE permission. |
| 2506 | * |
| 2507 | * @throws SecurityException if the caller does not have the required permission |
| 2508 | */ |
| 2509 | private void enforceCallPermission() { |
| 2510 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2511 | } |
| 2512 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 2513 | private void enforceSettingsPermission() { |
| 2514 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2515 | } |
| 2516 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2517 | private String createTelUrl(String number) { |
| 2518 | if (TextUtils.isEmpty(number)) { |
| 2519 | return null; |
| 2520 | } |
| 2521 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2522 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2523 | } |
| 2524 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2525 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2526 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2527 | } |
| 2528 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2529 | private static void logv(String msg) { |
| 2530 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2531 | } |
| 2532 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2533 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2534 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2535 | } |
| 2536 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2537 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2538 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2539 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2540 | } |
| 2541 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2542 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2543 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2544 | final long identity = Binder.clearCallingIdentity(); |
| 2545 | try { |
| 2546 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2547 | if (phone == null) { |
| 2548 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2549 | } else { |
| 2550 | return phone.getPhoneType(); |
| 2551 | } |
| 2552 | } finally { |
| 2553 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2554 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2555 | } |
| 2556 | |
| 2557 | /** |
| 2558 | * Returns the CDMA ERI icon index to display |
| 2559 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2560 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2561 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 2562 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 2563 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2564 | } |
| 2565 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2566 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2567 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 2568 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2569 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2570 | mApp, subId, callingPackage, callingFeatureId, |
| 2571 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2572 | return -1; |
| 2573 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2574 | |
| 2575 | final long identity = Binder.clearCallingIdentity(); |
| 2576 | try { |
| 2577 | final Phone phone = getPhone(subId); |
| 2578 | if (phone != null) { |
| 2579 | return phone.getCdmaEriIconIndex(); |
| 2580 | } else { |
| 2581 | return -1; |
| 2582 | } |
| 2583 | } finally { |
| 2584 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2585 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2586 | } |
| 2587 | |
| 2588 | /** |
| 2589 | * Returns the CDMA ERI icon mode, |
| 2590 | * 0 - ON |
| 2591 | * 1 - FLASHING |
| 2592 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2593 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2594 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 2595 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 2596 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2597 | } |
| 2598 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2599 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2600 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 2601 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2602 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2603 | mApp, subId, callingPackage, callingFeatureId, |
| 2604 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2605 | return -1; |
| 2606 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2607 | |
| 2608 | final long identity = Binder.clearCallingIdentity(); |
| 2609 | try { |
| 2610 | final Phone phone = getPhone(subId); |
| 2611 | if (phone != null) { |
| 2612 | return phone.getCdmaEriIconMode(); |
| 2613 | } else { |
| 2614 | return -1; |
| 2615 | } |
| 2616 | } finally { |
| 2617 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2618 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2619 | } |
| 2620 | |
| 2621 | /** |
| 2622 | * Returns the CDMA ERI text, |
| 2623 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2624 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2625 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 2626 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 2627 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2628 | } |
| 2629 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2630 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2631 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 2632 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2633 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2634 | mApp, subId, callingPackage, callingFeatureId, |
| 2635 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2636 | return null; |
| 2637 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2638 | |
| 2639 | final long identity = Binder.clearCallingIdentity(); |
| 2640 | try { |
| 2641 | final Phone phone = getPhone(subId); |
| 2642 | if (phone != null) { |
| 2643 | return phone.getCdmaEriText(); |
| 2644 | } else { |
| 2645 | return null; |
| 2646 | } |
| 2647 | } finally { |
| 2648 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2649 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2650 | } |
| 2651 | |
| 2652 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2653 | * Returns the CDMA MDN. |
| 2654 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2655 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2656 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2657 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2658 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2659 | |
| 2660 | final long identity = Binder.clearCallingIdentity(); |
| 2661 | try { |
| 2662 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2663 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2664 | return phone.getLine1Number(); |
| 2665 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2666 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2667 | return null; |
| 2668 | } |
| 2669 | } finally { |
| 2670 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2671 | } |
| 2672 | } |
| 2673 | |
| 2674 | /** |
| 2675 | * Returns the CDMA MIN. |
| 2676 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2677 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2678 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2679 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2680 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2681 | |
| 2682 | final long identity = Binder.clearCallingIdentity(); |
| 2683 | try { |
| 2684 | final Phone phone = getPhone(subId); |
| 2685 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2686 | return phone.getCdmaMin(); |
| 2687 | } else { |
| 2688 | return null; |
| 2689 | } |
| 2690 | } finally { |
| 2691 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2692 | } |
| 2693 | } |
| 2694 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2695 | @Override |
| 2696 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2697 | INumberVerificationCallback callback, String callingPackage) { |
| 2698 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2699 | != PERMISSION_GRANTED) { |
| 2700 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2701 | } |
| 2702 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2703 | |
| 2704 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2705 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2706 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2707 | } |
| 2708 | |
| 2709 | if (range == null) { |
| 2710 | throw new NullPointerException("Range must be non-null"); |
| 2711 | } |
| 2712 | |
| 2713 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2714 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2715 | |
| 2716 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2717 | } |
| 2718 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2719 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2720 | * Returns true if CDMA provisioning needs to run. |
| 2721 | */ |
| 2722 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2723 | final long identity = Binder.clearCallingIdentity(); |
| 2724 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2725 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2726 | } finally { |
| 2727 | Binder.restoreCallingIdentity(identity); |
| 2728 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2729 | } |
| 2730 | |
| 2731 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2732 | * Sets the voice mail number of a given subId. |
| 2733 | */ |
| 2734 | @Override |
| 2735 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 2736 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2737 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2738 | |
| 2739 | final long identity = Binder.clearCallingIdentity(); |
| 2740 | try { |
| 2741 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2742 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2743 | return success; |
| 2744 | } finally { |
| 2745 | Binder.restoreCallingIdentity(identity); |
| 2746 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2747 | } |
| 2748 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2749 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2750 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2751 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 2752 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 2753 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2754 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2755 | throw new SecurityException("caller must be system dialer"); |
| 2756 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2757 | |
| 2758 | final long identity = Binder.clearCallingIdentity(); |
| 2759 | try { |
| 2760 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2761 | if (phoneAccountHandle == null) { |
| 2762 | return null; |
| 2763 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2764 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2765 | } finally { |
| 2766 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2767 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2768 | } |
| 2769 | |
| 2770 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2771 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 2772 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2773 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2774 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2775 | mApp, subId, callingPackage, callingFeatureId, |
| 2776 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2777 | return null; |
| 2778 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2779 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2780 | final long identity = Binder.clearCallingIdentity(); |
| 2781 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2782 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2783 | } finally { |
| 2784 | Binder.restoreCallingIdentity(identity); |
| 2785 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2786 | } |
| 2787 | |
| 2788 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2789 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2790 | VisualVoicemailSmsFilterSettings settings) { |
| 2791 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2792 | |
| 2793 | final long identity = Binder.clearCallingIdentity(); |
| 2794 | try { |
| 2795 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2796 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2797 | } finally { |
| 2798 | Binder.restoreCallingIdentity(identity); |
| 2799 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2800 | } |
| 2801 | |
| 2802 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2803 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2804 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2805 | |
| 2806 | final long identity = Binder.clearCallingIdentity(); |
| 2807 | try { |
| 2808 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2809 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2810 | } finally { |
| 2811 | Binder.restoreCallingIdentity(identity); |
| 2812 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2813 | } |
| 2814 | |
| 2815 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2816 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2817 | String callingPackage, int subId) { |
| 2818 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2819 | |
| 2820 | final long identity = Binder.clearCallingIdentity(); |
| 2821 | try { |
| 2822 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2823 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2824 | } finally { |
| 2825 | Binder.restoreCallingIdentity(identity); |
| 2826 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2827 | } |
| 2828 | |
| 2829 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2830 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2831 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2832 | |
| 2833 | final long identity = Binder.clearCallingIdentity(); |
| 2834 | try { |
| 2835 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2836 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2837 | } finally { |
| 2838 | Binder.restoreCallingIdentity(identity); |
| 2839 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2840 | } |
| 2841 | |
| 2842 | @Override |
| 2843 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2844 | String number, int port, String text, PendingIntent sentIntent) { |
| 2845 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2846 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2847 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2848 | SmsController smsController = PhoneFactory.getSmsController(); |
| 2849 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text, |
| 2850 | sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2851 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2852 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2853 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2854 | * Sets the voice activation state of a given subId. |
| 2855 | */ |
| 2856 | @Override |
| 2857 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2858 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2859 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2860 | |
| 2861 | final long identity = Binder.clearCallingIdentity(); |
| 2862 | try { |
| 2863 | final Phone phone = getPhone(subId); |
| 2864 | if (phone != null) { |
| 2865 | phone.setVoiceActivationState(activationState); |
| 2866 | } else { |
| 2867 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2868 | } |
| 2869 | } finally { |
| 2870 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2871 | } |
| 2872 | } |
| 2873 | |
| 2874 | /** |
| 2875 | * Sets the data activation state of a given subId. |
| 2876 | */ |
| 2877 | @Override |
| 2878 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2879 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2880 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2881 | |
| 2882 | final long identity = Binder.clearCallingIdentity(); |
| 2883 | try { |
| 2884 | final Phone phone = getPhone(subId); |
| 2885 | if (phone != null) { |
| 2886 | phone.setDataActivationState(activationState); |
| 2887 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 2888 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2889 | } |
| 2890 | } finally { |
| 2891 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2892 | } |
| 2893 | } |
| 2894 | |
| 2895 | /** |
| 2896 | * Returns the voice activation state of a given subId. |
| 2897 | */ |
| 2898 | @Override |
| 2899 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2900 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2901 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2902 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2903 | final long identity = Binder.clearCallingIdentity(); |
| 2904 | try { |
| 2905 | if (phone != null) { |
| 2906 | return phone.getVoiceActivationState(); |
| 2907 | } else { |
| 2908 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2909 | } |
| 2910 | } finally { |
| 2911 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2912 | } |
| 2913 | } |
| 2914 | |
| 2915 | /** |
| 2916 | * Returns the data activation state of a given subId. |
| 2917 | */ |
| 2918 | @Override |
| 2919 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2920 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2921 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2922 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2923 | final long identity = Binder.clearCallingIdentity(); |
| 2924 | try { |
| 2925 | if (phone != null) { |
| 2926 | return phone.getDataActivationState(); |
| 2927 | } else { |
| 2928 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2929 | } |
| 2930 | } finally { |
| 2931 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2932 | } |
| 2933 | } |
| 2934 | |
| 2935 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2936 | * Returns the unread count of voicemails for a subId |
| 2937 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2938 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2939 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 2940 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2941 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2942 | mApp, subId, callingPackage, callingFeatureId, |
| 2943 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2944 | return 0; |
| 2945 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2946 | final long identity = Binder.clearCallingIdentity(); |
| 2947 | try { |
| 2948 | final Phone phone = getPhone(subId); |
| 2949 | if (phone != null) { |
| 2950 | return phone.getVoiceMessageCount(); |
| 2951 | } else { |
| 2952 | return 0; |
| 2953 | } |
| 2954 | } finally { |
| 2955 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2956 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2957 | } |
| 2958 | |
| 2959 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2960 | * returns true, if the device is in a state where both voice and data |
| 2961 | * are supported simultaneously. This can change based on location or network condition. |
| 2962 | */ |
| 2963 | @Override |
| 2964 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2965 | final long identity = Binder.clearCallingIdentity(); |
| 2966 | try { |
| 2967 | final Phone phone = getPhone(subId); |
| 2968 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 2969 | } finally { |
| 2970 | Binder.restoreCallingIdentity(identity); |
| 2971 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2972 | } |
| 2973 | |
| 2974 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2975 | * Send the dialer code if called from the current default dialer or the caller has |
| 2976 | * carrier privilege. |
| 2977 | * @param inputCode The dialer code to send |
| 2978 | */ |
| 2979 | @Override |
| 2980 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2981 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2982 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 2983 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 2984 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2985 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 2986 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2987 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2988 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2989 | |
| 2990 | final long identity = Binder.clearCallingIdentity(); |
| 2991 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2992 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2993 | } finally { |
| 2994 | Binder.restoreCallingIdentity(identity); |
| 2995 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2996 | } |
| 2997 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2998 | @Override |
| 2999 | public int getNetworkSelectionMode(int subId) { |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3000 | if (!isActiveSubscription(subId)) { |
| 3001 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3002 | } |
| 3003 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3004 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3005 | } |
| 3006 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3007 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3008 | public boolean isInEmergencySmsMode() { |
| 3009 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3010 | final long identity = Binder.clearCallingIdentity(); |
| 3011 | try { |
| 3012 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3013 | if (phone.isInEmergencySmsMode()) { |
| 3014 | return true; |
| 3015 | } |
| 3016 | } |
| 3017 | } finally { |
| 3018 | Binder.restoreCallingIdentity(identity); |
| 3019 | } |
| 3020 | return false; |
| 3021 | } |
| 3022 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3023 | /** |
| 3024 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3025 | * @param subId The subscription to use to check the configuration. |
| 3026 | * @param c The callback that will be used to send the result. |
| 3027 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3028 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3029 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3030 | throws RemoteException { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3031 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3032 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3033 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3034 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3035 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3036 | "IMS not available on device."); |
| 3037 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3038 | final long token = Binder.clearCallingIdentity(); |
| 3039 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3040 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3041 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3042 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3043 | } catch (ImsException e) { |
| 3044 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3045 | } finally { |
| 3046 | Binder.restoreCallingIdentity(token); |
| 3047 | } |
| 3048 | } |
| 3049 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3050 | /** |
| 3051 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3052 | * @param subId The subscription to use to check the configuration. |
| 3053 | * @param c The callback that will be used to send the result. |
| 3054 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3055 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3056 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3057 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3058 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3059 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3060 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3061 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3062 | final long token = Binder.clearCallingIdentity(); |
| 3063 | try { |
| 3064 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3065 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3066 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3067 | } catch (ImsException e) { |
| 3068 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3069 | + "is inactive, ignoring unregister."); |
| 3070 | // If the subscription is no longer active, just return, since the callback |
| 3071 | // will already have been removed internally. |
| 3072 | } finally { |
| 3073 | Binder.restoreCallingIdentity(token); |
| 3074 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3075 | } |
| 3076 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3077 | /** |
| 3078 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3079 | */ |
| 3080 | @Override |
| 3081 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3082 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3083 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3084 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3085 | "IMS not available on device."); |
| 3086 | } |
| 3087 | final long token = Binder.clearCallingIdentity(); |
| 3088 | try { |
| 3089 | Phone phone = getPhone(subId); |
| 3090 | if (phone == null) { |
| 3091 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3092 | + subId + "'"); |
| 3093 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3094 | } |
| 3095 | phone.getImsRegistrationState(regState -> { |
| 3096 | try { |
| 3097 | consumer.accept((regState == null) |
| 3098 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3099 | } catch (RemoteException e) { |
| 3100 | // Ignore if the remote process is no longer available to call back. |
| 3101 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3102 | } |
| 3103 | }); |
| 3104 | } finally { |
| 3105 | Binder.restoreCallingIdentity(token); |
| 3106 | } |
| 3107 | } |
| 3108 | |
| 3109 | /** |
| 3110 | * Get the transport type for the IMS service registration state. |
| 3111 | */ |
| 3112 | @Override |
| 3113 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3114 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3115 | enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType"); |
| 3116 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3117 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3118 | "IMS not available on device."); |
| 3119 | } |
| 3120 | final long token = Binder.clearCallingIdentity(); |
| 3121 | try { |
| 3122 | Phone phone = getPhone(subId); |
| 3123 | if (phone == null) { |
| 3124 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3125 | + subId + "'"); |
| 3126 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3127 | } |
| 3128 | phone.getImsRegistrationTech(regTech -> { |
| 3129 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3130 | int regTechConverted = (regTech == null) |
| 3131 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3132 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3133 | regTechConverted); |
| 3134 | try { |
| 3135 | consumer.accept(regTechConverted); |
| 3136 | } catch (RemoteException e) { |
| 3137 | // Ignore if the remote process is no longer available to call back. |
| 3138 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3139 | } |
| 3140 | }); |
| 3141 | } finally { |
| 3142 | Binder.restoreCallingIdentity(token); |
| 3143 | } |
| 3144 | } |
| 3145 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3146 | /** |
| 3147 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3148 | * @param subId The subscription to use to check the configuration. |
| 3149 | * @param c The callback that will be used to send the result. |
| 3150 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3151 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3152 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3153 | throws RemoteException { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3154 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3155 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3156 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3157 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3158 | "IMS not available on device."); |
| 3159 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3160 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3161 | final long token = Binder.clearCallingIdentity(); |
| 3162 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3163 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3164 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3165 | } catch (ImsException e) { |
| 3166 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3167 | } finally { |
| 3168 | Binder.restoreCallingIdentity(token); |
| 3169 | } |
| 3170 | } |
| 3171 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3172 | /** |
| 3173 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3174 | * @param subId The subscription to use to check the configuration. |
| 3175 | * @param c The callback that will be used to send the result. |
| 3176 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3177 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3178 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3179 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3180 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3181 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3182 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3183 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3184 | |
| 3185 | final long token = Binder.clearCallingIdentity(); |
| 3186 | try { |
| 3187 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3188 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3189 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3190 | } catch (ImsException e) { |
| 3191 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3192 | + "is inactive, ignoring unregister."); |
| 3193 | // If the subscription is no longer active, just return, since the callback |
| 3194 | // will already have been removed internally. |
| 3195 | } finally { |
| 3196 | Binder.restoreCallingIdentity(token); |
| 3197 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3198 | } |
| 3199 | |
| 3200 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3201 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3202 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3203 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3204 | final long token = Binder.clearCallingIdentity(); |
| 3205 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3206 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3207 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3208 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3209 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3210 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3211 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3212 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3213 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3214 | } finally { |
| 3215 | Binder.restoreCallingIdentity(token); |
| 3216 | } |
| 3217 | } |
| 3218 | |
| 3219 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3220 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3221 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3222 | final long token = Binder.clearCallingIdentity(); |
| 3223 | try { |
| 3224 | Phone phone = getPhone(subId); |
| 3225 | if (phone == null) return false; |
| 3226 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 3227 | } finally { |
| 3228 | Binder.restoreCallingIdentity(token); |
| 3229 | } |
| 3230 | } |
| 3231 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3232 | /** |
| 3233 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3234 | * subscription. |
| 3235 | * @param subId The subscription to use to check the configuration. |
| 3236 | * @param callback The callback that will be used to send the result. |
| 3237 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3238 | * @param transportType The transport type of the MmTelFeature capability. |
| 3239 | */ |
| 3240 | @Override |
| 3241 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3242 | int transportType) { |
| 3243 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3244 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3245 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3246 | "IMS not available on device."); |
| 3247 | } |
| 3248 | final long token = Binder.clearCallingIdentity(); |
| 3249 | try { |
| 3250 | int slotId = getSlotIndex(subId); |
| 3251 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3252 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3253 | + subId + "'"); |
| 3254 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3255 | } |
| 3256 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3257 | transportType, aBoolean -> { |
| 3258 | try { |
| 3259 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3260 | } catch (RemoteException e) { |
| 3261 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3262 | + "running. Ignore"); |
| 3263 | } |
| 3264 | }); |
| 3265 | } finally { |
| 3266 | Binder.restoreCallingIdentity(token); |
| 3267 | } |
| 3268 | } |
| 3269 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3270 | /** |
| 3271 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3272 | * @param subId The subscription to use to check the configuration. |
| 3273 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3274 | @Override |
| 3275 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3276 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
| 3277 | enforceReadPrivilegedPermission("isAdvancedCallingSettingEnabled"); |
| 3278 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3279 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3280 | final long token = Binder.clearCallingIdentity(); |
| 3281 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3282 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3283 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3284 | } catch (ImsException e) { |
| 3285 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3286 | } finally { |
| 3287 | Binder.restoreCallingIdentity(token); |
| 3288 | } |
| 3289 | } |
| 3290 | |
| 3291 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3292 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3293 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3294 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3295 | final long identity = Binder.clearCallingIdentity(); |
| 3296 | try { |
| 3297 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3298 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3299 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3300 | } catch (ImsException e) { |
| 3301 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3302 | } finally { |
| 3303 | Binder.restoreCallingIdentity(identity); |
| 3304 | } |
| 3305 | } |
| 3306 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3307 | /** |
| 3308 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3309 | * @param subId The subscription to use to check the configuration. |
| 3310 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3311 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3312 | public boolean isVtSettingEnabled(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3313 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3314 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3315 | final long identity = Binder.clearCallingIdentity(); |
| 3316 | try { |
| 3317 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3318 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3319 | } catch (ImsException e) { |
| 3320 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3321 | } finally { |
| 3322 | Binder.restoreCallingIdentity(identity); |
| 3323 | } |
| 3324 | } |
| 3325 | |
| 3326 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3327 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3328 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3329 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3330 | final long identity = Binder.clearCallingIdentity(); |
| 3331 | try { |
| 3332 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3333 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3334 | } catch (ImsException e) { |
| 3335 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3336 | } finally { |
| 3337 | Binder.restoreCallingIdentity(identity); |
| 3338 | } |
| 3339 | } |
| 3340 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3341 | /** |
| 3342 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3343 | * @param subId The subscription to use to check the configuration. |
| 3344 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3345 | @Override |
| 3346 | public boolean isVoWiFiSettingEnabled(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3347 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3348 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 3349 | final long identity = Binder.clearCallingIdentity(); |
| 3350 | try { |
| 3351 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3352 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3353 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3354 | } catch (ImsException e) { |
| 3355 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3356 | } finally { |
| 3357 | Binder.restoreCallingIdentity(identity); |
| 3358 | } |
| 3359 | } |
| 3360 | |
| 3361 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3362 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3363 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3364 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3365 | final long identity = Binder.clearCallingIdentity(); |
| 3366 | try { |
| 3367 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3368 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3369 | } catch (ImsException e) { |
| 3370 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3371 | } finally { |
| 3372 | Binder.restoreCallingIdentity(identity); |
| 3373 | } |
| 3374 | } |
| 3375 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3376 | /** |
| 3377 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3378 | * @param subId The subscription to use to check the configuration. |
| 3379 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3380 | @Override |
| 3381 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3382 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3383 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 3384 | final long identity = Binder.clearCallingIdentity(); |
| 3385 | try { |
| 3386 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3387 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3388 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3389 | } catch (ImsException e) { |
| 3390 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3391 | } finally { |
| 3392 | Binder.restoreCallingIdentity(identity); |
| 3393 | } |
| 3394 | } |
| 3395 | |
| 3396 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3397 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3398 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3399 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3400 | final long identity = Binder.clearCallingIdentity(); |
| 3401 | try { |
| 3402 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3403 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3404 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3405 | } catch (ImsException e) { |
| 3406 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3407 | } finally { |
| 3408 | Binder.restoreCallingIdentity(identity); |
| 3409 | } |
| 3410 | } |
| 3411 | |
| 3412 | @Override |
| 3413 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3414 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3415 | "setVoWiFiNonPersistent"); |
| 3416 | final long identity = Binder.clearCallingIdentity(); |
| 3417 | try { |
| 3418 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3419 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3420 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3421 | } catch (ImsException e) { |
| 3422 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3423 | } finally { |
| 3424 | Binder.restoreCallingIdentity(identity); |
| 3425 | } |
| 3426 | } |
| 3427 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3428 | /** |
| 3429 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3430 | * @param subId The subscription to use to check the configuration. |
| 3431 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3432 | @Override |
| 3433 | public int getVoWiFiModeSetting(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3434 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3435 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 3436 | final long identity = Binder.clearCallingIdentity(); |
| 3437 | try { |
| 3438 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3439 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3440 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3441 | } catch (ImsException e) { |
| 3442 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3443 | } finally { |
| 3444 | Binder.restoreCallingIdentity(identity); |
| 3445 | } |
| 3446 | } |
| 3447 | |
| 3448 | @Override |
| 3449 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3450 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3451 | "setVoWiFiModeSetting"); |
| 3452 | final long identity = Binder.clearCallingIdentity(); |
| 3453 | try { |
| 3454 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3455 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3456 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3457 | } catch (ImsException e) { |
| 3458 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3459 | } finally { |
| 3460 | Binder.restoreCallingIdentity(identity); |
| 3461 | } |
| 3462 | } |
| 3463 | |
| 3464 | @Override |
| 3465 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3466 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3467 | final long identity = Binder.clearCallingIdentity(); |
| 3468 | try { |
| 3469 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3470 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3471 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3472 | } catch (ImsException e) { |
| 3473 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3474 | } finally { |
| 3475 | Binder.restoreCallingIdentity(identity); |
| 3476 | } |
| 3477 | } |
| 3478 | |
| 3479 | @Override |
| 3480 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3481 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3482 | "setVoWiFiRoamingModeSetting"); |
| 3483 | final long identity = Binder.clearCallingIdentity(); |
| 3484 | try { |
| 3485 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3486 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3487 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3488 | } catch (ImsException e) { |
| 3489 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3490 | } finally { |
| 3491 | Binder.restoreCallingIdentity(identity); |
| 3492 | } |
| 3493 | } |
| 3494 | |
| 3495 | @Override |
| 3496 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3497 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3498 | "setRttCapabilityEnabled"); |
| 3499 | final long identity = Binder.clearCallingIdentity(); |
| 3500 | try { |
| 3501 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3502 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3503 | } catch (ImsException e) { |
| 3504 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3505 | } finally { |
| 3506 | Binder.restoreCallingIdentity(identity); |
| 3507 | } |
| 3508 | } |
| 3509 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3510 | /** |
| 3511 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3512 | * @param subId The subscription to use to check the configuration. |
| 3513 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3514 | @Override |
| 3515 | public boolean isTtyOverVolteEnabled(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3516 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3517 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 3518 | final long identity = Binder.clearCallingIdentity(); |
| 3519 | try { |
| 3520 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3521 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3522 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3523 | } catch (ImsException e) { |
| 3524 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3525 | } finally { |
| 3526 | Binder.restoreCallingIdentity(identity); |
| 3527 | } |
| 3528 | } |
| 3529 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3530 | @Override |
| 3531 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3532 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3533 | final long identity = Binder.clearCallingIdentity(); |
| 3534 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 3535 | if (!isImsAvailableOnDevice()) { |
| 3536 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3537 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 3538 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3539 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3540 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3541 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3542 | } catch (ImsException e) { |
| 3543 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3544 | } finally { |
| 3545 | Binder.restoreCallingIdentity(identity); |
| 3546 | } |
| 3547 | } |
| 3548 | |
| 3549 | @Override |
| 3550 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3551 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3552 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3553 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3554 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3555 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3556 | try { |
| 3557 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3558 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3559 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3560 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3561 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3562 | + "is inactive, ignoring unregister."); |
| 3563 | // If the subscription is no longer active, just return, since the callback will already |
| 3564 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3565 | } finally { |
| 3566 | Binder.restoreCallingIdentity(identity); |
| 3567 | } |
| 3568 | } |
| 3569 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3570 | |
| 3571 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 3572 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3573 | message); |
| 3574 | } |
| 3575 | |
| 3576 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 3577 | boolean isMmtelCapability) { |
| 3578 | Phone phone = getPhone(subId); |
| 3579 | if (phone == null) { |
| 3580 | loge("phone instance null for subid " + subId); |
| 3581 | return false; |
| 3582 | } |
| 3583 | if (isMmtelCapability) { |
| 3584 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3585 | return false; |
| 3586 | } |
| 3587 | } else { |
| 3588 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3589 | return false; |
| 3590 | } |
| 3591 | } |
| 3592 | return true; |
| 3593 | } |
| 3594 | |
| 3595 | @Override |
| 3596 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 3597 | boolean isProvisioned) { |
| 3598 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 3599 | |
| 3600 | final long identity = Binder.clearCallingIdentity(); |
| 3601 | try { |
| 3602 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3603 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3604 | return; |
| 3605 | } |
| 3606 | |
| 3607 | // this capability requires provisioning, route to the correct API. |
| 3608 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3609 | switch (capability) { |
| 3610 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3611 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3612 | ims.setEabProvisioned(isProvisioned); |
| 3613 | break; |
| 3614 | default: { |
| 3615 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3616 | + "rcs capability '" + capability + "', which does not require " |
| 3617 | + "provisioning."); |
| 3618 | } |
| 3619 | } |
| 3620 | } finally { |
| 3621 | Binder.restoreCallingIdentity(identity); |
| 3622 | } |
| 3623 | |
| 3624 | } |
| 3625 | |
| 3626 | |
| 3627 | @Override |
| 3628 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 3629 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 3630 | final long identity = Binder.clearCallingIdentity(); |
| 3631 | try { |
| 3632 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3633 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3634 | return true; |
| 3635 | } |
| 3636 | |
| 3637 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3638 | switch (capability) { |
| 3639 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3640 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3641 | return ims.isEabProvisionedOnDevice(); |
| 3642 | |
| 3643 | default: { |
| 3644 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 3645 | + "capability '" + capability + "', which does not require " |
| 3646 | + "provisioning."); |
| 3647 | } |
| 3648 | } |
| 3649 | |
| 3650 | } finally { |
| 3651 | Binder.restoreCallingIdentity(identity); |
| 3652 | } |
| 3653 | } |
| 3654 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3655 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3656 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3657 | boolean isProvisioned) { |
| 3658 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3659 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3660 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3661 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3662 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3663 | final long identity = Binder.clearCallingIdentity(); |
| 3664 | try { |
| 3665 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3666 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3667 | return; |
| 3668 | } |
| 3669 | |
| 3670 | // this capability requires provisioning, route to the correct API. |
| 3671 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3672 | switch (capability) { |
| 3673 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3674 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3675 | ims.setVolteProvisioned(isProvisioned); |
| 3676 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3677 | ims.setWfcProvisioned(isProvisioned); |
| 3678 | } |
| 3679 | break; |
| 3680 | } |
| 3681 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3682 | // There is currently no difference in VT provisioning type. |
| 3683 | ims.setVtProvisioned(isProvisioned); |
| 3684 | break; |
| 3685 | } |
| 3686 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3687 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3688 | // change the capability of the feature instead if needed. |
| 3689 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3690 | == isProvisioned) { |
| 3691 | // No change in provisioning. |
| 3692 | return; |
| 3693 | } |
| 3694 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3695 | try { |
| 3696 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3697 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3698 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3699 | + ", Exception" + e.getMessage()); |
| 3700 | } |
| 3701 | break; |
| 3702 | } |
| 3703 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3704 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3705 | + "MmTel capability '" + capability + "', which does not require " |
| 3706 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3707 | } |
| 3708 | } |
| 3709 | |
| 3710 | } finally { |
| 3711 | Binder.restoreCallingIdentity(identity); |
| 3712 | } |
| 3713 | } |
| 3714 | |
| 3715 | @Override |
| 3716 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3717 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3718 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3719 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3720 | } |
| 3721 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3722 | final long identity = Binder.clearCallingIdentity(); |
| 3723 | try { |
| 3724 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3725 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3726 | return true; |
| 3727 | } |
| 3728 | |
| 3729 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3730 | switch (capability) { |
| 3731 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3732 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3733 | return ims.isVolteProvisionedOnDevice(); |
| 3734 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3735 | return ims.isWfcProvisionedOnDevice(); |
| 3736 | } |
| 3737 | // This should never happen, since we are checking tech above to make sure it |
| 3738 | // is either LTE or IWLAN. |
| 3739 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3740 | + "capability."); |
| 3741 | } |
| 3742 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3743 | // There is currently no difference in VT provisioning type. |
| 3744 | return ims.isVtProvisionedOnDevice(); |
| 3745 | } |
| 3746 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3747 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3748 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3749 | } |
| 3750 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3751 | throw new IllegalArgumentException( |
| 3752 | "Tried to get provisioning for MmTel capability '" + capability |
| 3753 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3754 | } |
| 3755 | } |
| 3756 | |
| 3757 | } finally { |
| 3758 | Binder.restoreCallingIdentity(identity); |
| 3759 | } |
| 3760 | } |
| 3761 | |
| 3762 | @Override |
| 3763 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3764 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3765 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3766 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3767 | } |
| 3768 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3769 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3770 | return (provisionedBits & capability) > 0; |
| 3771 | } |
| 3772 | |
| 3773 | @Override |
| 3774 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3775 | boolean isProvisioned) { |
| 3776 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3777 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3778 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3779 | } |
| 3780 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3781 | "setProvisioningStatusForCapability"); |
| 3782 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3783 | // If the current provisioning status for capability already matches isProvisioned, |
| 3784 | // do nothing. |
| 3785 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3786 | return; |
| 3787 | } |
| 3788 | if (isProvisioned) { |
| 3789 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3790 | } else { |
| 3791 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3792 | } |
| 3793 | } |
| 3794 | |
| 3795 | /** |
| 3796 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 3797 | * technology. The bitfield should mirror the bitfield defined by |
| 3798 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 3799 | */ |
| 3800 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 3801 | String key = getMmTelProvisioningKey(subId, tech); |
| 3802 | // Default is no capabilities are provisioned. |
| 3803 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 3804 | } |
| 3805 | |
| 3806 | /** |
| 3807 | * Sets the MmTel capability provisioning bitfield (defined by |
| 3808 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 3809 | * technology specified. |
| 3810 | * |
| 3811 | * Note: This is a synchronous command and should not be called on UI thread. |
| 3812 | */ |
| 3813 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 3814 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 3815 | String key = getMmTelProvisioningKey(subId, tech); |
| 3816 | editor.putInt(key, newField); |
| 3817 | editor.commit(); |
| 3818 | } |
| 3819 | |
| 3820 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 3821 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 3822 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 3823 | } |
| 3824 | |
| 3825 | /** |
| 3826 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 3827 | * carrier associated with the subscription id. |
| 3828 | */ |
| 3829 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 3830 | int capability) { |
| 3831 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 3832 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 3833 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 3834 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3835 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 3836 | false); |
| 3837 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 3838 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 3839 | |
| 3840 | // First check to make sure that the capability requires provisioning. |
| 3841 | switch (capability) { |
| 3842 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 3843 | // intentional fallthrough |
| 3844 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3845 | if (requireVoiceVtProvisioning) { |
| 3846 | // Voice and Video requires provisioning |
| 3847 | return true; |
| 3848 | } |
| 3849 | break; |
| 3850 | } |
| 3851 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3852 | if (requireUtProvisioning) { |
| 3853 | // UT requires provisioning |
| 3854 | return true; |
| 3855 | } |
| 3856 | break; |
| 3857 | } |
| 3858 | } |
| 3859 | return false; |
| 3860 | } |
| 3861 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3862 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 3863 | int capability) { |
| 3864 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 3865 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 3866 | |
| 3867 | boolean requireRcsProvisioning = c.getBoolean( |
| 3868 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 3869 | |
| 3870 | // First check to make sure that the capability requires provisioning. |
| 3871 | switch (capability) { |
| 3872 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3873 | // intentional fallthrough |
| 3874 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 3875 | if (requireRcsProvisioning) { |
| 3876 | // OPTION or PRESENCE requires provisioning |
| 3877 | return true; |
| 3878 | } |
| 3879 | break; |
| 3880 | } |
| 3881 | } |
| 3882 | return false; |
| 3883 | } |
| 3884 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3885 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3886 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3887 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3888 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3889 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3890 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 3891 | final long identity = Binder.clearCallingIdentity(); |
| 3892 | try { |
| 3893 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3894 | int slotId = getSlotIndex(subId); |
| 3895 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3896 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 3897 | + subId + "' for key:" + key); |
| 3898 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 3899 | } |
| 3900 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3901 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3902 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 3903 | + subId + "' for key:" + key); |
| 3904 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3905 | } finally { |
| 3906 | Binder.restoreCallingIdentity(identity); |
| 3907 | } |
| 3908 | } |
| 3909 | |
| 3910 | @Override |
| 3911 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3912 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3913 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3914 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3915 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 3916 | final long identity = Binder.clearCallingIdentity(); |
| 3917 | try { |
| 3918 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3919 | int slotId = getSlotIndex(subId); |
| 3920 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3921 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 3922 | + subId + "' for key:" + key); |
| 3923 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 3924 | } |
| 3925 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3926 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3927 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 3928 | + subId + "' for key:" + key); |
| 3929 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3930 | } finally { |
| 3931 | Binder.restoreCallingIdentity(identity); |
| 3932 | } |
| 3933 | } |
| 3934 | |
| 3935 | @Override |
| 3936 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3937 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3938 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3939 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3940 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3941 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3942 | final long identity = Binder.clearCallingIdentity(); |
| 3943 | try { |
| 3944 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3945 | int slotId = getSlotIndex(subId); |
| 3946 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3947 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 3948 | + subId + "' for key:" + key); |
| 3949 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3950 | } |
| 3951 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3952 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3953 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 3954 | + "' for key:" + key); |
| 3955 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3956 | } finally { |
| 3957 | Binder.restoreCallingIdentity(identity); |
| 3958 | } |
| 3959 | } |
| 3960 | |
| 3961 | @Override |
| 3962 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3963 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3964 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3965 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3966 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3967 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3968 | final long identity = Binder.clearCallingIdentity(); |
| 3969 | try { |
| 3970 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3971 | int slotId = getSlotIndex(subId); |
| 3972 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3973 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 3974 | + subId + "' for key:" + key); |
| 3975 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3976 | } |
| 3977 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3978 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3979 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 3980 | + "' for key:" + key); |
| 3981 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3982 | } finally { |
| 3983 | Binder.restoreCallingIdentity(identity); |
| 3984 | } |
| 3985 | } |
| 3986 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3987 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3988 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3989 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3990 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 3991 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3992 | } |
| 3993 | return slotId; |
| 3994 | } |
| 3995 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3996 | private int getSlotIndex(int subId) { |
| 3997 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3998 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 3999 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4000 | } |
| 4001 | return slotId; |
| 4002 | } |
| 4003 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4004 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4005 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4006 | */ |
| 4007 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4008 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4009 | String callingFeatureId) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4010 | final int targetSdk = getTargetSdk(callingPackage); |
| 4011 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4012 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4013 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4014 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4015 | mApp, subId, callingPackage, callingFeatureId, |
| 4016 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4017 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4018 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4019 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4020 | final long identity = Binder.clearCallingIdentity(); |
| 4021 | try { |
| 4022 | final Phone phone = getPhone(subId); |
| 4023 | if (phone != null) { |
| 4024 | return phone.getServiceState().getDataNetworkType(); |
| 4025 | } else { |
| 4026 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4027 | } |
| 4028 | } finally { |
| 4029 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4030 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4031 | } |
| 4032 | |
| 4033 | /** |
| 4034 | * Returns the data network type |
| 4035 | */ |
| 4036 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4037 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4038 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4039 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4040 | } |
| 4041 | |
| 4042 | /** |
| 4043 | * Returns the data network type for a subId |
| 4044 | */ |
| 4045 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4046 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4047 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4048 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4049 | mApp, subId, callingPackage, callingFeatureId, |
| 4050 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4051 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4052 | } |
| 4053 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4054 | final long identity = Binder.clearCallingIdentity(); |
| 4055 | try { |
| 4056 | final Phone phone = getPhone(subId); |
| 4057 | if (phone != null) { |
| 4058 | return phone.getServiceState().getDataNetworkType(); |
| 4059 | } else { |
| 4060 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4061 | } |
| 4062 | } finally { |
| 4063 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4064 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4065 | } |
| 4066 | |
| 4067 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4068 | * Returns the Voice network type for a subId |
| 4069 | */ |
| 4070 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4071 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4072 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4073 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4074 | mApp, subId, callingPackage, callingFeatureId, |
| 4075 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4076 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4077 | } |
| 4078 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4079 | final long identity = Binder.clearCallingIdentity(); |
| 4080 | try { |
| 4081 | final Phone phone = getPhone(subId); |
| 4082 | if (phone != null) { |
| 4083 | return phone.getServiceState().getVoiceNetworkType(); |
| 4084 | } else { |
| 4085 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4086 | } |
| 4087 | } finally { |
| 4088 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4089 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4090 | } |
| 4091 | |
| 4092 | /** |
| 4093 | * @return true if a ICC card is present |
| 4094 | */ |
| 4095 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4096 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4097 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4098 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4099 | } |
| 4100 | |
| 4101 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4102 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4103 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4104 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4105 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4106 | final long identity = Binder.clearCallingIdentity(); |
| 4107 | try { |
| 4108 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4109 | if (phone != null) { |
| 4110 | return phone.getIccCard().hasIccCard(); |
| 4111 | } else { |
| 4112 | return false; |
| 4113 | } |
| 4114 | } finally { |
| 4115 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4116 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4117 | } |
| 4118 | |
| 4119 | /** |
| 4120 | * Return if the current radio is LTE on CDMA. This |
| 4121 | * is a tri-state return value as for a period of time |
| 4122 | * the mode may be unknown. |
| 4123 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4124 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4125 | * @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] | 4126 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4127 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4128 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4129 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4130 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4131 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4132 | } |
| 4133 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4134 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4135 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4136 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4137 | try { |
| 4138 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4139 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4140 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4141 | } |
| 4142 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4143 | final long identity = Binder.clearCallingIdentity(); |
| 4144 | try { |
| 4145 | final Phone phone = getPhone(subId); |
| 4146 | if (phone == null) { |
| 4147 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4148 | } else { |
| 4149 | return phone.getLteOnCdmaMode(); |
| 4150 | } |
| 4151 | } finally { |
| 4152 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4153 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4154 | } |
| 4155 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4156 | /** |
| 4157 | * {@hide} |
| 4158 | * Returns Default subId, 0 in the case of single standby. |
| 4159 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4160 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4161 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4162 | } |
| 4163 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4164 | private int getSlotForDefaultSubscription() { |
| 4165 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4166 | } |
| 4167 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4168 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4169 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4170 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4171 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4172 | private boolean isActiveSubscription(int subId) { |
| 4173 | return mSubscriptionController.isActiveSubId(subId); |
| 4174 | } |
| 4175 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4176 | /** |
| 4177 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4178 | */ |
| 4179 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4180 | final long identity = Binder.clearCallingIdentity(); |
| 4181 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4182 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4183 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4184 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4185 | } finally { |
| 4186 | Binder.restoreCallingIdentity(identity); |
| 4187 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4188 | } |
| 4189 | |
| 4190 | /** |
| 4191 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4192 | */ |
| 4193 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4194 | final long identity = Binder.clearCallingIdentity(); |
| 4195 | try { |
| 4196 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4197 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4198 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4199 | } finally { |
| 4200 | Binder.restoreCallingIdentity(identity); |
| 4201 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4202 | } |
| 4203 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4204 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4205 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4206 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4207 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4208 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4209 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4210 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4211 | if (phoneId == -1) { |
| 4212 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4213 | + " does not correspond to an active phone"); |
| 4214 | } |
| 4215 | return PhoneFactory.getPhone(phoneId); |
| 4216 | } |
| 4217 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4218 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4219 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4220 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4221 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4222 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4223 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4224 | if (DBG) { |
| 4225 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4226 | } |
| 4227 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4228 | p2); |
| 4229 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4230 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4231 | |
| 4232 | @Override |
| 4233 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4234 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4235 | enforceModifyPermission(); |
| 4236 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4237 | if (DBG) { |
| 4238 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4239 | } |
| 4240 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4241 | callingPackage, aid, p2); |
| 4242 | } |
| 4243 | |
| 4244 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4245 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4246 | final long identity = Binder.clearCallingIdentity(); |
| 4247 | try { |
| 4248 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4249 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4250 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4251 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4252 | if (bestComponent == null |
| 4253 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4254 | loge("The calling package is not allowed to access ISD-R."); |
| 4255 | throw new SecurityException( |
| 4256 | "The calling package is not allowed to access ISD-R."); |
| 4257 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4258 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4259 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4260 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4261 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4262 | null /* workSource */); |
| 4263 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4264 | return response; |
| 4265 | } finally { |
| 4266 | Binder.restoreCallingIdentity(identity); |
| 4267 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4268 | } |
| 4269 | |
| 4270 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4271 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4272 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4273 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4274 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4275 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4276 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4277 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4278 | @Override |
| 4279 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4280 | enforceModifyPermission(); |
| 4281 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4282 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4283 | channel); |
| 4284 | } |
| 4285 | |
| 4286 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4287 | final long identity = Binder.clearCallingIdentity(); |
| 4288 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4289 | if (channel < 0) { |
| 4290 | return false; |
| 4291 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4292 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4293 | null /* workSource */); |
| 4294 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4295 | return success; |
| 4296 | } finally { |
| 4297 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4298 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4299 | } |
| 4300 | |
| 4301 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4302 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4303 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4304 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4305 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4306 | if (DBG) { |
| 4307 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4308 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4309 | + p3 + " data=" + data); |
| 4310 | } |
| 4311 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4312 | command, p1, p2, p3, data); |
| 4313 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4314 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4315 | @Override |
| 4316 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4317 | int command, int p1, int p2, int p3, String data) { |
| 4318 | enforceModifyPermission(); |
| 4319 | if (DBG) { |
| 4320 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4321 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4322 | + p3 + " data=" + data); |
| 4323 | } |
| 4324 | return iccTransmitApduLogicalChannelWithPermission( |
| 4325 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4326 | data); |
| 4327 | } |
| 4328 | |
| 4329 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4330 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4331 | final long identity = Binder.clearCallingIdentity(); |
| 4332 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4333 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4334 | return ""; |
| 4335 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4336 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4337 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4338 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4339 | null /* workSource */); |
| 4340 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4341 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4342 | // Append the returned status code to the end of the response payload. |
| 4343 | String s = Integer.toHexString( |
| 4344 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4345 | if (response.payload != null) { |
| 4346 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4347 | } |
| 4348 | return s; |
| 4349 | } finally { |
| 4350 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4351 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4352 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4353 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4354 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4355 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4356 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4357 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4358 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4359 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4360 | if (DBG) { |
| 4361 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4362 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4363 | } |
| 4364 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4365 | cla, command, p1, p2, p3, data); |
| 4366 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4367 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4368 | @Override |
| 4369 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4370 | int command, int p1, int p2, int p3, String data) { |
| 4371 | enforceModifyPermission(); |
| 4372 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4373 | if (DBG) { |
| 4374 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4375 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4376 | + " data=" + data); |
| 4377 | } |
| 4378 | |
| 4379 | return iccTransmitApduBasicChannelWithPermission( |
| 4380 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4381 | p2, p3, data); |
| 4382 | } |
| 4383 | |
| 4384 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4385 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4386 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4387 | final long identity = Binder.clearCallingIdentity(); |
| 4388 | try { |
| 4389 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4390 | && TextUtils.equals(ISDR_AID, data)) { |
| 4391 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4392 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4393 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4394 | if (bestComponent == null |
| 4395 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4396 | loge("The calling package is not allowed to select ISD-R."); |
| 4397 | throw new SecurityException( |
| 4398 | "The calling package is not allowed to select ISD-R."); |
| 4399 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4400 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4401 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4402 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4403 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4404 | null /* workSource */); |
| 4405 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4406 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4407 | // Append the returned status code to the end of the response payload. |
| 4408 | String s = Integer.toHexString( |
| 4409 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4410 | if (response.payload != null) { |
| 4411 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4412 | } |
| 4413 | return s; |
| 4414 | } finally { |
| 4415 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4416 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4417 | } |
| 4418 | |
| 4419 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4420 | 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] | 4421 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4422 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4423 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4424 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4425 | final long identity = Binder.clearCallingIdentity(); |
| 4426 | try { |
| 4427 | if (DBG) { |
| 4428 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4429 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4430 | } |
| 4431 | |
| 4432 | IccIoResult response = |
| 4433 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4434 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4435 | subId); |
| 4436 | |
| 4437 | if (DBG) { |
| 4438 | log("Exchange SIM_IO [R]" + response); |
| 4439 | } |
| 4440 | |
| 4441 | byte[] result = null; |
| 4442 | int length = 2; |
| 4443 | if (response.payload != null) { |
| 4444 | length = 2 + response.payload.length; |
| 4445 | result = new byte[length]; |
| 4446 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4447 | } else { |
| 4448 | result = new byte[length]; |
| 4449 | } |
| 4450 | |
| 4451 | result[length - 1] = (byte) response.sw2; |
| 4452 | result[length - 2] = (byte) response.sw1; |
| 4453 | return result; |
| 4454 | } finally { |
| 4455 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4456 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4457 | } |
| 4458 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4459 | /** |
| 4460 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4461 | * on a particular subscription |
| 4462 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4463 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 4464 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4465 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4466 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4467 | return null; |
| 4468 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4469 | |
| 4470 | final long identity = Binder.clearCallingIdentity(); |
| 4471 | try { |
| 4472 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4473 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4474 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4475 | return null; |
| 4476 | } |
| 4477 | Object response = sendRequest( |
| 4478 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4479 | if (response instanceof String[]) { |
| 4480 | return (String[]) response; |
| 4481 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4482 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4483 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4484 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4485 | } finally { |
| 4486 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4487 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4488 | } |
| 4489 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4490 | /** |
| 4491 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 4492 | * subscription. |
| 4493 | * |
| 4494 | * @param subId the id of the subscription. |
| 4495 | * @param appType the uicc app type, must be USIM or SIM. |
| 4496 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 4497 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4498 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4499 | * @return number of fplmns that is successfully written to the SIM. |
| 4500 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4501 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 4502 | String callingFeatureId) { |
| 4503 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 4504 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4505 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 4506 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 4507 | } |
| 4508 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 4509 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4510 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 4511 | } |
| 4512 | if (fplmns == null) { |
| 4513 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 4514 | } |
| 4515 | for (String fplmn : fplmns) { |
| 4516 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 4517 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 4518 | } |
| 4519 | } |
| 4520 | final long identity = Binder.clearCallingIdentity(); |
| 4521 | try { |
| 4522 | Object response = sendRequest( |
| 4523 | CMD_SET_FORBIDDEN_PLMNS, |
| 4524 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 4525 | subId); |
| 4526 | return (int) response; |
| 4527 | } finally { |
| 4528 | Binder.restoreCallingIdentity(identity); |
| 4529 | } |
| 4530 | } |
| 4531 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4532 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4533 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4534 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4535 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4536 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4537 | final long identity = Binder.clearCallingIdentity(); |
| 4538 | try { |
| 4539 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4540 | if (response.payload == null) { |
| 4541 | return ""; |
| 4542 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4543 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4544 | // Append the returned status code to the end of the response payload. |
| 4545 | String s = Integer.toHexString( |
| 4546 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4547 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4548 | return s; |
| 4549 | } finally { |
| 4550 | Binder.restoreCallingIdentity(identity); |
| 4551 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4552 | } |
| 4553 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4554 | /** |
| 4555 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4556 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4557 | * |
| 4558 | * @param itemID the ID of the item to read |
| 4559 | * @return the NV item as a String, or null on error. |
| 4560 | */ |
| 4561 | @Override |
| 4562 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4563 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4564 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4565 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4566 | |
| 4567 | final long identity = Binder.clearCallingIdentity(); |
| 4568 | try { |
| 4569 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4570 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4571 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4572 | return value; |
| 4573 | } finally { |
| 4574 | Binder.restoreCallingIdentity(identity); |
| 4575 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4576 | } |
| 4577 | |
| 4578 | /** |
| 4579 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4580 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4581 | * |
| 4582 | * @param itemID the ID of the item to read |
| 4583 | * @param itemValue the value to write, as a String |
| 4584 | * @return true on success; false on any failure |
| 4585 | */ |
| 4586 | @Override |
| 4587 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4588 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4589 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4590 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4591 | |
| 4592 | final long identity = Binder.clearCallingIdentity(); |
| 4593 | try { |
| 4594 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4595 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4596 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4597 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4598 | return success; |
| 4599 | } finally { |
| 4600 | Binder.restoreCallingIdentity(identity); |
| 4601 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4602 | } |
| 4603 | |
| 4604 | /** |
| 4605 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4606 | * Used for device configuration by some CDMA operators. |
| 4607 | * |
| 4608 | * @param preferredRoamingList byte array containing the new PRL |
| 4609 | * @return true on success; false on any failure |
| 4610 | */ |
| 4611 | @Override |
| 4612 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4613 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4614 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4615 | |
| 4616 | final long identity = Binder.clearCallingIdentity(); |
| 4617 | try { |
| 4618 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4619 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4620 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4621 | return success; |
| 4622 | } finally { |
| 4623 | Binder.restoreCallingIdentity(identity); |
| 4624 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4625 | } |
| 4626 | |
| 4627 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4628 | * 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] | 4629 | * Used for device configuration by some CDMA operators. |
| 4630 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4631 | * @param slotIndex - device slot. |
| 4632 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4633 | * @return true on success; false on any failure |
| 4634 | */ |
| 4635 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4636 | public boolean resetModemConfig(int slotIndex) { |
| 4637 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4638 | if (phone != null) { |
| 4639 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4640 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4641 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4642 | final long identity = Binder.clearCallingIdentity(); |
| 4643 | try { |
| 4644 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4645 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4646 | return success; |
| 4647 | } finally { |
| 4648 | Binder.restoreCallingIdentity(identity); |
| 4649 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4650 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4651 | return false; |
| 4652 | } |
| 4653 | |
| 4654 | /** |
| 4655 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4656 | * |
| 4657 | * @param slotIndex - device slot. |
| 4658 | * |
| 4659 | * @return true on success; false on any failure |
| 4660 | */ |
| 4661 | @Override |
| 4662 | public boolean rebootModem(int slotIndex) { |
| 4663 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4664 | if (phone != null) { |
| 4665 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4666 | mApp, phone.getSubId(), "rebootModem"); |
| 4667 | |
| 4668 | final long identity = Binder.clearCallingIdentity(); |
| 4669 | try { |
| 4670 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4671 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4672 | return success; |
| 4673 | } finally { |
| 4674 | Binder.restoreCallingIdentity(identity); |
| 4675 | } |
| 4676 | } |
| 4677 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4678 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4679 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4680 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 4681 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4682 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4683 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4684 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4685 | return new String[0]; |
| 4686 | } |
| 4687 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4688 | final long identity = Binder.clearCallingIdentity(); |
| 4689 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4690 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4691 | } finally { |
| 4692 | Binder.restoreCallingIdentity(identity); |
| 4693 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4694 | } |
| 4695 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4696 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4697 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4698 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4699 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4700 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4701 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4702 | |
| 4703 | final long identity = Binder.clearCallingIdentity(); |
| 4704 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4705 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4706 | // may happen if the device does not support IMS. |
| 4707 | return; |
| 4708 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4709 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4710 | } finally { |
| 4711 | Binder.restoreCallingIdentity(identity); |
| 4712 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4713 | } |
| 4714 | |
| 4715 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4716 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4717 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4718 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4719 | public void disableIms(int slotId) { |
| 4720 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4721 | |
| 4722 | final long identity = Binder.clearCallingIdentity(); |
| 4723 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4724 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4725 | // may happen if the device does not support IMS. |
| 4726 | return; |
| 4727 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4728 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4729 | } finally { |
| 4730 | Binder.restoreCallingIdentity(identity); |
| 4731 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4732 | } |
| 4733 | |
| 4734 | /** |
| 4735 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4736 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4737 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4738 | */ |
| 4739 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4740 | IImsServiceFeatureCallback callback) { |
| 4741 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4742 | |
| 4743 | final long identity = Binder.clearCallingIdentity(); |
| 4744 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4745 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4746 | // may happen if the device does not support IMS. |
| 4747 | return null; |
| 4748 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4749 | return mImsResolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4750 | } finally { |
| 4751 | Binder.restoreCallingIdentity(identity); |
| 4752 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4753 | } |
| 4754 | |
| 4755 | /** |
| 4756 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4757 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4758 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4759 | * listener for feature updates. |
| 4760 | */ |
| 4761 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4762 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4763 | |
| 4764 | final long identity = Binder.clearCallingIdentity(); |
| 4765 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4766 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4767 | // may happen if the device does not support IMS. |
| 4768 | return null; |
| 4769 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4770 | return mImsResolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4771 | } finally { |
| 4772 | Binder.restoreCallingIdentity(identity); |
| 4773 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4774 | } |
| 4775 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4776 | /** |
| 4777 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4778 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4779 | */ |
| 4780 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 4781 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4782 | |
| 4783 | final long identity = Binder.clearCallingIdentity(); |
| 4784 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4785 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4786 | // may happen if the device does not support IMS. |
| 4787 | return null; |
| 4788 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4789 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4790 | } finally { |
| 4791 | Binder.restoreCallingIdentity(identity); |
| 4792 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4793 | } |
| 4794 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4795 | /** |
| 4796 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4797 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4798 | */ |
| 4799 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 4800 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4801 | |
| 4802 | final long identity = Binder.clearCallingIdentity(); |
| 4803 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4804 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4805 | // may happen if the device does not support IMS. |
| 4806 | return null; |
| 4807 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4808 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4809 | } finally { |
| 4810 | Binder.restoreCallingIdentity(identity); |
| 4811 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4812 | } |
| 4813 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 4814 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4815 | * Sets the ImsService Package Name that Telephony will bind to. |
| 4816 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4817 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 4818 | * @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] | 4819 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4820 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 4821 | * @param packageName The name of the package that the current configuration will be replaced |
| 4822 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4823 | * @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] | 4824 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4825 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 4826 | int[] featureTypes, String packageName) { |
| 4827 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 4828 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4829 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4830 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4831 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4832 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4833 | final long identity = Binder.clearCallingIdentity(); |
| 4834 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4835 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4836 | // may happen if the device does not support IMS. |
| 4837 | return false; |
| 4838 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4839 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 4840 | for (int featureType : featureTypes) { |
| 4841 | featureConfig.put(featureType, packageName); |
| 4842 | } |
| 4843 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 4844 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4845 | } finally { |
| 4846 | Binder.restoreCallingIdentity(identity); |
| 4847 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4848 | } |
| 4849 | |
| 4850 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4851 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4852 | * |
| 4853 | * @param slotId The slot that the ImsService is associated with. |
| 4854 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 4855 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4856 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4857 | * @return the package name of the ImsService configuration. |
| 4858 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4859 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 4860 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4861 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4862 | TelephonyPermissions |
| 4863 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4864 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4865 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4866 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4867 | final long identity = Binder.clearCallingIdentity(); |
| 4868 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4869 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4870 | // may happen if the device does not support IMS. |
| 4871 | return ""; |
| 4872 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 4873 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4874 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 4875 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4876 | } finally { |
| 4877 | Binder.restoreCallingIdentity(identity); |
| 4878 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4879 | } |
| 4880 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4881 | /** |
| 4882 | * Get the MmTelFeature state associated with the requested subscription id. |
| 4883 | * @param subId The subscription that the MmTelFeature is associated with. |
| 4884 | * @param callback A callback with an integer containing the |
| 4885 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 4886 | */ |
| 4887 | @Override |
| 4888 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 4889 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 4890 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4891 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4892 | "IMS not available on device."); |
| 4893 | } |
| 4894 | final long token = Binder.clearCallingIdentity(); |
| 4895 | try { |
| 4896 | int slotId = getSlotIndex(subId); |
| 4897 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4898 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 4899 | + subId + "'"); |
| 4900 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4901 | } |
| 4902 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 4903 | try { |
| 4904 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 4905 | } catch (RemoteException e) { |
| 4906 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 4907 | + "Ignore"); |
| 4908 | } |
| 4909 | }); |
| 4910 | } finally { |
| 4911 | Binder.restoreCallingIdentity(token); |
| 4912 | } |
| 4913 | } |
| 4914 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4915 | public void setImsRegistrationState(boolean registered) { |
| 4916 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4917 | |
| 4918 | final long identity = Binder.clearCallingIdentity(); |
| 4919 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4920 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4921 | } finally { |
| 4922 | Binder.restoreCallingIdentity(identity); |
| 4923 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4924 | } |
| 4925 | |
| 4926 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4927 | * Set the network selection mode to automatic. |
| 4928 | * |
| 4929 | */ |
| 4930 | @Override |
| 4931 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4932 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4933 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4934 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4935 | if (!isActiveSubscription(subId)) { |
| 4936 | return; |
| 4937 | } |
| 4938 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4939 | final long identity = Binder.clearCallingIdentity(); |
| 4940 | try { |
| 4941 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 4942 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 4943 | } finally { |
| 4944 | Binder.restoreCallingIdentity(identity); |
| 4945 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4946 | } |
| 4947 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4948 | /** |
| 4949 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 4950 | * |
| 4951 | * @param subId the id of the subscription. |
| 4952 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 4953 | * the operator to attach to. |
| 4954 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 4955 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 4956 | * normal network selection next time. |
| 4957 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4958 | */ |
| 4959 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4960 | public boolean setNetworkSelectionModeManual( |
| 4961 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4962 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4963 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4964 | |
| 4965 | if (!isActiveSubscription(subId)) { |
| 4966 | return false; |
| 4967 | } |
| 4968 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4969 | final long identity = Binder.clearCallingIdentity(); |
| 4970 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4971 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4972 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4973 | if (DBG) { |
| 4974 | log("setNetworkSelectionModeManual: subId: " + subId |
| 4975 | + " operator: " + operatorInfo); |
| 4976 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4977 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 4978 | } finally { |
| 4979 | Binder.restoreCallingIdentity(identity); |
| 4980 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4981 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame^] | 4982 | /** |
| 4983 | * Get the manual network selection |
| 4984 | * |
| 4985 | * @param subId the id of the subscription. |
| 4986 | * |
| 4987 | * @return the previously saved user selected PLMN |
| 4988 | */ |
| 4989 | @Override |
| 4990 | public String getManualNetworkSelectionPlmn(int subId) { |
| 4991 | TelephonyPermissions |
| 4992 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4993 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 4994 | |
| 4995 | final long identity = Binder.clearCallingIdentity(); |
| 4996 | try { |
| 4997 | if (!isActiveSubscription(subId)) { |
| 4998 | return ""; |
| 4999 | } |
| 5000 | |
| 5001 | final Phone phone = getPhone(subId); |
| 5002 | if (phone == null) { |
| 5003 | return ""; |
| 5004 | } |
| 5005 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5006 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5007 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5008 | } finally { |
| 5009 | Binder.restoreCallingIdentity(identity); |
| 5010 | } |
| 5011 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5012 | |
| 5013 | /** |
| 5014 | * Scans for available networks. |
| 5015 | */ |
| 5016 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5017 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5018 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5019 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5020 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5021 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5022 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5023 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5024 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5025 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5026 | .setCallingPid(Binder.getCallingPid()) |
| 5027 | .setCallingUid(Binder.getCallingUid()) |
| 5028 | .setMethod("getCellNetworkScanResults") |
| 5029 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5030 | .build()); |
| 5031 | switch (locationResult) { |
| 5032 | case DENIED_HARD: |
| 5033 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5034 | case DENIED_SOFT: |
| 5035 | return null; |
| 5036 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5037 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5038 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5039 | try { |
| 5040 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5041 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5042 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5043 | } finally { |
| 5044 | Binder.restoreCallingIdentity(identity); |
| 5045 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5046 | } |
| 5047 | |
| 5048 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5049 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5050 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5051 | * @param subId id of the subscription |
| 5052 | * @param request contains the radio access networks with bands/channels to scan |
| 5053 | * @param messenger callback messenger for scan results or errors |
| 5054 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5055 | * @return the id of the requested scan which can be used to stop the scan. |
| 5056 | */ |
| 5057 | @Override |
| 5058 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5059 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5060 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5061 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5062 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5063 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5064 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5065 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5066 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5067 | .setCallingPid(Binder.getCallingPid()) |
| 5068 | .setCallingUid(Binder.getCallingUid()) |
| 5069 | .setMethod("requestNetworkScan") |
| 5070 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5071 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5072 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5073 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5074 | if (e != null) { |
| 5075 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5076 | throw e; |
| 5077 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5078 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5079 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5080 | } |
| 5081 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5082 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5083 | int callingUid = Binder.getCallingUid(); |
| 5084 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5085 | final long identity = Binder.clearCallingIdentity(); |
| 5086 | try { |
| 5087 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5088 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5089 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5090 | } finally { |
| 5091 | Binder.restoreCallingIdentity(identity); |
| 5092 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5093 | } |
| 5094 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5095 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5096 | NetworkScanRequest request, int subId) { |
| 5097 | boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid()) |
| 5098 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5099 | boolean hasNetworkScanPermission = |
| 5100 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5101 | == PERMISSION_GRANTED; |
| 5102 | |
| 5103 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5104 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5105 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5106 | } |
| 5107 | |
| 5108 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5109 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5110 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5111 | return new SecurityException("Specific channels must not be" |
| 5112 | + " scanned without location access."); |
| 5113 | } |
| 5114 | } |
| 5115 | } |
| 5116 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5117 | return null; |
| 5118 | } |
| 5119 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5120 | /** |
| 5121 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5122 | * |
| 5123 | * @param subId id of the subscription |
| 5124 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5125 | */ |
| 5126 | @Override |
| 5127 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5128 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5129 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5130 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5131 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5132 | final long identity = Binder.clearCallingIdentity(); |
| 5133 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5134 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5135 | } finally { |
| 5136 | Binder.restoreCallingIdentity(identity); |
| 5137 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5138 | } |
| 5139 | |
| 5140 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5141 | * Get the calculated preferred network type. |
| 5142 | * Used for debugging incorrect network type. |
| 5143 | * |
| 5144 | * @return the preferred network type, defined in RILConstants.java. |
| 5145 | */ |
| 5146 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5147 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5148 | final Phone defaultPhone = getDefaultPhone(); |
| 5149 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5150 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5151 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5152 | } |
| 5153 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5154 | final long identity = Binder.clearCallingIdentity(); |
| 5155 | try { |
| 5156 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5157 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5158 | } finally { |
| 5159 | Binder.restoreCallingIdentity(identity); |
| 5160 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5161 | } |
| 5162 | |
| 5163 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5164 | * Get the preferred network type. |
| 5165 | * Used for device configuration by some CDMA operators. |
| 5166 | * |
| 5167 | * @return the preferred network type, defined in RILConstants.java. |
| 5168 | */ |
| 5169 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5170 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5171 | TelephonyPermissions |
| 5172 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5173 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5174 | |
| 5175 | final long identity = Binder.clearCallingIdentity(); |
| 5176 | try { |
| 5177 | if (DBG) log("getPreferredNetworkType"); |
| 5178 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5179 | int networkType = (result != null ? result[0] : -1); |
| 5180 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5181 | return networkType; |
| 5182 | } finally { |
| 5183 | Binder.restoreCallingIdentity(identity); |
| 5184 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5185 | } |
| 5186 | |
| 5187 | /** |
| 5188 | * Set the preferred network type. |
| 5189 | * Used for device configuration by some CDMA operators. |
| 5190 | * |
| 5191 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5192 | * @return true on success; false on any failure. |
| 5193 | */ |
| 5194 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5195 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5196 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5197 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5198 | |
| 5199 | final long identity = Binder.clearCallingIdentity(); |
| 5200 | try { |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5201 | Settings.Global.putInt(mApp.getContentResolver(), |
| 5202 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 5203 | return setPreferredNetworkTypesInternal(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5204 | } finally { |
| 5205 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5206 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5207 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5208 | |
| 5209 | /** |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5210 | * Get the allowed network types that store in the telephony provider. |
| 5211 | * |
| 5212 | * @param subId the id of the subscription. |
| 5213 | * @return allowedNetworkTypes the allowed network types. |
| 5214 | */ |
| 5215 | @Override |
| 5216 | public long getAllowedNetworkTypes(int subId) { |
| 5217 | TelephonyPermissions |
| 5218 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5219 | mApp, subId, "getAllowedNetworkTypes"); |
| 5220 | |
| 5221 | final long identity = Binder.clearCallingIdentity(); |
| 5222 | try { |
| 5223 | return SubscriptionManager.getLongSubscriptionProperty( |
| 5224 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5225 | } finally { |
| 5226 | Binder.restoreCallingIdentity(identity); |
| 5227 | } |
| 5228 | } |
| 5229 | |
| 5230 | /** |
| 5231 | * Set the allowed network types. |
| 5232 | * |
| 5233 | * @param subId the id of the subscription. |
| 5234 | * @param allowedNetworkTypes the allowed network types. |
| 5235 | * @return true on success; false on any failure. |
| 5236 | */ |
| 5237 | @Override |
| 5238 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 5239 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5240 | mApp, subId, "setAllowedNetworkTypes"); |
| 5241 | final long identity = Binder.clearCallingIdentity(); |
| 5242 | try { |
| 5243 | SubscriptionManager.setSubscriptionProperty(subId, |
| 5244 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 5245 | String.valueOf(allowedNetworkTypes)); |
| 5246 | return setPreferredNetworkTypesInternal(subId); |
| 5247 | } finally { |
| 5248 | Binder.restoreCallingIdentity(identity); |
| 5249 | } |
| 5250 | } |
| 5251 | |
| 5252 | private boolean setPreferredNetworkTypesInternal(int subId) { |
| 5253 | long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType( |
| 5254 | Settings.Global.getInt(mApp.getContentResolver(), |
| 5255 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5256 | RILConstants.PREFERRED_NETWORK_MODE)); |
| 5257 | long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty( |
| 5258 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5259 | int networkMode = RadioAccessFamily.getNetworkTypeFromRaf( |
| 5260 | (int) (networkTypeBitMask & allowedNetworkTypes)); |
| 5261 | |
| 5262 | if (DBG) { |
| 5263 | log("setPreferredNetworkTypesInternal: subId " + subId |
| 5264 | + " networkTypes " + networkTypeBitMask |
| 5265 | + " allowedNetworkTypes " + allowedNetworkTypes |
| 5266 | + " networkMode " + networkMode); |
| 5267 | } |
| 5268 | |
| 5269 | Boolean success = (Boolean) sendRequest( |
| 5270 | CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId); |
| 5271 | if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail")); |
| 5272 | return success; |
| 5273 | } |
| 5274 | |
| 5275 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5276 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5277 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5278 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 5279 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5280 | * @hide |
| 5281 | */ |
| 5282 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 5283 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5284 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5285 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5286 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5287 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5288 | if (phone != null) { |
| 5289 | return phone.hasMatchedTetherApnSetting(); |
| 5290 | } else { |
| 5291 | return false; |
| 5292 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5293 | } finally { |
| 5294 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5295 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5296 | } |
| 5297 | |
| 5298 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5299 | * Set mobile data enabled |
| 5300 | * Used by the user through settings etc to turn on/off mobile data |
| 5301 | * |
| 5302 | * @param enable {@code true} turn turn data on, else {@code false} |
| 5303 | */ |
| 5304 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5305 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5306 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5307 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5308 | |
| 5309 | final long identity = Binder.clearCallingIdentity(); |
| 5310 | try { |
| 5311 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5312 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5313 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5314 | if (phone != null) { |
| 5315 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5316 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5317 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5318 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5319 | } |
| 5320 | } finally { |
| 5321 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5322 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5323 | } |
| 5324 | |
| 5325 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5326 | * Get the user enabled state of Mobile Data. |
| 5327 | * |
| 5328 | * TODO: remove and use isUserDataEnabled. |
| 5329 | * This can't be removed now because some vendor codes |
| 5330 | * calls through ITelephony directly while they should |
| 5331 | * use TelephonyManager. |
| 5332 | * |
| 5333 | * @return true on enabled |
| 5334 | */ |
| 5335 | @Override |
| 5336 | public boolean getDataEnabled(int subId) { |
| 5337 | return isUserDataEnabled(subId); |
| 5338 | } |
| 5339 | |
| 5340 | /** |
| 5341 | * Get whether mobile data is enabled per user setting. |
| 5342 | * |
| 5343 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 5344 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5345 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 5346 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5347 | * |
| 5348 | * @return {@code true} if data is enabled else {@code false} |
| 5349 | */ |
| 5350 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5351 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5352 | try { |
| 5353 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 5354 | null); |
| 5355 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5356 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5357 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5358 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5359 | |
| 5360 | final long identity = Binder.clearCallingIdentity(); |
| 5361 | try { |
| 5362 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5363 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5364 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5365 | if (phone != null) { |
| 5366 | boolean retVal = phone.isUserDataEnabled(); |
| 5367 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5368 | return retVal; |
| 5369 | } else { |
| 5370 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5371 | return false; |
| 5372 | } |
| 5373 | } finally { |
| 5374 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5375 | } |
| 5376 | } |
| 5377 | |
| 5378 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5379 | * Checks if the device is capable of mobile data by considering whether whether the |
| 5380 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 5381 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5382 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5383 | * @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] | 5384 | */ |
| 5385 | @Override |
| 5386 | public boolean isDataEnabled(int subId) { |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5387 | enforceReadPrivilegedPermission("isDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5388 | |
| 5389 | final long identity = Binder.clearCallingIdentity(); |
| 5390 | try { |
| 5391 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5392 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5393 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5394 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5395 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5396 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5397 | return retVal; |
| 5398 | } else { |
| 5399 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5400 | return false; |
| 5401 | } |
| 5402 | } finally { |
| 5403 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5404 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5405 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5406 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5407 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, |
| 5408 | Phone phone) { |
| 5409 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5410 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5411 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5412 | || subController == null) return privilegeFromSim; |
| 5413 | |
| 5414 | int uid = Binder.getCallingUid(); |
| 5415 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 5416 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 5417 | |
| 5418 | final long identity = Binder.clearCallingIdentity(); |
| 5419 | try { |
| 5420 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5421 | SubscriptionManager subManager = (SubscriptionManager) |
| 5422 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5423 | for (String pkg : packages) { |
| 5424 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 5425 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5426 | } |
| 5427 | } |
| 5428 | return privilegeFromSim; |
| 5429 | } finally { |
| 5430 | Binder.restoreCallingIdentity(identity); |
| 5431 | } |
| 5432 | } |
| 5433 | |
| 5434 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 5435 | String pkgName) { |
| 5436 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5437 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5438 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5439 | || subController == null) return privilegeFromSim; |
| 5440 | |
| 5441 | final long identity = Binder.clearCallingIdentity(); |
| 5442 | try { |
| 5443 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5444 | SubscriptionManager subManager = (SubscriptionManager) |
| 5445 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5446 | return subManager.canManageSubscription(subInfo, pkgName) |
| 5447 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 5448 | } finally { |
| 5449 | Binder.restoreCallingIdentity(identity); |
| 5450 | } |
| 5451 | } |
| 5452 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5453 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5454 | public int getCarrierPrivilegeStatus(int subId) { |
| 5455 | final Phone phone = getPhone(subId); |
| 5456 | if (phone == null) { |
| 5457 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 5458 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5459 | } |
| 5460 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5461 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 5462 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5463 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5464 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5465 | |
| 5466 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5467 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
| 5468 | phone.getContext().getPackageManager()), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5469 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5470 | |
| 5471 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5472 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5473 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5474 | final Phone phone = getPhone(subId); |
| 5475 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5476 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5477 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5478 | } |
| 5479 | UiccProfile profile = |
| 5480 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 5481 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5482 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5483 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5484 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5485 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5486 | profile.getCarrierPrivilegeStatusForUid( |
| 5487 | phone.getContext().getPackageManager(), uid), phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5488 | } |
| 5489 | |
| 5490 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5491 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 5492 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5493 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5494 | } |
| 5495 | |
| 5496 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 5497 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5498 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5499 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5500 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5501 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5502 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5503 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5504 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5505 | } |
| 5506 | |
| 5507 | @Override |
| 5508 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5509 | if (TextUtils.isEmpty(pkgName)) |
| 5510 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5511 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5512 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5513 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 5514 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 5515 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5516 | continue; |
| 5517 | } |
| 5518 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5519 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5520 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5521 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5522 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 5523 | break; |
| 5524 | } |
| 5525 | } |
| 5526 | |
| 5527 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5528 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 5529 | |
| 5530 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 5531 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 5532 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 5533 | loge("phoneId " + phoneId + " is not valid."); |
| 5534 | return null; |
| 5535 | } |
| 5536 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5537 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5538 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5539 | return null ; |
| 5540 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5541 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5542 | } |
| 5543 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5544 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5545 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5546 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5547 | List<String> privilegedPackages = new ArrayList<>(); |
| 5548 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5549 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 5550 | // has UICC in that slot. |
| 5551 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5552 | if (card.hasCarrierPrivilegeRules()) { |
| 5553 | if (packages == null) { |
| 5554 | // Only check packages in user 0 for now |
| 5555 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5556 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 5557 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 5558 | | PackageManager.GET_SIGNING_CERTIFICATES, |
| 5559 | UserHandle.USER_SYSTEM); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5560 | } |
| 5561 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 5562 | PackageInfo pkgInfo = packages.get(p); |
| 5563 | if (pkgInfo != null && pkgInfo.packageName != null |
| 5564 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5565 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5566 | privilegedPackages.add(pkgInfo.packageName); |
| 5567 | } |
| 5568 | } |
| 5569 | } |
| 5570 | } |
| 5571 | return privilegedPackages; |
| 5572 | } |
| 5573 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5574 | @Override |
| 5575 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5576 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 5577 | |
| 5578 | final long identity = Binder.clearCallingIdentity(); |
| 5579 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5580 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5581 | try { |
| 5582 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5583 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 5584 | } |
| 5585 | } finally { |
| 5586 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5587 | } |
| 5588 | return privilegedPackages; |
| 5589 | } |
| 5590 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5591 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5592 | final Phone phone = getPhone(subId); |
| 5593 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5594 | if (card == null) { |
| 5595 | loge("getIccId: No UICC"); |
| 5596 | return null; |
| 5597 | } |
| 5598 | String iccId = card.getIccId(); |
| 5599 | if (TextUtils.isEmpty(iccId)) { |
| 5600 | loge("getIccId: ICC ID is null or empty."); |
| 5601 | return null; |
| 5602 | } |
| 5603 | return iccId; |
| 5604 | } |
| 5605 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5606 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5607 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 5608 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5609 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5610 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5611 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5612 | final long identity = Binder.clearCallingIdentity(); |
| 5613 | try { |
| 5614 | final String iccId = getIccId(subId); |
| 5615 | final Phone phone = getPhone(subId); |
| 5616 | if (phone == null) { |
| 5617 | return false; |
| 5618 | } |
| 5619 | final String subscriberId = phone.getSubscriberId(); |
| 5620 | |
| 5621 | if (DBG_MERGE) { |
| 5622 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 5623 | + subscriberId + " to " + number); |
| 5624 | } |
| 5625 | |
| 5626 | if (TextUtils.isEmpty(iccId)) { |
| 5627 | return false; |
| 5628 | } |
| 5629 | |
| 5630 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 5631 | |
| 5632 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5633 | if (alphaTag == null) { |
| 5634 | editor.remove(alphaTagPrefKey); |
| 5635 | } else { |
| 5636 | editor.putString(alphaTagPrefKey, alphaTag); |
| 5637 | } |
| 5638 | |
| 5639 | // Record both the line number and IMSI for this ICCID, since we need to |
| 5640 | // track all merged IMSIs based on line number |
| 5641 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5642 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5643 | if (number == null) { |
| 5644 | editor.remove(numberPrefKey); |
| 5645 | editor.remove(subscriberPrefKey); |
| 5646 | } else { |
| 5647 | editor.putString(numberPrefKey, number); |
| 5648 | editor.putString(subscriberPrefKey, subscriberId); |
| 5649 | } |
| 5650 | |
| 5651 | editor.commit(); |
| 5652 | return true; |
| 5653 | } finally { |
| 5654 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5655 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5656 | } |
| 5657 | |
| 5658 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5659 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 5660 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 5661 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5662 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5663 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5664 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5665 | return null; |
| 5666 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5667 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5668 | final long identity = Binder.clearCallingIdentity(); |
| 5669 | try { |
| 5670 | String iccId = getIccId(subId); |
| 5671 | if (iccId != null) { |
| 5672 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5673 | if (DBG_MERGE) { |
| 5674 | log("getLine1NumberForDisplay returning " |
| 5675 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 5676 | } |
| 5677 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5678 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5679 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 5680 | return null; |
| 5681 | } finally { |
| 5682 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5683 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5684 | } |
| 5685 | |
| 5686 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5687 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 5688 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5689 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5690 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5691 | return null; |
| 5692 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5693 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5694 | final long identity = Binder.clearCallingIdentity(); |
| 5695 | try { |
| 5696 | String iccId = getIccId(subId); |
| 5697 | if (iccId != null) { |
| 5698 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5699 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 5700 | } |
| 5701 | return null; |
| 5702 | } finally { |
| 5703 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5704 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5705 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5706 | |
| 5707 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5708 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 5709 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5710 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 5711 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5712 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5713 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5714 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5715 | return null; |
| 5716 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5717 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5718 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 5719 | // the process, where TelephonyManager was instantiated. |
| 5720 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5721 | final long identity = Binder.clearCallingIdentity(); |
| 5722 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5723 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5724 | final TelephonyManager tele = TelephonyManager.from(context); |
| 5725 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 5726 | |
| 5727 | // Figure out what subscribers are currently active |
| 5728 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5729 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5730 | // Only consider subs which match the current subId |
| 5731 | // This logic can be simplified. See b/131189269 for progress. |
| 5732 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5733 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 5734 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5735 | |
| 5736 | // First pass, find a number override for an active subscriber |
| 5737 | String mergeNumber = null; |
| 5738 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 5739 | for (String key : prefs.keySet()) { |
| 5740 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 5741 | final String subscriberId = (String) prefs.get(key); |
| 5742 | if (activeSubscriberIds.contains(subscriberId)) { |
| 5743 | final String iccId = key.substring( |
| 5744 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 5745 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5746 | mergeNumber = (String) prefs.get(numberKey); |
| 5747 | if (DBG_MERGE) { |
| 5748 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 5749 | + " for active subscriber " + subscriberId); |
| 5750 | } |
| 5751 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 5752 | break; |
| 5753 | } |
| 5754 | } |
| 5755 | } |
| 5756 | } |
| 5757 | |
| 5758 | // Shortcut when no active merged subscribers |
| 5759 | if (TextUtils.isEmpty(mergeNumber)) { |
| 5760 | return null; |
| 5761 | } |
| 5762 | |
| 5763 | // Second pass, find all subscribers under that line override |
| 5764 | final ArraySet<String> result = new ArraySet<>(); |
| 5765 | for (String key : prefs.keySet()) { |
| 5766 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 5767 | final String number = (String) prefs.get(key); |
| 5768 | if (mergeNumber.equals(number)) { |
| 5769 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 5770 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5771 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 5772 | if (!TextUtils.isEmpty(subscriberId)) { |
| 5773 | result.add(subscriberId); |
| 5774 | } |
| 5775 | } |
| 5776 | } |
| 5777 | } |
| 5778 | |
| 5779 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 5780 | Arrays.sort(resultArray); |
| 5781 | if (DBG_MERGE) { |
| 5782 | Slog.d(LOG_TAG, |
| 5783 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 5784 | } |
| 5785 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5786 | } finally { |
| 5787 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5788 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5789 | } |
| 5790 | |
| 5791 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 5792 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 5793 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 5794 | |
| 5795 | final long identity = Binder.clearCallingIdentity(); |
| 5796 | try { |
| 5797 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 5798 | TelephonyManager.class); |
| 5799 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 5800 | if (subscriberId == null) { |
| 5801 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 5802 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 5803 | + subId); |
| 5804 | } |
| 5805 | return null; |
| 5806 | } |
| 5807 | |
| 5808 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 5809 | .getSubscriptionInfo(subId); |
| 5810 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 5811 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 5812 | if (groupUuid == null) { |
| 5813 | return new String[]{subscriberId}; |
| 5814 | } |
| 5815 | |
| 5816 | // Get all subscriberIds from the group. |
| 5817 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 5818 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5819 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 5820 | mApp.getFeatureId()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 5821 | for (SubscriptionInfo subInfo : groupInfos) { |
| 5822 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 5823 | if (subscriberId != null) { |
| 5824 | mergedSubscriberIds.add(subscriberId); |
| 5825 | } |
| 5826 | } |
| 5827 | |
| 5828 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 5829 | } finally { |
| 5830 | Binder.restoreCallingIdentity(identity); |
| 5831 | |
| 5832 | } |
| 5833 | } |
| 5834 | |
| 5835 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5836 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5837 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5838 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5839 | |
| 5840 | final long identity = Binder.clearCallingIdentity(); |
| 5841 | try { |
| 5842 | final Phone phone = getPhone(subId); |
| 5843 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 5844 | } finally { |
| 5845 | Binder.restoreCallingIdentity(identity); |
| 5846 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5847 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 5848 | |
| 5849 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5850 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5851 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 5852 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5853 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 5854 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5855 | |
| 5856 | final long identity = Binder.clearCallingIdentity(); |
| 5857 | try { |
| 5858 | final Phone phone = getPhone(subId); |
| 5859 | if (phone == null) { |
| 5860 | return false; |
| 5861 | } |
| 5862 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 5863 | cdmaNonRoamingList); |
| 5864 | } finally { |
| 5865 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5866 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5867 | } |
| 5868 | |
| 5869 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5870 | @Deprecated |
| 5871 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 5872 | enforceModifyPermission(); |
| 5873 | |
| 5874 | int returnValue = 0; |
| 5875 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5876 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5877 | if(result.exception == null) { |
| 5878 | if (result.result != null) { |
| 5879 | byte[] responseData = (byte[])(result.result); |
| 5880 | if(responseData.length > oemResp.length) { |
| 5881 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 5882 | responseData.length + "bytes. Buffer Size is " + |
| 5883 | oemResp.length + "bytes."); |
| 5884 | } |
| 5885 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 5886 | returnValue = responseData.length; |
| 5887 | } |
| 5888 | } else { |
| 5889 | CommandException ex = (CommandException) result.exception; |
| 5890 | returnValue = ex.getCommandError().ordinal(); |
| 5891 | if(returnValue > 0) returnValue *= -1; |
| 5892 | } |
| 5893 | } catch (RuntimeException e) { |
| 5894 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 5895 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 5896 | if(returnValue > 0) returnValue *= -1; |
| 5897 | } |
| 5898 | |
| 5899 | return returnValue; |
| 5900 | } |
| 5901 | |
| 5902 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5903 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 5904 | try { |
| 5905 | ProxyController.getInstance().setRadioCapability(rafs); |
| 5906 | } catch (RuntimeException e) { |
| 5907 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 5908 | } |
| 5909 | } |
| 5910 | |
| 5911 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5912 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5913 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5914 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5915 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5916 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5917 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5918 | final long identity = Binder.clearCallingIdentity(); |
| 5919 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5920 | TelephonyPermissions |
| 5921 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5922 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 5923 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5924 | } finally { |
| 5925 | Binder.restoreCallingIdentity(identity); |
| 5926 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5927 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5928 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5929 | |
| 5930 | @Override |
| 5931 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5932 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5933 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5934 | |
| 5935 | final long identity = Binder.clearCallingIdentity(); |
| 5936 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5937 | ImsManager.getInstance(defaultPhone.getContext(), |
| 5938 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5939 | } finally { |
| 5940 | Binder.restoreCallingIdentity(identity); |
| 5941 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5942 | } |
| 5943 | |
| 5944 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5945 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5946 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5947 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5948 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5949 | return false; |
| 5950 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5951 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5952 | final long identity = Binder.clearCallingIdentity(); |
| 5953 | try { |
| 5954 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 5955 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 5956 | // In the long run, we may instead need to check if there exists a connection service |
| 5957 | // which can support video calling. |
| 5958 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5959 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5960 | return imsManager.isVtEnabledByPlatform() |
| 5961 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 5962 | && imsManager.isVtEnabledByUser(); |
| 5963 | } finally { |
| 5964 | Binder.restoreCallingIdentity(identity); |
| 5965 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5966 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 5967 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5968 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5969 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 5970 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5971 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5972 | mApp, subId, callingPackage, callingFeatureId, |
| 5973 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5974 | return false; |
| 5975 | } |
| 5976 | |
| 5977 | final long identity = Binder.clearCallingIdentity(); |
| 5978 | try { |
| 5979 | CarrierConfigManager configManager = |
| 5980 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5981 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5982 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 5983 | } finally { |
| 5984 | Binder.restoreCallingIdentity(identity); |
| 5985 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5986 | } |
| 5987 | |
| 5988 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5989 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5990 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5991 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5992 | return false; |
| 5993 | } |
| 5994 | |
| 5995 | final long identity = Binder.clearCallingIdentity(); |
| 5996 | try { |
| 5997 | CarrierConfigManager configManager = |
| 5998 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5999 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6000 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 6001 | } finally { |
| 6002 | Binder.restoreCallingIdentity(identity); |
| 6003 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6004 | } |
| 6005 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6006 | @Override |
| 6007 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6008 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 6009 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6010 | } |
| 6011 | |
| 6012 | @Override |
| 6013 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6014 | final long identity = Binder.clearCallingIdentity(); |
| 6015 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6016 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6017 | } finally { |
| 6018 | Binder.restoreCallingIdentity(identity); |
| 6019 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6020 | } |
| 6021 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6022 | /** |
| 6023 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 6024 | * support for the feature and device firmware support. |
| 6025 | * |
| 6026 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 6027 | */ |
| 6028 | @Override |
| 6029 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6030 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6031 | final Phone phone = getPhone(subscriptionId); |
| 6032 | if (phone == null) { |
| 6033 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 6034 | return false; |
| 6035 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6036 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6037 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6038 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 6039 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6040 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6041 | return isCarrierSupported && isDeviceSupported; |
| 6042 | } finally { |
| 6043 | Binder.restoreCallingIdentity(identity); |
| 6044 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 6045 | } |
| 6046 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6047 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 6048 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 6049 | * RTT setting, will return true if the device and carrier both support RTT. |
| 6050 | * 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] | 6051 | */ |
| 6052 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6053 | final long identity = Binder.clearCallingIdentity(); |
| 6054 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 6055 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 6056 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 6057 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 6058 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 6059 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 6060 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6061 | } finally { |
| 6062 | Binder.restoreCallingIdentity(identity); |
| 6063 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 6064 | } |
| 6065 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6066 | @Deprecated |
| 6067 | @Override |
| 6068 | public String getDeviceId(String callingPackage) { |
| 6069 | return getDeviceIdWithFeature(callingPackage, null); |
| 6070 | } |
| 6071 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6072 | /** |
| 6073 | * Returns the unique device ID of phone, for example, the IMEI for |
| 6074 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 6075 | * |
| 6076 | * <p>Requires Permission: |
| 6077 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 6078 | */ |
| 6079 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6080 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6081 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6082 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6083 | return null; |
| 6084 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6085 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 6086 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6087 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6088 | return null; |
| 6089 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6090 | |
| 6091 | final long identity = Binder.clearCallingIdentity(); |
| 6092 | try { |
| 6093 | return phone.getDeviceId(); |
| 6094 | } finally { |
| 6095 | Binder.restoreCallingIdentity(identity); |
| 6096 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6097 | } |
| 6098 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6099 | /** |
| 6100 | * {@hide} |
| 6101 | * Returns the IMS Registration Status on a particular subid |
| 6102 | * |
| 6103 | * @param subId |
| 6104 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6105 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6106 | Phone phone = getPhone(subId); |
| 6107 | if (phone != null) { |
| 6108 | return phone.isImsRegistered(); |
| 6109 | } else { |
| 6110 | return false; |
| 6111 | } |
| 6112 | } |
| 6113 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6114 | @Override |
| 6115 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6116 | final long identity = Binder.clearCallingIdentity(); |
| 6117 | try { |
| 6118 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 6119 | } finally { |
| 6120 | Binder.restoreCallingIdentity(identity); |
| 6121 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6122 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 6123 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6124 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6125 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6126 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6127 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6128 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6129 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6130 | } |
| 6131 | final long identity = Binder.clearCallingIdentity(); |
| 6132 | try { |
| 6133 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 6134 | } finally { |
| 6135 | Binder.restoreCallingIdentity(identity); |
| 6136 | } |
| 6137 | } |
| 6138 | |
| 6139 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6140 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 6141 | final long identity = Binder.clearCallingIdentity(); |
| 6142 | try { |
| 6143 | Phone phone = getPhone(subscriptionId); |
| 6144 | if (phone == null) { |
| 6145 | return null; |
| 6146 | } |
| 6147 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 6148 | } finally { |
| 6149 | Binder.restoreCallingIdentity(identity); |
| 6150 | } |
| 6151 | } |
| 6152 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6153 | /** |
| 6154 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6155 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6156 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6157 | final long identity = Binder.clearCallingIdentity(); |
| 6158 | try { |
| 6159 | Phone phone = getPhone(subId); |
| 6160 | if (phone != null) { |
| 6161 | return phone.isWifiCallingEnabled(); |
| 6162 | } else { |
| 6163 | return false; |
| 6164 | } |
| 6165 | } finally { |
| 6166 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6167 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6168 | } |
| 6169 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6170 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6171 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6172 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6173 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6174 | final long identity = Binder.clearCallingIdentity(); |
| 6175 | try { |
| 6176 | Phone phone = getPhone(subId); |
| 6177 | if (phone != null) { |
| 6178 | return phone.isVideoEnabled(); |
| 6179 | } else { |
| 6180 | return false; |
| 6181 | } |
| 6182 | } finally { |
| 6183 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6184 | } |
| 6185 | } |
| 6186 | |
| 6187 | /** |
| 6188 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 6189 | * defined in {@link ImsRegistrationImplBase}. |
| 6190 | */ |
| 6191 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6192 | final long identity = Binder.clearCallingIdentity(); |
| 6193 | try { |
| 6194 | Phone phone = getPhone(subId); |
| 6195 | if (phone != null) { |
| 6196 | return phone.getImsRegistrationTech(); |
| 6197 | } else { |
| 6198 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 6199 | } |
| 6200 | } finally { |
| 6201 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6202 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6203 | } |
| 6204 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6205 | @Override |
| 6206 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 6207 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6208 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 6209 | return; |
| 6210 | } |
| 6211 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6212 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6213 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6214 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6215 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 6216 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6217 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6218 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6219 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6220 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 6221 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6222 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6223 | // There has been issues when Sms raw table somehow stores orphan |
| 6224 | // fragments. They lead to garbled message when new fragments come |
| 6225 | // in and combined with those stale ones. In case this happens again, |
| 6226 | // user can reset all network settings which will clean up this table. |
| 6227 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6228 | // Clean up IMS settings as well here. |
| 6229 | int slotId = getSlotIndex(subId); |
| 6230 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6231 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 6232 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 6233 | |
| 6234 | // Erase modem config if erase modem on network setting is enabled. |
| 6235 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 6236 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 6237 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 6238 | sendEraseModemConfig(getDefaultPhone()); |
| 6239 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6240 | } finally { |
| 6241 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6242 | } |
| 6243 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6244 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6245 | private void cleanUpSmsRawTable(Context context) { |
| 6246 | ContentResolver resolver = context.getContentResolver(); |
| 6247 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 6248 | resolver.delete(uri, null, null); |
| 6249 | } |
| 6250 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6251 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6252 | public String getSimLocaleForSubscriber(int subId) { |
| 6253 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 6254 | final Phone phone = getPhone(subId); |
| 6255 | if (phone == null) { |
| 6256 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 6257 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6258 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6259 | final long identity = Binder.clearCallingIdentity(); |
| 6260 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6261 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6262 | phone.getContext().getOpPackageName(), phone.getContext().getFeatureId()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 6263 | if (info == null) { |
| 6264 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 6265 | return null; |
| 6266 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6267 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 6268 | // preferences (EF-PL and EF-LI)... |
| 6269 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6270 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6271 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 6272 | if (localeFromDefaultSim != null) { |
| 6273 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 6274 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 6275 | + localeFromDefaultSim); |
| 6276 | return localeFromDefaultSim.toLanguageTag(); |
| 6277 | } else { |
| 6278 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6279 | } |
| 6280 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6281 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6282 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 6283 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 6284 | // the SIM and carrier preferences does not include a country we add the country |
| 6285 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 6286 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6287 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6288 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6289 | return mccLocale.toLanguageTag(); |
| 6290 | } |
| 6291 | |
| 6292 | if (DBG) log("No locale found - returning null"); |
| 6293 | return null; |
| 6294 | } finally { |
| 6295 | Binder.restoreCallingIdentity(identity); |
| 6296 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6297 | } |
| 6298 | |
| 6299 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6300 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
| 6301 | mApp.getFeatureId()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6302 | } |
| 6303 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6304 | /** |
| 6305 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 6306 | */ |
| 6307 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6308 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
| 6309 | mApp.getFeatureId()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6310 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6311 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6312 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6313 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6314 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6315 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6316 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 6317 | * representing the state of the modem. |
| 6318 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6319 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 6320 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6321 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6322 | */ |
| 6323 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6324 | public void requestModemActivityInfo(ResultReceiver result) { |
| 6325 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6326 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6327 | |
| 6328 | final long identity = Binder.clearCallingIdentity(); |
| 6329 | try { |
| 6330 | ModemActivityInfo ret = null; |
| 6331 | synchronized (mLastModemActivityInfo) { |
| 6332 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 6333 | CMD_GET_MODEM_ACTIVITY_INFO, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6334 | null, workSource); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6335 | if (isModemActivityInfoValid(info)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6336 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6337 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6338 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6339 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6340 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6341 | } |
| 6342 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6343 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 6344 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6345 | mLastModemActivityInfo.setIdleTimeMillis( |
| 6346 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6347 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 6348 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 6349 | info.getReceiveTimeMillis() + mLastModemActivityInfo |
| 6350 | .getReceiveTimeMillis()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6351 | } |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6352 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6353 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 6354 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 6355 | mLastModemActivityInfo.getIdleTimeMillis(), |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6356 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 6357 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6358 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6359 | Bundle bundle = new Bundle(); |
| 6360 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 6361 | result.send(0, bundle); |
| 6362 | } finally { |
| 6363 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6364 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6365 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6366 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6367 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 6368 | // less than total activity duration. |
| 6369 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 6370 | if (info == null) { |
| 6371 | return false; |
| 6372 | } |
| 6373 | int activityDurationMs = |
| 6374 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 6375 | int totalTxTimeMs = 0; |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6376 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6377 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 6378 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6379 | } |
| 6380 | return (info.isValid() |
| 6381 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 6382 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6383 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6384 | && (totalTxTimeMs <= activityDurationMs)); |
| 6385 | } |
| 6386 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6387 | /** |
| 6388 | * {@hide} |
| 6389 | * Returns the service state information on specified subscription. |
| 6390 | */ |
| 6391 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6392 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 6393 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6394 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6395 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6396 | return null; |
| 6397 | } |
| 6398 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6399 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 6400 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6401 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6402 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6403 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6404 | .setCallingPid(Binder.getCallingPid()) |
| 6405 | .setCallingUid(Binder.getCallingUid()) |
| 6406 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6407 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6408 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6409 | .build()); |
| 6410 | |
| 6411 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 6412 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6413 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6414 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6415 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6416 | .setCallingPid(Binder.getCallingPid()) |
| 6417 | .setCallingUid(Binder.getCallingUid()) |
| 6418 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6419 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6420 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6421 | .build()); |
| 6422 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 6423 | boolean hasFinePermission = |
| 6424 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6425 | boolean hasCoarsePermission = |
| 6426 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6427 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6428 | final long identity = Binder.clearCallingIdentity(); |
| 6429 | try { |
| 6430 | final Phone phone = getPhone(subId); |
| 6431 | if (phone == null) { |
| 6432 | return null; |
| 6433 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6434 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6435 | ServiceState ss = phone.getServiceState(); |
| 6436 | |
| 6437 | // Scrub out the location info in ServiceState depending on what level of access |
| 6438 | // the caller has. |
| 6439 | if (hasFinePermission) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 6440 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 6441 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6442 | } finally { |
| 6443 | Binder.restoreCallingIdentity(identity); |
| 6444 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6445 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6446 | |
| 6447 | /** |
| 6448 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 6449 | * |
| 6450 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6451 | * voicemail ringtone. |
| 6452 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 6453 | * PhoneAccount. |
| 6454 | */ |
| 6455 | @Override |
| 6456 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6457 | final long identity = Binder.clearCallingIdentity(); |
| 6458 | try { |
| 6459 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6460 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6461 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6462 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6463 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6464 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 6465 | } finally { |
| 6466 | Binder.restoreCallingIdentity(identity); |
| 6467 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6468 | } |
| 6469 | |
| 6470 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6471 | * Sets the per-account voicemail ringtone. |
| 6472 | * |
| 6473 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6474 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6475 | * |
| 6476 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6477 | * voicemail ringtone. |
| 6478 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 6479 | * PhoneAccount. |
| 6480 | */ |
| 6481 | @Override |
| 6482 | public void setVoicemailRingtoneUri(String callingPackage, |
| 6483 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6484 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6485 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6486 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6487 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6488 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6489 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6490 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6491 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6492 | |
| 6493 | final long identity = Binder.clearCallingIdentity(); |
| 6494 | try { |
| 6495 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6496 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6497 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6498 | } |
| 6499 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 6500 | } finally { |
| 6501 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6502 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6503 | } |
| 6504 | |
| 6505 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6506 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 6507 | * |
| 6508 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6509 | * voicemail vibration setting. |
| 6510 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 6511 | */ |
| 6512 | @Override |
| 6513 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6514 | final long identity = Binder.clearCallingIdentity(); |
| 6515 | try { |
| 6516 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6517 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6518 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6519 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6520 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6521 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 6522 | } finally { |
| 6523 | Binder.restoreCallingIdentity(identity); |
| 6524 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6525 | } |
| 6526 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6527 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6528 | * Sets the per-account voicemail vibration. |
| 6529 | * |
| 6530 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6531 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6532 | * |
| 6533 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6534 | * voicemail vibration setting. |
| 6535 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 6536 | * specific PhoneAccount. |
| 6537 | */ |
| 6538 | @Override |
| 6539 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 6540 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6541 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6542 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6543 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6544 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6545 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6546 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6547 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6548 | } |
| 6549 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6550 | final long identity = Binder.clearCallingIdentity(); |
| 6551 | try { |
| 6552 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6553 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6554 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6555 | } |
| 6556 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 6557 | } finally { |
| 6558 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6559 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6560 | } |
| 6561 | |
| 6562 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6563 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 6564 | * |
| 6565 | * @throws SecurityException if the caller does not have the required permission |
| 6566 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6567 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6568 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6569 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6570 | } |
| 6571 | |
| 6572 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6573 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 6574 | * permission. |
| 6575 | * |
| 6576 | * @throws SecurityException if the caller does not have the required permission |
| 6577 | */ |
| 6578 | private void enforceSendSmsPermission() { |
| 6579 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 6580 | } |
| 6581 | |
| 6582 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6583 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6584 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6585 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6586 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6587 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6588 | final long identity = Binder.clearCallingIdentity(); |
| 6589 | try { |
| 6590 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6591 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6592 | if (componentName == null) { |
| 6593 | throw new SecurityException( |
| 6594 | "Caller not current active visual voicemail package[null]"); |
| 6595 | } |
| 6596 | String vvmPackage = componentName.getPackageName(); |
| 6597 | if (!callingPackage.equals(vvmPackage)) { |
| 6598 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 6599 | + vvmPackage + "]"); |
| 6600 | } |
| 6601 | } finally { |
| 6602 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6603 | } |
| 6604 | } |
| 6605 | |
| 6606 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6607 | * Return the application ID for the app type. |
| 6608 | * |
| 6609 | * @param subId the subscription ID that this request applies to. |
| 6610 | * @param appType the uicc app type. |
| 6611 | * @return Application ID for specificied app type, or null if no uicc. |
| 6612 | */ |
| 6613 | @Override |
| 6614 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6615 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6616 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6617 | |
| 6618 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6619 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6620 | if (phone == null) { |
| 6621 | return null; |
| 6622 | } |
| 6623 | String aid = null; |
| 6624 | try { |
| 6625 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 6626 | .getApplicationByType(appType).getAid(); |
| 6627 | } catch (Exception e) { |
| 6628 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 6629 | } |
| 6630 | return aid; |
| 6631 | } finally { |
| 6632 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6633 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6634 | } |
| 6635 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6636 | /** |
| 6637 | * Return the Electronic Serial Number. |
| 6638 | * |
| 6639 | * @param subId the subscription ID that this request applies to. |
| 6640 | * @return ESN or null if error. |
| 6641 | */ |
| 6642 | @Override |
| 6643 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6644 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6645 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6646 | |
| 6647 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6648 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6649 | if (phone == null) { |
| 6650 | return null; |
| 6651 | } |
| 6652 | String esn = null; |
| 6653 | try { |
| 6654 | esn = phone.getEsn(); |
| 6655 | } catch (Exception e) { |
| 6656 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 6657 | } |
| 6658 | return esn; |
| 6659 | } finally { |
| 6660 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6661 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6662 | } |
| 6663 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6664 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6665 | * Return the Preferred Roaming List Version. |
| 6666 | * |
| 6667 | * @param subId the subscription ID that this request applies to. |
| 6668 | * @return PRLVersion or null if error. |
| 6669 | */ |
| 6670 | @Override |
| 6671 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6672 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6673 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6674 | |
| 6675 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6676 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6677 | if (phone == null) { |
| 6678 | return null; |
| 6679 | } |
| 6680 | String cdmaPrlVersion = null; |
| 6681 | try { |
| 6682 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 6683 | } catch (Exception e) { |
| 6684 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 6685 | } |
| 6686 | return cdmaPrlVersion; |
| 6687 | } finally { |
| 6688 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6689 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6690 | } |
| 6691 | |
| 6692 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6693 | * Get snapshot of Telephony histograms |
| 6694 | * @return List of Telephony histograms |
| 6695 | * @hide |
| 6696 | */ |
| 6697 | @Override |
| 6698 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6699 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6700 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6701 | |
| 6702 | final long identity = Binder.clearCallingIdentity(); |
| 6703 | try { |
| 6704 | return RIL.getTelephonyRILTimingHistograms(); |
| 6705 | } finally { |
| 6706 | Binder.restoreCallingIdentity(identity); |
| 6707 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6708 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6709 | |
| 6710 | /** |
| 6711 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6712 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 6713 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6714 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6715 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6716 | * @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] | 6717 | */ |
| 6718 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6719 | @TelephonyManager.SetCarrierRestrictionResult |
| 6720 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6721 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6722 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6723 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6724 | if (carrierRestrictionRules == null) { |
| 6725 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 6726 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6727 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6728 | final long identity = Binder.clearCallingIdentity(); |
| 6729 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6730 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6731 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6732 | } finally { |
| 6733 | Binder.restoreCallingIdentity(identity); |
| 6734 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6735 | } |
| 6736 | |
| 6737 | /** |
| 6738 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6739 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 6740 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6741 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6742 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6743 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6744 | */ |
| 6745 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6746 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6747 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6748 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6749 | |
| 6750 | final long identity = Binder.clearCallingIdentity(); |
| 6751 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6752 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 6753 | if (response instanceof CarrierRestrictionRules) { |
| 6754 | return (CarrierRestrictionRules) response; |
| 6755 | } |
| 6756 | // Response is an Exception of some kind, |
| 6757 | // which is signalled to the user as a NULL retval |
| 6758 | return null; |
| 6759 | } catch (Exception e) { |
| 6760 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 6761 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6762 | } finally { |
| 6763 | Binder.restoreCallingIdentity(identity); |
| 6764 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6765 | } |
| 6766 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6767 | /** |
| 6768 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 6769 | * @param subId the subscription ID that this action applies to. |
| 6770 | * @param enabled control enable or disable metered apns. |
| 6771 | * {@hide} |
| 6772 | */ |
| 6773 | @Override |
| 6774 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 6775 | enforceModifyPermission(); |
| 6776 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6777 | |
| 6778 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6779 | if (phone == null) { |
| 6780 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 6781 | return; |
| 6782 | } |
| 6783 | try { |
| 6784 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 6785 | } catch (Exception e) { |
| 6786 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6787 | } finally { |
| 6788 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6789 | } |
| 6790 | } |
| 6791 | |
| 6792 | /** |
| 6793 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 6794 | * @param subId the subscription ID that this action applies to. |
| 6795 | * @param enabled control enable or disable radio. |
| 6796 | * {@hide} |
| 6797 | */ |
| 6798 | @Override |
| 6799 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 6800 | enforceModifyPermission(); |
| 6801 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6802 | |
| 6803 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6804 | if (phone == null) { |
| 6805 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 6806 | return; |
| 6807 | } |
| 6808 | try { |
| 6809 | phone.carrierActionSetRadioEnabled(enabled); |
| 6810 | } catch (Exception e) { |
| 6811 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6812 | } finally { |
| 6813 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6814 | } |
| 6815 | } |
| 6816 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6817 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6818 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 6819 | * network status based on which carrier apps could apply actions accordingly, |
| 6820 | * enable/disable default url handler for example. |
| 6821 | * |
| 6822 | * @param subId the subscription ID that this action applies to. |
| 6823 | * @param report control start/stop reporting the default network status. |
| 6824 | * {@hide} |
| 6825 | */ |
| 6826 | @Override |
| 6827 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 6828 | enforceModifyPermission(); |
| 6829 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6830 | |
| 6831 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6832 | if (phone == null) { |
| 6833 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 6834 | return; |
| 6835 | } |
| 6836 | try { |
| 6837 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 6838 | } catch (Exception e) { |
| 6839 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6840 | } finally { |
| 6841 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6842 | } |
| 6843 | } |
| 6844 | |
| 6845 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 6846 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 6847 | * @param subId the subscription ID that this action applies to. |
| 6848 | * {@hide} |
| 6849 | */ |
| 6850 | @Override |
| 6851 | public void carrierActionResetAll(int subId) { |
| 6852 | enforceModifyPermission(); |
| 6853 | final Phone phone = getPhone(subId); |
| 6854 | if (phone == null) { |
| 6855 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 6856 | return; |
| 6857 | } |
| 6858 | try { |
| 6859 | phone.carrierActionResetAll(); |
| 6860 | } catch (Exception e) { |
| 6861 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 6862 | } |
| 6863 | } |
| 6864 | |
| 6865 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6866 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 6867 | * bug report is being generated. |
| 6868 | */ |
| 6869 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 6870 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6871 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 6872 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 6873 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 6874 | + Binder.getCallingPid() |
| 6875 | + ", uid=" + Binder.getCallingUid() |
| 6876 | + "without permission " |
| 6877 | + android.Manifest.permission.DUMP); |
| 6878 | return; |
| 6879 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6880 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6881 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6882 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6883 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 6884 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 6885 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 6886 | @NonNull String[] args) { |
| 6887 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 6888 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 6889 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6890 | } |
| 6891 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6892 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6893 | * Get aggregated video call data usage since boot. |
| 6894 | * |
| 6895 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 6896 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6897 | * {@hide} |
| 6898 | */ |
| 6899 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6900 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6901 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 6902 | null); |
| 6903 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6904 | final long identity = Binder.clearCallingIdentity(); |
| 6905 | try { |
| 6906 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 6907 | // records the delta with the corresponding network identity. |
| 6908 | // We just return the total video call data usage snapshot since boot. |
| 6909 | Phone phone = getPhone(subId); |
| 6910 | if (phone != null) { |
| 6911 | return phone.getVtDataUsage(perUidStats); |
| 6912 | } |
| 6913 | return null; |
| 6914 | } finally { |
| 6915 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6916 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6917 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6918 | |
| 6919 | /** |
| 6920 | * Policy control of data connection. Usually used when data limit is passed. |
| 6921 | * @param enabled True if enabling the data, otherwise disabling. |
| 6922 | * @param subId Subscription index |
| 6923 | * {@hide} |
| 6924 | */ |
| 6925 | @Override |
| 6926 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 6927 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6928 | |
| 6929 | final long identity = Binder.clearCallingIdentity(); |
| 6930 | try { |
| 6931 | Phone phone = getPhone(subId); |
| 6932 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6933 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6934 | } |
| 6935 | } finally { |
| 6936 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6937 | } |
| 6938 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6939 | |
| 6940 | /** |
| 6941 | * Get Client request stats |
| 6942 | * @return List of Client Request Stats |
| 6943 | * @hide |
| 6944 | */ |
| 6945 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6946 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 6947 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6948 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6949 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6950 | return null; |
| 6951 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6952 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6953 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6954 | final long identity = Binder.clearCallingIdentity(); |
| 6955 | try { |
| 6956 | if (phone != null) { |
| 6957 | return phone.getClientRequestStats(); |
| 6958 | } |
| 6959 | |
| 6960 | return null; |
| 6961 | } finally { |
| 6962 | Binder.restoreCallingIdentity(identity); |
| 6963 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6964 | } |
| 6965 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6966 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6967 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6968 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6969 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6970 | |
| 6971 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6972 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6973 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6974 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6975 | * @param state State of SIM (power down, power up, pass through) |
| 6976 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 6977 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 6978 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6979 | * |
| 6980 | **/ |
| 6981 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6982 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6983 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6984 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6985 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6986 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6987 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6988 | final long identity = Binder.clearCallingIdentity(); |
| 6989 | try { |
| 6990 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6991 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6992 | } |
| 6993 | } finally { |
| 6994 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6995 | } |
| 6996 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6997 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6998 | private boolean isUssdApiAllowed(int subId) { |
| 6999 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7000 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7001 | if (configManager == null) { |
| 7002 | return false; |
| 7003 | } |
| 7004 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 7005 | if (pb == null) { |
| 7006 | return false; |
| 7007 | } |
| 7008 | return pb.getBoolean( |
| 7009 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 7010 | } |
| 7011 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7012 | /** |
| 7013 | * Check if phone is in emergency callback mode |
| 7014 | * @return true if phone is in emergency callback mode |
| 7015 | * @param subId sub id |
| 7016 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 7017 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7018 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7019 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7020 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7021 | |
| 7022 | final long identity = Binder.clearCallingIdentity(); |
| 7023 | try { |
| 7024 | if (phone != null) { |
| 7025 | return phone.isInEcm(); |
| 7026 | } else { |
| 7027 | return false; |
| 7028 | } |
| 7029 | } finally { |
| 7030 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7031 | } |
| 7032 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7033 | |
| 7034 | /** |
| 7035 | * Get the current signal strength information for the given subscription. |
| 7036 | * Because this information is not updated when the device is in a low power state |
| 7037 | * it should not be relied-upon to be current. |
| 7038 | * @param subId Subscription index |
| 7039 | * @return the most recent cached signal strength info from the modem |
| 7040 | */ |
| 7041 | @Override |
| 7042 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7043 | final long identity = Binder.clearCallingIdentity(); |
| 7044 | try { |
| 7045 | Phone p = getPhone(subId); |
| 7046 | if (p == null) { |
| 7047 | return null; |
| 7048 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7049 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7050 | return p.getSignalStrength(); |
| 7051 | } finally { |
| 7052 | Binder.restoreCallingIdentity(identity); |
| 7053 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7054 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7055 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7056 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7057 | * Get the current modem radio state for the given slot. |
| 7058 | * @param slotIndex slot index. |
| 7059 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7060 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7061 | * @return the current radio power state from the modem |
| 7062 | */ |
| 7063 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7064 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7065 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7066 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7067 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 7068 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7069 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7070 | } |
| 7071 | |
| 7072 | final long identity = Binder.clearCallingIdentity(); |
| 7073 | try { |
| 7074 | return phone.getRadioPowerState(); |
| 7075 | } finally { |
| 7076 | Binder.restoreCallingIdentity(identity); |
| 7077 | } |
| 7078 | } |
| 7079 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7080 | } |
| 7081 | |
| 7082 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7083 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 7084 | * |
| 7085 | * <p>Requires one of the following permissions: |
| 7086 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 7087 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 7088 | * privileges. |
| 7089 | * |
| 7090 | * @param subId subscription id |
| 7091 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 7092 | * {@code false}. |
| 7093 | */ |
| 7094 | @Override |
| 7095 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7096 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7097 | null /* message */); |
| 7098 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7099 | boolean isEnabled = false; |
| 7100 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7101 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7102 | Phone phone = getPhone(subId); |
| 7103 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7104 | } catch (Exception e) { |
| 7105 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 7106 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7107 | } finally { |
| 7108 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7109 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7110 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7111 | } |
| 7112 | |
| 7113 | |
| 7114 | /** |
| 7115 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 7116 | * |
| 7117 | * <p> Requires permission: |
| 7118 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 7119 | * privileges. |
| 7120 | * |
| 7121 | * @param subId subscription id |
| 7122 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 7123 | */ |
| 7124 | @Override |
| 7125 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7126 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7127 | mApp, subId, "setDataRoamingEnabled"); |
| 7128 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7129 | final long identity = Binder.clearCallingIdentity(); |
| 7130 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7131 | Phone phone = getPhone(subId); |
| 7132 | if (phone != null) { |
| 7133 | phone.setDataRoamingEnabled(isEnabled); |
| 7134 | } |
| 7135 | } finally { |
| 7136 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7137 | } |
| 7138 | } |
| 7139 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7140 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7141 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 7142 | TelephonyPermissions |
| 7143 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7144 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 7145 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7146 | boolean isAllowed = true; |
| 7147 | final long identity = Binder.clearCallingIdentity(); |
| 7148 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7149 | Phone phone = getPhone(subId); |
| 7150 | if (phone != null) { |
| 7151 | isAllowed = phone.isCspPlmnEnabled(); |
| 7152 | } |
| 7153 | } finally { |
| 7154 | Binder.restoreCallingIdentity(identity); |
| 7155 | } |
| 7156 | return isAllowed; |
| 7157 | } |
| 7158 | |
| 7159 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7160 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7161 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7162 | try { |
| 7163 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7164 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7165 | } catch (SecurityException e) { |
| 7166 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 7167 | // has carrier privileges on an active UICC |
| 7168 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 7169 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7170 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7171 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7172 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7173 | |
| 7174 | final long identity = Binder.clearCallingIdentity(); |
| 7175 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7176 | UiccController uiccController = UiccController.getInstance(); |
| 7177 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7178 | if (hasReadPermission) { |
| 7179 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7180 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7181 | |
| 7182 | // Remove private info if the caller doesn't have access |
| 7183 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 7184 | for (UiccCardInfo cardInfo : cardInfos) { |
| 7185 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 7186 | // is available |
| 7187 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 7188 | if (card == null || card.getUiccProfile() == null) { |
| 7189 | // assume no access if the card or profile is unavailable |
| 7190 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7191 | continue; |
| 7192 | } |
| 7193 | UiccProfile profile = card.getUiccProfile(); |
| 7194 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 7195 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7196 | filteredInfos.add(cardInfo); |
| 7197 | } else { |
| 7198 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7199 | } |
| 7200 | } |
| 7201 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7202 | } finally { |
| 7203 | Binder.restoreCallingIdentity(identity); |
| 7204 | } |
| 7205 | } |
| 7206 | |
| 7207 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7208 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7209 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7210 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7211 | final long identity = Binder.clearCallingIdentity(); |
| 7212 | try { |
| 7213 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 7214 | if (slots == null) { |
| 7215 | Rlog.i(LOG_TAG, "slots is null."); |
| 7216 | return null; |
| 7217 | } |
| 7218 | |
| 7219 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 7220 | for (int i = 0; i < slots.length; i++) { |
| 7221 | UiccSlot slot = slots[i]; |
| 7222 | if (slot == null) { |
| 7223 | continue; |
| 7224 | } |
| 7225 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7226 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7227 | UiccCard card = slot.getUiccCard(); |
| 7228 | if (card != null) { |
| 7229 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7230 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 7231 | cardId = slot.getEid(); |
| 7232 | if (TextUtils.isEmpty(cardId)) { |
| 7233 | cardId = slot.getIccId(); |
| 7234 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7235 | } |
| 7236 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 7237 | if (cardId != null) { |
| 7238 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 7239 | // if cardId is an EID, it's all digits so this is fine |
| 7240 | cardId = IccUtils.stripTrailingFs(cardId); |
| 7241 | } |
| 7242 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7243 | int cardState = 0; |
| 7244 | switch (slot.getCardState()) { |
| 7245 | case CARDSTATE_ABSENT: |
| 7246 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 7247 | break; |
| 7248 | case CARDSTATE_PRESENT: |
| 7249 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 7250 | break; |
| 7251 | case CARDSTATE_ERROR: |
| 7252 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 7253 | break; |
| 7254 | case CARDSTATE_RESTRICTED: |
| 7255 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 7256 | break; |
| 7257 | default: |
| 7258 | break; |
| 7259 | |
| 7260 | } |
| 7261 | |
| 7262 | infos[i] = new UiccSlotInfo( |
| 7263 | slot.isActive(), |
| 7264 | slot.isEuicc(), |
| 7265 | cardId, |
| 7266 | cardState, |
| 7267 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 7268 | slot.isExtendedApduSupported(), |
| 7269 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7270 | } |
| 7271 | return infos; |
| 7272 | } finally { |
| 7273 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 7274 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7275 | } |
| 7276 | |
| 7277 | @Override |
| 7278 | public boolean switchSlots(int[] physicalSlots) { |
| 7279 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7280 | |
| 7281 | final long identity = Binder.clearCallingIdentity(); |
| 7282 | try { |
| 7283 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 7284 | } finally { |
| 7285 | Binder.restoreCallingIdentity(identity); |
| 7286 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7287 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7288 | |
| 7289 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7290 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7291 | final long identity = Binder.clearCallingIdentity(); |
| 7292 | try { |
| 7293 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 7294 | } finally { |
| 7295 | Binder.restoreCallingIdentity(identity); |
| 7296 | } |
| 7297 | } |
| 7298 | |
| 7299 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7300 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 7301 | enforceModifyPermission(); |
| 7302 | final Phone phone = getPhone(subId); |
| 7303 | if (phone == null) { |
| 7304 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 7305 | return; |
| 7306 | } |
| 7307 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7308 | final long identity = Binder.clearCallingIdentity(); |
| 7309 | try { |
| 7310 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 7311 | } finally { |
| 7312 | Binder.restoreCallingIdentity(identity); |
| 7313 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7314 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7315 | |
| 7316 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 7317 | * A test API to reload the UICC profile. |
| 7318 | * |
| 7319 | * <p>Requires that the calling app has permission |
| 7320 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7321 | * @hide |
| 7322 | */ |
| 7323 | @Override |
| 7324 | public void refreshUiccProfile(int subId) { |
| 7325 | enforceModifyPermission(); |
| 7326 | |
| 7327 | final long identity = Binder.clearCallingIdentity(); |
| 7328 | try { |
| 7329 | Phone phone = getPhone(subId); |
| 7330 | if (phone == null) { |
| 7331 | return; |
| 7332 | } |
| 7333 | UiccCard uiccCard = phone.getUiccCard(); |
| 7334 | if (uiccCard == null) { |
| 7335 | return; |
| 7336 | } |
| 7337 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7338 | if (uiccProfile == null) { |
| 7339 | return; |
| 7340 | } |
| 7341 | uiccProfile.refresh(); |
| 7342 | } finally { |
| 7343 | Binder.restoreCallingIdentity(identity); |
| 7344 | } |
| 7345 | } |
| 7346 | |
| 7347 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7348 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 7349 | */ |
| 7350 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7351 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7352 | } |
| 7353 | |
| 7354 | /** |
| 7355 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 7356 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 7357 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 7358 | */ |
| 7359 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 7360 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7361 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7362 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7363 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 7364 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 7365 | return isDataRoamingEnabled; |
| 7366 | } |
| 7367 | |
| 7368 | /** |
| 7369 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 7370 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 7371 | */ |
| 7372 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7373 | List<Integer> list = TelephonyProperties.default_network(); |
| 7374 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 7375 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 7376 | return list.get(phoneId); |
| 7377 | } |
| 7378 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7379 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7380 | |
| 7381 | @Override |
| 7382 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7383 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7384 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7385 | |
| 7386 | final long identity = Binder.clearCallingIdentity(); |
| 7387 | try { |
| 7388 | final Phone phone = getPhone(subId); |
| 7389 | if (phone == null) { |
| 7390 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 7391 | return; |
| 7392 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7393 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 7394 | carrierPrivilegeRules, apn); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7395 | } finally { |
| 7396 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7397 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7398 | } |
| 7399 | |
| 7400 | @Override |
| 7401 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7402 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7403 | |
| 7404 | final long identity = Binder.clearCallingIdentity(); |
| 7405 | try { |
| 7406 | final Phone phone = getPhone(subId); |
| 7407 | if (phone == null) { |
| 7408 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 7409 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 7410 | } |
| 7411 | return phone.getCarrierIdListVersion(); |
| 7412 | } finally { |
| 7413 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7414 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7415 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7416 | |
| 7417 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7418 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 7419 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7420 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7421 | mApp, subId, callingPackage, callingFeatureId, |
| 7422 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7423 | return -1; |
| 7424 | } |
| 7425 | |
| 7426 | final long identity = Binder.clearCallingIdentity(); |
| 7427 | try { |
| 7428 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 7429 | } finally { |
| 7430 | Binder.restoreCallingIdentity(identity); |
| 7431 | } |
| 7432 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7433 | |
| 7434 | @Override |
| 7435 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 7436 | TelephonyPermissions |
| 7437 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7438 | mApp, subId, "getCdmaRoamingMode"); |
| 7439 | |
| 7440 | final long identity = Binder.clearCallingIdentity(); |
| 7441 | try { |
| 7442 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 7443 | } finally { |
| 7444 | Binder.restoreCallingIdentity(identity); |
| 7445 | } |
| 7446 | } |
| 7447 | |
| 7448 | @Override |
| 7449 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 7450 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7451 | mApp, subId, "setCdmaRoamingMode"); |
| 7452 | |
| 7453 | final long identity = Binder.clearCallingIdentity(); |
| 7454 | try { |
| 7455 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 7456 | } finally { |
| 7457 | Binder.restoreCallingIdentity(identity); |
| 7458 | } |
| 7459 | } |
| 7460 | |
| 7461 | @Override |
| 7462 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 7463 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7464 | mApp, subId, "setCdmaSubscriptionMode"); |
| 7465 | |
| 7466 | final long identity = Binder.clearCallingIdentity(); |
| 7467 | try { |
| 7468 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 7469 | } finally { |
| 7470 | Binder.restoreCallingIdentity(identity); |
| 7471 | } |
| 7472 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 7473 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7474 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7475 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7476 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7477 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7478 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 7479 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7480 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7481 | } |
| 7482 | final long identity = Binder.clearCallingIdentity(); |
| 7483 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7484 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 7485 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7486 | if (phone.getEmergencyNumberTracker() != null |
| 7487 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 7488 | emergencyNumberListInternal.put( |
| 7489 | phone.getSubId(), |
| 7490 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 7491 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7492 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7493 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7494 | } finally { |
| 7495 | Binder.restoreCallingIdentity(identity); |
| 7496 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7497 | } |
| 7498 | |
| 7499 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7500 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7501 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7502 | if (!exactMatch) { |
| 7503 | TelephonyPermissions |
| 7504 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7505 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7506 | } |
| 7507 | final long identity = Binder.clearCallingIdentity(); |
| 7508 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7509 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7510 | if (phone.getEmergencyNumberTracker() != null |
| 7511 | && phone.getEmergencyNumberTracker() != null) { |
| 7512 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 7513 | number, exactMatch)) { |
| 7514 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7515 | } |
| 7516 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7517 | } |
| 7518 | return false; |
| 7519 | } finally { |
| 7520 | Binder.restoreCallingIdentity(identity); |
| 7521 | } |
| 7522 | } |
| 7523 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 7524 | /** |
| 7525 | * Update emergency number list for test mode. |
| 7526 | */ |
| 7527 | @Override |
| 7528 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 7529 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7530 | "updateEmergencyNumberListTestMode"); |
| 7531 | |
| 7532 | final long identity = Binder.clearCallingIdentity(); |
| 7533 | try { |
| 7534 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7535 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7536 | if (tracker != null) { |
| 7537 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 7538 | } |
| 7539 | } |
| 7540 | } finally { |
| 7541 | Binder.restoreCallingIdentity(identity); |
| 7542 | } |
| 7543 | } |
| 7544 | |
| 7545 | /** |
| 7546 | * Get the full emergency number list for test mode. |
| 7547 | */ |
| 7548 | @Override |
| 7549 | public List<String> getEmergencyNumberListTestMode() { |
| 7550 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7551 | "getEmergencyNumberListTestMode"); |
| 7552 | |
| 7553 | final long identity = Binder.clearCallingIdentity(); |
| 7554 | try { |
| 7555 | Set<String> emergencyNumbers = new HashSet<>(); |
| 7556 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7557 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7558 | if (tracker != null) { |
| 7559 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 7560 | emergencyNumbers.add(num.getNumber()); |
| 7561 | } |
| 7562 | } |
| 7563 | } |
| 7564 | return new ArrayList<>(emergencyNumbers); |
| 7565 | } finally { |
| 7566 | Binder.restoreCallingIdentity(identity); |
| 7567 | } |
| 7568 | } |
| 7569 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7570 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7571 | public int getEmergencyNumberDbVersion(int subId) { |
| 7572 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 7573 | |
| 7574 | final long identity = Binder.clearCallingIdentity(); |
| 7575 | try { |
| 7576 | final Phone phone = getPhone(subId); |
| 7577 | if (phone == null) { |
| 7578 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 7579 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 7580 | } |
| 7581 | return phone.getEmergencyNumberDbVersion(); |
| 7582 | } finally { |
| 7583 | Binder.restoreCallingIdentity(identity); |
| 7584 | } |
| 7585 | } |
| 7586 | |
| 7587 | @Override |
| 7588 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 7589 | enforceModifyPermission(); |
| 7590 | |
| 7591 | final long identity = Binder.clearCallingIdentity(); |
| 7592 | try { |
| 7593 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7594 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7595 | if (tracker != null) { |
| 7596 | tracker.updateOtaEmergencyNumberDatabase(); |
| 7597 | } |
| 7598 | } |
| 7599 | } finally { |
| 7600 | Binder.restoreCallingIdentity(identity); |
| 7601 | } |
| 7602 | } |
| 7603 | |
| 7604 | @Override |
| 7605 | public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) { |
| 7606 | enforceActiveEmergencySessionPermission(); |
| 7607 | |
| 7608 | final long identity = Binder.clearCallingIdentity(); |
| 7609 | try { |
| 7610 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7611 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7612 | if (tracker != null) { |
| 7613 | tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath); |
| 7614 | } |
| 7615 | } |
| 7616 | } finally { |
| 7617 | Binder.restoreCallingIdentity(identity); |
| 7618 | } |
| 7619 | } |
| 7620 | |
| 7621 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7622 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 7623 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 7624 | Phone phone = getPhone(subId); |
| 7625 | if (phone == null) { |
| 7626 | return null; |
| 7627 | } |
| 7628 | final long identity = Binder.clearCallingIdentity(); |
| 7629 | try { |
| 7630 | UiccProfile profile = UiccController.getInstance() |
| 7631 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 7632 | if (profile != null) { |
| 7633 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 7634 | } |
| 7635 | } finally { |
| 7636 | Binder.restoreCallingIdentity(identity); |
| 7637 | } |
| 7638 | return null; |
| 7639 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 7640 | |
| 7641 | /** |
| 7642 | * Enable or disable a modem stack. |
| 7643 | */ |
| 7644 | @Override |
| 7645 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 7646 | enforceModifyPermission(); |
| 7647 | |
| 7648 | final long identity = Binder.clearCallingIdentity(); |
| 7649 | try { |
| 7650 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7651 | if (phone == null) { |
| 7652 | return false; |
| 7653 | } else { |
| 7654 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 7655 | } |
| 7656 | } finally { |
| 7657 | Binder.restoreCallingIdentity(identity); |
| 7658 | } |
| 7659 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7660 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7661 | /** |
| 7662 | * Whether a modem stack is enabled or not. |
| 7663 | */ |
| 7664 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7665 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 7666 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7667 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7668 | if (phone == null) return false; |
| 7669 | |
| 7670 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7671 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 7672 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7673 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7674 | } |
| 7675 | |
| 7676 | final long identity = Binder.clearCallingIdentity(); |
| 7677 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 7678 | try { |
| 7679 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 7680 | } catch (NoSuchElementException ex) { |
| 7681 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 7682 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7683 | } finally { |
| 7684 | Binder.restoreCallingIdentity(identity); |
| 7685 | } |
| 7686 | } |
| 7687 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7688 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7689 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7690 | enforceModifyPermission(); |
| 7691 | |
| 7692 | final long identity = Binder.clearCallingIdentity(); |
| 7693 | try { |
| 7694 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7695 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7696 | .commit(); |
| 7697 | } finally { |
| 7698 | Binder.restoreCallingIdentity(identity); |
| 7699 | } |
| 7700 | } |
| 7701 | |
| 7702 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7703 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7704 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7705 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7706 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 7707 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7708 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7709 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7710 | |
| 7711 | final long identity = Binder.clearCallingIdentity(); |
| 7712 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7713 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7714 | } finally { |
| 7715 | Binder.restoreCallingIdentity(identity); |
| 7716 | } |
| 7717 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7718 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7719 | @TelephonyManager.IsMultiSimSupportedResult |
| 7720 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7721 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 7722 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 7723 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7724 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 7725 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7726 | } |
| 7727 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 7728 | // supported by the modem, indicate that it is restricted. |
| 7729 | PhoneCapability staticCapability = |
| 7730 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 7731 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7732 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 7733 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7734 | } |
| 7735 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7736 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 7737 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7738 | } |
| 7739 | // Check if support of multiple SIMs is restricted by carrier |
| 7740 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7741 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7742 | } |
| 7743 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7744 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7745 | } |
| 7746 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7747 | /** |
| 7748 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7749 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 7750 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 7751 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7752 | * @param numOfSims number of active sims we want to switch to |
| 7753 | */ |
| 7754 | @Override |
| 7755 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7756 | if (numOfSims == 1) { |
| 7757 | enforceModifyPermission(); |
| 7758 | } else { |
| 7759 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7760 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 7761 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7762 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7763 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7764 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7765 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7766 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7767 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 7768 | return; |
| 7769 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7770 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 7771 | } finally { |
| 7772 | Binder.restoreCallingIdentity(identity); |
| 7773 | } |
| 7774 | } |
| 7775 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 7776 | @Override |
| 7777 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 7778 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 7779 | Phone phone = getPhone(subId); |
| 7780 | if (phone == null) { |
| 7781 | return false; |
| 7782 | } |
| 7783 | final long identity = Binder.clearCallingIdentity(); |
| 7784 | try { |
| 7785 | UiccCard uiccCard = phone.getUiccCard(); |
| 7786 | if (uiccCard == null) { |
| 7787 | return false; |
| 7788 | } |
| 7789 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7790 | if (uiccProfile == null) { |
| 7791 | return false; |
| 7792 | } |
| 7793 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 7794 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 7795 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 7796 | } |
| 7797 | return false; |
| 7798 | } finally { |
| 7799 | Binder.restoreCallingIdentity(identity); |
| 7800 | } |
| 7801 | } |
| 7802 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7803 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7804 | * Get whether making changes to modem configurations will trigger reboot. |
| 7805 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 7806 | */ |
| 7807 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7808 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 7809 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7810 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7811 | mApp, subId, callingPackage, callingFeatureId, |
| 7812 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7813 | return false; |
| 7814 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 7815 | final long identity = Binder.clearCallingIdentity(); |
| 7816 | try { |
| 7817 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 7818 | } finally { |
| 7819 | Binder.restoreCallingIdentity(identity); |
| 7820 | } |
| 7821 | } |
| 7822 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 7823 | private void updateModemStateMetrics() { |
| 7824 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 7825 | // TODO: check the state for each modem if the api is ready. |
| 7826 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 7827 | } |
| 7828 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 7829 | @Override |
| 7830 | public int[] getSlotsMapping() { |
| 7831 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 7832 | |
| 7833 | final long identity = Binder.clearCallingIdentity(); |
| 7834 | try { |
| 7835 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 7836 | // All logical slots should have a mapping to a physical slot. |
| 7837 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 7838 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 7839 | for (int i = 0; i < slotInfos.length; i++) { |
| 7840 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 7841 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 7842 | } |
| 7843 | } |
| 7844 | return logicalSlotsMapping; |
| 7845 | } finally { |
| 7846 | Binder.restoreCallingIdentity(identity); |
| 7847 | } |
| 7848 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 7849 | |
| 7850 | /** |
| 7851 | * Get the IRadio HAL Version |
| 7852 | */ |
| 7853 | @Override |
| 7854 | public int getRadioHalVersion() { |
| 7855 | Phone phone = getDefaultPhone(); |
| 7856 | if (phone == null) return -1; |
| 7857 | HalVersion hv = phone.getHalVersion(); |
| 7858 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 7859 | return hv.major * 100 + hv.minor; |
| 7860 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7861 | |
| 7862 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 7863 | * Get the current calling package name. |
| 7864 | * @return the current calling package name |
| 7865 | */ |
| 7866 | @Override |
| 7867 | public String getCurrentPackageName() { |
| 7868 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 7869 | } |
| 7870 | |
| 7871 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7872 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 7873 | * corresponding network requests on a subId. |
| 7874 | * |
| 7875 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7876 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7877 | * 2) APN is un-metered for this subscription, or |
| 7878 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 7879 | * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7880 | * |
| 7881 | * @return whether data is allowed for a apn type. |
| 7882 | * |
| 7883 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7884 | */ |
| 7885 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7886 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 7887 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 7888 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7889 | |
| 7890 | // Now that all security checks passes, perform the operation as ourselves. |
| 7891 | final long identity = Binder.clearCallingIdentity(); |
| 7892 | try { |
| 7893 | Phone phone = getPhone(subId); |
| 7894 | if (phone == null) return false; |
| 7895 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7896 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7897 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 7898 | } finally { |
| 7899 | Binder.restoreCallingIdentity(identity); |
| 7900 | } |
| 7901 | } |
| 7902 | |
| 7903 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7904 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7905 | enforceReadPrivilegedPermission("isApnMetered"); |
| 7906 | |
| 7907 | // Now that all security checks passes, perform the operation as ourselves. |
| 7908 | final long identity = Binder.clearCallingIdentity(); |
| 7909 | try { |
| 7910 | Phone phone = getPhone(subId); |
| 7911 | if (phone == null) return true; // By default return true. |
| 7912 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7913 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7914 | } finally { |
| 7915 | Binder.restoreCallingIdentity(identity); |
| 7916 | } |
| 7917 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 7918 | |
| 7919 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 7920 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
| 7921 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 7922 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 7923 | if (iccRecords == null) { |
| 7924 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 7925 | return false; |
| 7926 | } |
| 7927 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 7928 | } |
| 7929 | |
| 7930 | @Override |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 7931 | public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 7932 | if (callingPackage == null) { |
| 7933 | callingPackage = getCurrentPackageName(); |
| 7934 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 7935 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 7936 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
| 7937 | if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) { |
| 7938 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 7939 | } |
| 7940 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 7941 | Intent intent = new Intent(); |
| 7942 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 7943 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 7944 | // Bring up choose default SMS subscription dialog right now |
| 7945 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 7946 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 7947 | mApp.startActivity(intent); |
| 7948 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 7949 | |
| 7950 | @Override |
| 7951 | public String getMmsUAProfUrl(int subId) { |
| 7952 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 7953 | final long identity = Binder.clearCallingIdentity(); |
| 7954 | try { |
| 7955 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 7956 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 7957 | } finally { |
| 7958 | Binder.restoreCallingIdentity(identity); |
| 7959 | } |
| 7960 | } |
| 7961 | |
| 7962 | @Override |
| 7963 | public String getMmsUserAgent(int subId) { |
| 7964 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 7965 | final long identity = Binder.clearCallingIdentity(); |
| 7966 | try { |
| 7967 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 7968 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 7969 | } finally { |
| 7970 | Binder.restoreCallingIdentity(identity); |
| 7971 | } |
| 7972 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 7973 | |
| 7974 | @Override |
| 7975 | public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) { |
| 7976 | enforceModifyPermission(); |
| 7977 | |
| 7978 | // Now that all security checks passes, perform the operation as ourselves. |
| 7979 | final long identity = Binder.clearCallingIdentity(); |
| 7980 | try { |
| 7981 | Phone phone = getPhone(subId); |
| 7982 | if (phone == null) return false; |
| 7983 | |
| 7984 | return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow); |
| 7985 | } finally { |
| 7986 | Binder.restoreCallingIdentity(identity); |
| 7987 | } |
| 7988 | } |
| 7989 | |
| 7990 | @Override |
| 7991 | public boolean isDataAllowedInVoiceCall(int subId) { |
| 7992 | enforceReadPrivilegedPermission("isDataAllowedInVoiceCall"); |
| 7993 | |
| 7994 | // Now that all security checks passes, perform the operation as ourselves. |
| 7995 | final long identity = Binder.clearCallingIdentity(); |
| 7996 | try { |
| 7997 | Phone phone = getPhone(subId); |
| 7998 | if (phone == null) return false; |
| 7999 | |
| 8000 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 8001 | } finally { |
| 8002 | Binder.restoreCallingIdentity(identity); |
| 8003 | } |
| 8004 | } |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8005 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8006 | @Override |
| 8007 | public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) { |
| 8008 | enforceModifyPermission(); |
| 8009 | |
| 8010 | // Now that all security checks passes, perform the operation as ourselves. |
| 8011 | final long identity = Binder.clearCallingIdentity(); |
| 8012 | try { |
| 8013 | Phone phone = getPhone(subId); |
| 8014 | if (phone == null) return false; |
| 8015 | |
| 8016 | return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow); |
| 8017 | } finally { |
| 8018 | Binder.restoreCallingIdentity(identity); |
| 8019 | } |
| 8020 | } |
| 8021 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8022 | /** |
| 8023 | * Updates whether conference event pacakge handling is enabled. |
| 8024 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 8025 | * otherwise. |
| 8026 | */ |
| 8027 | @Override |
| 8028 | public void setCepEnabled(boolean isCepEnabled) { |
| 8029 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 8030 | |
| 8031 | final long identity = Binder.clearCallingIdentity(); |
| 8032 | try { |
| 8033 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 8034 | for (Phone phone : PhoneFactory.getPhones()) { |
| 8035 | Phone defaultPhone = phone.getImsPhone(); |
| 8036 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 8037 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 8038 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 8039 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 8040 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 8041 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 8042 | + imsPhone.getMsisdn()); |
| 8043 | } |
| 8044 | } |
| 8045 | } finally { |
| 8046 | Binder.restoreCallingIdentity(identity); |
| 8047 | } |
| 8048 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 8049 | |
| 8050 | /** |
| 8051 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 8052 | * |
| 8053 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 8054 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 8055 | * before being read. |
| 8056 | */ |
| 8057 | @Override |
| 8058 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 8059 | isCompressed) { |
| 8060 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8061 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
| 8062 | try { |
| 8063 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 8064 | if (configBinder == null) { |
| 8065 | Rlog.e(LOG_TAG, "null result for getImsConfig"); |
| 8066 | } else { |
| 8067 | configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed); |
| 8068 | } |
| 8069 | } catch (RemoteException e) { |
| 8070 | Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage()); |
| 8071 | } |
| 8072 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8073 | |
| 8074 | @Override |
| 8075 | public boolean isIccLockEnabled(int subId) { |
| 8076 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 8077 | |
| 8078 | // Now that all security checks passes, perform the operation as ourselves. |
| 8079 | final long identity = Binder.clearCallingIdentity(); |
| 8080 | try { |
| 8081 | Phone phone = getPhone(subId); |
| 8082 | if (phone != null && phone.getIccCard() != null) { |
| 8083 | return phone.getIccCard().getIccLockEnabled(); |
| 8084 | } else { |
| 8085 | return false; |
| 8086 | } |
| 8087 | } finally { |
| 8088 | Binder.restoreCallingIdentity(identity); |
| 8089 | } |
| 8090 | } |
| 8091 | |
| 8092 | /** |
| 8093 | * Set the ICC pin lock enabled or disabled. |
| 8094 | * |
| 8095 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 8096 | * three cases: |
| 8097 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 8098 | * successfully. |
| 8099 | * - Positive number and zero for remaining password attempts. |
| 8100 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 8101 | * |
| 8102 | */ |
| 8103 | @Override |
| 8104 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 8105 | enforceModifyPermission(); |
| 8106 | |
| 8107 | Phone phone = getPhone(subId); |
| 8108 | if (phone == null) { |
| 8109 | return 0; |
| 8110 | } |
| 8111 | // Now that all security checks passes, perform the operation as ourselves. |
| 8112 | final long identity = Binder.clearCallingIdentity(); |
| 8113 | try { |
| 8114 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 8115 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 8116 | return attemptsRemaining; |
| 8117 | |
| 8118 | } catch (Exception e) { |
| 8119 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 8120 | } finally { |
| 8121 | Binder.restoreCallingIdentity(identity); |
| 8122 | } |
| 8123 | return 0; |
| 8124 | } |
| 8125 | |
| 8126 | /** |
| 8127 | * Change the ICC password used in ICC pin lock. |
| 8128 | * |
| 8129 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 8130 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 8131 | * - Positive number and zero for remaining password attempts. |
| 8132 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 8133 | * |
| 8134 | */ |
| 8135 | @Override |
| 8136 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 8137 | enforceModifyPermission(); |
| 8138 | |
| 8139 | Phone phone = getPhone(subId); |
| 8140 | if (phone == null) { |
| 8141 | return 0; |
| 8142 | } |
| 8143 | // Now that all security checks passes, perform the operation as ourselves. |
| 8144 | final long identity = Binder.clearCallingIdentity(); |
| 8145 | try { |
| 8146 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 8147 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 8148 | return attemptsRemaining; |
| 8149 | |
| 8150 | } catch (Exception e) { |
| 8151 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 8152 | } finally { |
| 8153 | Binder.restoreCallingIdentity(identity); |
| 8154 | } |
| 8155 | return 0; |
| 8156 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 8157 | } |