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; |
Meng Wang | ebdba86 | 2020-01-08 18:00:39 -0800 | [diff] [blame] | 86 | import com.android.telephony.Rlog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 87 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 88 | import android.telephony.SignalStrength; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 89 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 90 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 91 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 92 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 93 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 94 | import android.telephony.TelephonyScanManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 95 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 96 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 97 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 98 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 99 | import android.telephony.data.ApnSetting; |
| 100 | import android.telephony.emergency.EmergencyNumber; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 101 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 102 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 103 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 104 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 105 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 106 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 107 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 108 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 109 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 110 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 111 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 112 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 113 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 114 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 115 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 116 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 117 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 118 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 119 | import android.util.Pair; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 120 | import android.util.Slog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 121 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 122 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 123 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 124 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 127 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.CommandException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 130 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 131 | import com.android.internal.telephony.HalVersion; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 132 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 133 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 134 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 135 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 141 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 150 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 151 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 153 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 155 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 157 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 158 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 161 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 163 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 165 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 166 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 167 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 168 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 169 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 171 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 172 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 173 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 174 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 175 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 176 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
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; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 270 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 271 | // Parameters of select command. |
| 272 | private static final int SELECT_COMMAND = 0xA4; |
| 273 | private static final int SELECT_P1 = 0x04; |
| 274 | private static final int SELECT_P2 = 0; |
| 275 | private static final int SELECT_P3 = 0x10; |
| 276 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 277 | /** The singleton instance. */ |
| 278 | private static PhoneInterfaceManager sInstance; |
| 279 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 280 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 281 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 282 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 283 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 284 | private AppOpsManager mAppOps; |
| 285 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 286 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 287 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 288 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 289 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 290 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 291 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 292 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 293 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 294 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 295 | // String to store multi SIM allowed |
| 296 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 297 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 298 | // The AID of ISD-R. |
| 299 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 300 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 301 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 302 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 303 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 304 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 305 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 306 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 307 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 308 | */ |
| 309 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 310 | "reset_network_erase_modem_config_enabled"; |
| 311 | |
| 312 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 313 | * A request object to use for transmitting data to an ICC. |
| 314 | */ |
| 315 | private static final class IccAPDUArgument { |
| 316 | public int channel, cla, command, p1, p2, p3; |
| 317 | public String data; |
| 318 | |
| 319 | public IccAPDUArgument(int channel, int cla, int command, |
| 320 | int p1, int p2, int p3, String data) { |
| 321 | this.channel = channel; |
| 322 | this.cla = cla; |
| 323 | this.command = command; |
| 324 | this.p1 = p1; |
| 325 | this.p2 = p2; |
| 326 | this.p3 = p3; |
| 327 | this.data = data; |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 332 | * A request object to use for transmitting data to an ICC. |
| 333 | */ |
| 334 | private static final class ManualNetworkSelectionArgument { |
| 335 | public OperatorInfo operatorInfo; |
| 336 | public boolean persistSelection; |
| 337 | |
| 338 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 339 | this.operatorInfo = operatorInfo; |
| 340 | this.persistSelection = persistSelection; |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 345 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 346 | * request after sending. The main thread will notify the request when it is complete. |
| 347 | */ |
| 348 | private static final class MainThreadRequest { |
| 349 | /** The argument to use for the request */ |
| 350 | public Object argument; |
| 351 | /** The result of the request that is run on the main thread */ |
| 352 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 353 | // The subscriber id that this request applies to. Defaults to |
| 354 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 355 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 356 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 357 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 358 | public Phone phone; |
| 359 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 360 | public WorkSource workSource; |
| 361 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 362 | public MainThreadRequest(Object argument) { |
| 363 | this.argument = argument; |
| 364 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 365 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 366 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 367 | this.argument = argument; |
| 368 | if (phone != null) { |
| 369 | this.phone = phone; |
| 370 | } |
| 371 | this.workSource = workSource; |
| 372 | } |
| 373 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 374 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 375 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 376 | if (subId != null) { |
| 377 | this.subId = subId; |
| 378 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 379 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 380 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 381 | } |
| 382 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 383 | private static final class IncomingThirdPartyCallArgs { |
| 384 | public final ComponentName component; |
| 385 | public final String callId; |
| 386 | public final String callerDisplayName; |
| 387 | |
| 388 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 389 | String callerDisplayName) { |
| 390 | this.component = component; |
| 391 | this.callId = callId; |
| 392 | this.callerDisplayName = callerDisplayName; |
| 393 | } |
| 394 | } |
| 395 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 396 | /** |
| 397 | * A handler that processes messages on the main thread in the phone process. Since many |
| 398 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 399 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 400 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 401 | * on, which will be notified when the operation completes and will contain the result of the |
| 402 | * request. |
| 403 | * |
| 404 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 405 | * note that request.result must be set to something non-null for the calling thread to |
| 406 | * unblock. |
| 407 | */ |
| 408 | private final class MainThreadHandler extends Handler { |
| 409 | @Override |
| 410 | public void handleMessage(Message msg) { |
| 411 | MainThreadRequest request; |
| 412 | Message onCompleted; |
| 413 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 414 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 415 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 416 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 417 | |
| 418 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 419 | case CMD_HANDLE_USSD_REQUEST: { |
| 420 | request = (MainThreadRequest) msg.obj; |
| 421 | final Phone phone = getPhoneFromRequest(request); |
| 422 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 423 | String ussdRequest = ussdObject.first; |
| 424 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 425 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 426 | if (!isUssdApiAllowed(request.subId)) { |
| 427 | // Carrier does not support use of this API, return failure. |
| 428 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 429 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 430 | Bundle returnData = new Bundle(); |
| 431 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 432 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 433 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 434 | request.result = true; |
| 435 | notifyRequester(request); |
| 436 | return; |
| 437 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 438 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 439 | try { |
| 440 | request.result = phone != null |
| 441 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 442 | } catch (CallStateException cse) { |
| 443 | request.result = false; |
| 444 | } |
| 445 | // Wake up the requesting thread |
| 446 | notifyRequester(request); |
| 447 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 448 | } |
| 449 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 450 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 451 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 452 | final Phone phone = getPhoneFromRequest(request); |
| 453 | request.result = phone != null ? |
| 454 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 455 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 456 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 457 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 458 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 459 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 460 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 461 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 462 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 463 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 464 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 465 | if (uiccCard == null) { |
| 466 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 467 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 468 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 469 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 470 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 471 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 472 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 473 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 474 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 475 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 476 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 477 | break; |
| 478 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 479 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 480 | ar = (AsyncResult) msg.obj; |
| 481 | request = (MainThreadRequest) ar.userObj; |
| 482 | if (ar.exception == null && ar.result != null) { |
| 483 | request.result = ar.result; |
| 484 | } else { |
| 485 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 486 | if (ar.result == null) { |
| 487 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 488 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 489 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 490 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 491 | } else { |
| 492 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 493 | } |
| 494 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 495 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 496 | break; |
| 497 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 498 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 499 | request = (MainThreadRequest) msg.obj; |
| 500 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 501 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 502 | if (uiccCard == null) { |
| 503 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 504 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 505 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 506 | } else { |
| 507 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 508 | request); |
| 509 | uiccCard.iccTransmitApduBasicChannel( |
| 510 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 511 | iccArgument.p3, iccArgument.data, onCompleted); |
| 512 | } |
| 513 | break; |
| 514 | |
| 515 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 516 | ar = (AsyncResult) msg.obj; |
| 517 | request = (MainThreadRequest) ar.userObj; |
| 518 | if (ar.exception == null && ar.result != null) { |
| 519 | request.result = ar.result; |
| 520 | } else { |
| 521 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 522 | if (ar.result == null) { |
| 523 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 524 | } else if (ar.exception instanceof CommandException) { |
| 525 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 526 | ar.exception); |
| 527 | } else { |
| 528 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 529 | } |
| 530 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 531 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 532 | break; |
| 533 | |
| 534 | case CMD_EXCHANGE_SIM_IO: |
| 535 | request = (MainThreadRequest) msg.obj; |
| 536 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 537 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 538 | if (uiccCard == null) { |
| 539 | loge("iccExchangeSimIO: No UICC"); |
| 540 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 541 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 542 | } else { |
| 543 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 544 | request); |
| 545 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 546 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 547 | iccArgument.data, onCompleted); |
| 548 | } |
| 549 | break; |
| 550 | |
| 551 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 552 | ar = (AsyncResult) msg.obj; |
| 553 | request = (MainThreadRequest) ar.userObj; |
| 554 | if (ar.exception == null && ar.result != null) { |
| 555 | request.result = ar.result; |
| 556 | } else { |
| 557 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 558 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 559 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 560 | break; |
| 561 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 562 | case CMD_SEND_ENVELOPE: |
| 563 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 564 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 565 | if (uiccCard == null) { |
| 566 | loge("sendEnvelopeWithStatus: No UICC"); |
| 567 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 568 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 569 | } else { |
| 570 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 571 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 572 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 573 | break; |
| 574 | |
| 575 | case EVENT_SEND_ENVELOPE_DONE: |
| 576 | ar = (AsyncResult) msg.obj; |
| 577 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 578 | if (ar.exception == null && ar.result != null) { |
| 579 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 580 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 581 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 582 | if (ar.result == null) { |
| 583 | loge("sendEnvelopeWithStatus: Empty response"); |
| 584 | } else if (ar.exception instanceof CommandException) { |
| 585 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 586 | ar.exception); |
| 587 | } else { |
| 588 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 589 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 590 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 591 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 592 | break; |
| 593 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 594 | case CMD_OPEN_CHANNEL: |
| 595 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 596 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 597 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 598 | if (uiccCard == null) { |
| 599 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 600 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 601 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 602 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 603 | } else { |
| 604 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 605 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 606 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 607 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 608 | break; |
| 609 | |
| 610 | case EVENT_OPEN_CHANNEL_DONE: |
| 611 | ar = (AsyncResult) msg.obj; |
| 612 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 613 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 614 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 615 | int[] result = (int[]) ar.result; |
| 616 | int channelId = result[0]; |
| 617 | byte[] selectResponse = null; |
| 618 | if (result.length > 1) { |
| 619 | selectResponse = new byte[result.length - 1]; |
| 620 | for (int i = 1; i < result.length; ++i) { |
| 621 | selectResponse[i - 1] = (byte) result[i]; |
| 622 | } |
| 623 | } |
| 624 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 625 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 626 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 627 | if (ar.result == null) { |
| 628 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 629 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 630 | if (ar.exception != null) { |
| 631 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 632 | } |
| 633 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 634 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 635 | if (ar.exception instanceof CommandException) { |
| 636 | CommandException.Error error = |
| 637 | ((CommandException) (ar.exception)).getCommandError(); |
| 638 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 639 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 640 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 641 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 642 | } |
| 643 | } |
| 644 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 645 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 646 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 647 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 648 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 649 | break; |
| 650 | |
| 651 | case CMD_CLOSE_CHANNEL: |
| 652 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 653 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 654 | if (uiccCard == null) { |
| 655 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 656 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 657 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 658 | } else { |
| 659 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 660 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 661 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 662 | break; |
| 663 | |
| 664 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 665 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 666 | break; |
| 667 | |
| 668 | case CMD_NV_READ_ITEM: |
| 669 | request = (MainThreadRequest) msg.obj; |
| 670 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 671 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 672 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 673 | break; |
| 674 | |
| 675 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 676 | ar = (AsyncResult) msg.obj; |
| 677 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 678 | if (ar.exception == null && ar.result != null) { |
| 679 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 680 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 681 | request.result = ""; |
| 682 | if (ar.result == null) { |
| 683 | loge("nvReadItem: Empty response"); |
| 684 | } else if (ar.exception instanceof CommandException) { |
| 685 | loge("nvReadItem: CommandException: " + |
| 686 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 687 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 688 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 689 | } |
| 690 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 691 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 692 | break; |
| 693 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 694 | case CMD_NV_WRITE_ITEM: |
| 695 | request = (MainThreadRequest) msg.obj; |
| 696 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 697 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 698 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 699 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 700 | break; |
| 701 | |
| 702 | case EVENT_NV_WRITE_ITEM_DONE: |
| 703 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 704 | break; |
| 705 | |
| 706 | case CMD_NV_WRITE_CDMA_PRL: |
| 707 | request = (MainThreadRequest) msg.obj; |
| 708 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 709 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 710 | break; |
| 711 | |
| 712 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 713 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 714 | break; |
| 715 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 716 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 717 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 718 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 719 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 720 | break; |
| 721 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 722 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 723 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 724 | break; |
| 725 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 726 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 727 | request = (MainThreadRequest) msg.obj; |
| 728 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 729 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 730 | break; |
| 731 | |
| 732 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 733 | ar = (AsyncResult) msg.obj; |
| 734 | request = (MainThreadRequest) ar.userObj; |
| 735 | if (ar.exception == null && ar.result != null) { |
| 736 | request.result = ar.result; // Integer |
| 737 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 738 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 739 | if (ar.result == null) { |
| 740 | loge("getPreferredNetworkType: Empty response"); |
| 741 | } else if (ar.exception instanceof CommandException) { |
| 742 | loge("getPreferredNetworkType: CommandException: " + |
| 743 | ar.exception); |
| 744 | } else { |
| 745 | loge("getPreferredNetworkType: Unknown exception"); |
| 746 | } |
| 747 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 748 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 749 | break; |
| 750 | |
| 751 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 752 | request = (MainThreadRequest) msg.obj; |
| 753 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 754 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 755 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 756 | break; |
| 757 | |
| 758 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 759 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 760 | break; |
| 761 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 762 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 763 | request = (MainThreadRequest)msg.obj; |
| 764 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 765 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 766 | break; |
| 767 | |
| 768 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 769 | ar = (AsyncResult)msg.obj; |
| 770 | request = (MainThreadRequest)ar.userObj; |
| 771 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 772 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 773 | break; |
| 774 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 775 | case CMD_SET_VOICEMAIL_NUMBER: |
| 776 | request = (MainThreadRequest) msg.obj; |
| 777 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 778 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 779 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 780 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 781 | break; |
| 782 | |
| 783 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 784 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 785 | break; |
| 786 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 787 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 788 | request = (MainThreadRequest) msg.obj; |
| 789 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 790 | request); |
| 791 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 792 | break; |
| 793 | |
| 794 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 795 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 796 | break; |
| 797 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 798 | case CMD_PERFORM_NETWORK_SCAN: |
| 799 | request = (MainThreadRequest) msg.obj; |
| 800 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 801 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 802 | break; |
| 803 | |
| 804 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 805 | ar = (AsyncResult) msg.obj; |
| 806 | request = (MainThreadRequest) ar.userObj; |
| 807 | CellNetworkScanResult cellScanResult; |
| 808 | if (ar.exception == null && ar.result != null) { |
| 809 | cellScanResult = new CellNetworkScanResult( |
| 810 | CellNetworkScanResult.STATUS_SUCCESS, |
| 811 | (List<OperatorInfo>) ar.result); |
| 812 | } else { |
| 813 | if (ar.result == null) { |
| 814 | loge("getCellNetworkScanResults: Empty response"); |
| 815 | } |
| 816 | if (ar.exception != null) { |
| 817 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 818 | } |
| 819 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 820 | if (ar.exception instanceof CommandException) { |
| 821 | CommandException.Error error = |
| 822 | ((CommandException) (ar.exception)).getCommandError(); |
| 823 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 824 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 825 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 826 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 827 | } |
| 828 | } |
| 829 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 830 | } |
| 831 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 832 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 833 | break; |
| 834 | |
| 835 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 836 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 837 | ManualNetworkSelectionArgument selArg = |
| 838 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 839 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 840 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 841 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 842 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 843 | break; |
| 844 | |
| 845 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 846 | ar = (AsyncResult) msg.obj; |
| 847 | request = (MainThreadRequest) ar.userObj; |
| 848 | if (ar.exception == null) { |
| 849 | request.result = true; |
| 850 | } else { |
| 851 | request.result = false; |
| 852 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 853 | } |
| 854 | notifyRequester(request); |
| 855 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 856 | break; |
| 857 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 858 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 859 | request = (MainThreadRequest) msg.obj; |
| 860 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 861 | if (defaultPhone != null) { |
| 862 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
| 863 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 864 | break; |
| 865 | |
| 866 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 867 | ar = (AsyncResult) msg.obj; |
| 868 | request = (MainThreadRequest) ar.userObj; |
| 869 | if (ar.exception == null && ar.result != null) { |
| 870 | request.result = ar.result; |
| 871 | } else { |
| 872 | if (ar.result == null) { |
| 873 | loge("queryModemActivityInfo: Empty response"); |
| 874 | } else if (ar.exception instanceof CommandException) { |
| 875 | loge("queryModemActivityInfo: CommandException: " + |
| 876 | ar.exception); |
| 877 | } else { |
| 878 | loge("queryModemActivityInfo: Unknown exception"); |
| 879 | } |
| 880 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 881 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 882 | if (request.result == null) { |
Peter Collingbourne | c00e902 | 2019-11-26 09:56:26 -0800 | [diff] [blame] | 883 | request.result = new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 884 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 885 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 886 | break; |
| 887 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 888 | case CMD_SET_ALLOWED_CARRIERS: |
| 889 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 890 | CarrierRestrictionRules argument = |
| 891 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 892 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 893 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 894 | break; |
| 895 | |
| 896 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 897 | ar = (AsyncResult) msg.obj; |
| 898 | request = (MainThreadRequest) ar.userObj; |
| 899 | if (ar.exception == null && ar.result != null) { |
| 900 | request.result = ar.result; |
| 901 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 902 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 903 | if (ar.exception instanceof CommandException) { |
| 904 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 905 | CommandException.Error error = |
| 906 | ((CommandException) (ar.exception)).getCommandError(); |
| 907 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 908 | request.result = |
| 909 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 910 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 911 | } else { |
| 912 | loge("setAllowedCarriers: Unknown exception"); |
| 913 | } |
| 914 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 915 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 916 | break; |
| 917 | |
| 918 | case CMD_GET_ALLOWED_CARRIERS: |
| 919 | request = (MainThreadRequest) msg.obj; |
| 920 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 921 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 922 | break; |
| 923 | |
| 924 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 925 | ar = (AsyncResult) msg.obj; |
| 926 | request = (MainThreadRequest) ar.userObj; |
| 927 | if (ar.exception == null && ar.result != null) { |
| 928 | request.result = ar.result; |
| 929 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 930 | request.result = new IllegalStateException( |
| 931 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 932 | if (ar.result == null) { |
| 933 | loge("getAllowedCarriers: Empty response"); |
| 934 | } else if (ar.exception instanceof CommandException) { |
| 935 | loge("getAllowedCarriers: CommandException: " + |
| 936 | ar.exception); |
| 937 | } else { |
| 938 | loge("getAllowedCarriers: Unknown exception"); |
| 939 | } |
| 940 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 941 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 942 | break; |
| 943 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 944 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 945 | ar = (AsyncResult) msg.obj; |
| 946 | request = (MainThreadRequest) ar.userObj; |
| 947 | if (ar.exception == null && ar.result != null) { |
| 948 | request.result = ar.result; |
| 949 | } else { |
| 950 | request.result = new IllegalArgumentException( |
| 951 | "Failed to retrieve Forbidden Plmns"); |
| 952 | if (ar.result == null) { |
| 953 | loge("getForbiddenPlmns: Empty response"); |
| 954 | } else { |
| 955 | loge("getForbiddenPlmns: Unknown exception"); |
| 956 | } |
| 957 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 958 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 959 | break; |
| 960 | |
| 961 | case CMD_GET_FORBIDDEN_PLMNS: |
| 962 | request = (MainThreadRequest) msg.obj; |
| 963 | uiccCard = getUiccCardFromRequest(request); |
| 964 | if (uiccCard == null) { |
| 965 | loge("getForbiddenPlmns() UiccCard is null"); |
| 966 | request.result = new IllegalArgumentException( |
| 967 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 968 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 969 | break; |
| 970 | } |
| 971 | Integer appType = (Integer) request.argument; |
| 972 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 973 | if (uiccApp == null) { |
| 974 | loge("getForbiddenPlmns() no app with specified type -- " |
| 975 | + appType); |
| 976 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 977 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 978 | break; |
| 979 | } else { |
| 980 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 981 | + " specified type -- " + appType); |
| 982 | } |
| 983 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 984 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 985 | onCompleted); |
| 986 | break; |
| 987 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 988 | case CMD_SWITCH_SLOTS: |
| 989 | request = (MainThreadRequest) msg.obj; |
| 990 | int[] physicalSlots = (int[]) request.argument; |
| 991 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 992 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 993 | break; |
| 994 | |
| 995 | case EVENT_SWITCH_SLOTS_DONE: |
| 996 | ar = (AsyncResult) msg.obj; |
| 997 | request = (MainThreadRequest) ar.userObj; |
| 998 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 999 | notifyRequester(request); |
| 1000 | break; |
| 1001 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1002 | request = (MainThreadRequest) msg.obj; |
| 1003 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1004 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1005 | break; |
| 1006 | |
| 1007 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1008 | ar = (AsyncResult) msg.obj; |
| 1009 | request = (MainThreadRequest) ar.userObj; |
| 1010 | if (ar.exception != null) { |
| 1011 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1012 | } else { |
| 1013 | int mode = ((int[]) ar.result)[0]; |
| 1014 | if (mode == 0) { |
| 1015 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1016 | } else { |
| 1017 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1018 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1019 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1020 | notifyRequester(request); |
| 1021 | break; |
| 1022 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1023 | request = (MainThreadRequest) msg.obj; |
| 1024 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1025 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1026 | break; |
| 1027 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1028 | ar = (AsyncResult) msg.obj; |
| 1029 | request = (MainThreadRequest) ar.userObj; |
| 1030 | if (ar.exception != null) { |
| 1031 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1032 | } else { |
| 1033 | request.result = ((int[]) ar.result)[0]; |
| 1034 | } |
| 1035 | notifyRequester(request); |
| 1036 | break; |
| 1037 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1038 | request = (MainThreadRequest) msg.obj; |
| 1039 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1040 | int mode = (int) request.argument; |
| 1041 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1042 | break; |
| 1043 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1044 | ar = (AsyncResult) msg.obj; |
| 1045 | request = (MainThreadRequest) ar.userObj; |
| 1046 | request.result = ar.exception == null; |
| 1047 | notifyRequester(request); |
| 1048 | break; |
| 1049 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1050 | request = (MainThreadRequest) msg.obj; |
| 1051 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1052 | int subscriptionMode = (int) request.argument; |
| 1053 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1054 | break; |
| 1055 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1056 | ar = (AsyncResult) msg.obj; |
| 1057 | request = (MainThreadRequest) ar.userObj; |
| 1058 | request.result = ar.exception == null; |
| 1059 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1060 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1061 | case CMD_GET_ALL_CELL_INFO: |
| 1062 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1063 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1064 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1065 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1066 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1067 | ar = (AsyncResult) msg.obj; |
| 1068 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1069 | // If a timeout occurs, the response will be null |
| 1070 | request.result = (ar.exception == null && ar.result != null) |
| 1071 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1072 | synchronized (request) { |
| 1073 | request.notifyAll(); |
| 1074 | } |
| 1075 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1076 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1077 | request = (MainThreadRequest) msg.obj; |
| 1078 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1079 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1080 | break; |
| 1081 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1082 | ar = (AsyncResult) msg.obj; |
| 1083 | request = (MainThreadRequest) ar.userObj; |
| 1084 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1085 | try { |
| 1086 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1087 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1088 | cb.onError( |
| 1089 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1090 | ar.exception.getClass().getName(), |
| 1091 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1092 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1093 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1094 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1095 | } else { |
| 1096 | // use the result as returned |
| 1097 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1098 | } |
| 1099 | } catch (RemoteException re) { |
| 1100 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1101 | } |
| 1102 | break; |
| 1103 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1104 | request = (MainThreadRequest) msg.obj; |
| 1105 | WorkSource ws = (WorkSource) request.argument; |
| 1106 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1107 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1108 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1109 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1110 | ar = (AsyncResult) msg.obj; |
| 1111 | request = (MainThreadRequest) ar.userObj; |
| 1112 | if (ar.exception == null) { |
| 1113 | request.result = ar.result; |
| 1114 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1115 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1116 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1117 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | synchronized (request) { |
| 1121 | request.notifyAll(); |
| 1122 | } |
| 1123 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1124 | case CMD_MODEM_REBOOT: |
| 1125 | request = (MainThreadRequest) msg.obj; |
| 1126 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1127 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1128 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1129 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1130 | handleNullReturnEvent(msg, "rebootModem"); |
| 1131 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1132 | case CMD_REQUEST_ENABLE_MODEM: |
| 1133 | request = (MainThreadRequest) msg.obj; |
| 1134 | boolean enable = (boolean) request.argument; |
| 1135 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1136 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1137 | PhoneConfigurationManager.getInstance() |
| 1138 | .enablePhone(request.phone, enable, onCompleted); |
| 1139 | break; |
| 1140 | case EVENT_ENABLE_MODEM_DONE: |
| 1141 | ar = (AsyncResult) msg.obj; |
| 1142 | request = (MainThreadRequest) ar.userObj; |
| 1143 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1144 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1145 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1146 | if ((boolean) request.result) { |
| 1147 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1148 | updateModemStateMetrics(); |
| 1149 | } else { |
| 1150 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1151 | + ar.exception); |
| 1152 | } |
| 1153 | notifyRequester(request); |
| 1154 | break; |
| 1155 | case CMD_GET_MODEM_STATUS: |
| 1156 | request = (MainThreadRequest) msg.obj; |
| 1157 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1158 | PhoneConfigurationManager.getInstance() |
| 1159 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1160 | break; |
| 1161 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1162 | ar = (AsyncResult) msg.obj; |
| 1163 | request = (MainThreadRequest) ar.userObj; |
| 1164 | int id = request.phone.getPhoneId(); |
| 1165 | if (ar.exception == null && ar.result != null) { |
| 1166 | request.result = ar.result; |
| 1167 | //update the cache as modem status has changed |
| 1168 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1169 | (boolean) request.result); |
| 1170 | } else { |
| 1171 | // Return true if modem status cannot be retrieved. For most cases, |
| 1172 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1173 | // and disable modem are not supported. Modem is always on. |
| 1174 | // TODO: this should be fixed in R to support a third |
| 1175 | // status UNKNOWN b/131631629 |
| 1176 | request.result = true; |
| 1177 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1178 | + ar.exception); |
| 1179 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1180 | notifyRequester(request); |
| 1181 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1182 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1183 | ar = (AsyncResult) msg.obj; |
| 1184 | request = (MainThreadRequest) ar.userObj; |
| 1185 | if (ar.exception == null && ar.result != null) { |
| 1186 | request.result = ar.result; |
| 1187 | } else { |
| 1188 | request.result = -1; |
| 1189 | loge("Failed to set Forbidden Plmns"); |
| 1190 | if (ar.result == null) { |
| 1191 | loge("setForbidenPlmns: Empty response"); |
| 1192 | } else if (ar.exception != null) { |
| 1193 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1194 | request.result = -1; |
| 1195 | } else { |
| 1196 | loge("setForbiddenPlmns: Unknown exception"); |
| 1197 | } |
| 1198 | } |
| 1199 | notifyRequester(request); |
| 1200 | break; |
| 1201 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1202 | request = (MainThreadRequest) msg.obj; |
| 1203 | uiccCard = getUiccCardFromRequest(request); |
| 1204 | if (uiccCard == null) { |
| 1205 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1206 | request.result = -1; |
| 1207 | notifyRequester(request); |
| 1208 | break; |
| 1209 | } |
| 1210 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1211 | (Pair<Integer, List<String>>) request.argument; |
| 1212 | appType = setFplmnsArgs.first; |
| 1213 | List<String> fplmns = setFplmnsArgs.second; |
| 1214 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1215 | if (uiccApp == null) { |
| 1216 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1217 | request.result = -1; |
| 1218 | loge("Failed to get UICC App"); |
| 1219 | notifyRequester(request); |
| 1220 | } else { |
| 1221 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1222 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1223 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1224 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1225 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1226 | case CMD_ERASE_MODEM_CONFIG: |
| 1227 | request = (MainThreadRequest) msg.obj; |
| 1228 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1229 | defaultPhone.eraseModemConfig(onCompleted); |
| 1230 | break; |
| 1231 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1232 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1233 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1234 | default: |
| 1235 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1236 | break; |
| 1237 | } |
| 1238 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1239 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1240 | private void notifyRequester(MainThreadRequest request) { |
| 1241 | synchronized (request) { |
| 1242 | request.notifyAll(); |
| 1243 | } |
| 1244 | } |
| 1245 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1246 | private void handleNullReturnEvent(Message msg, String command) { |
| 1247 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1248 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1249 | if (ar.exception == null) { |
| 1250 | request.result = true; |
| 1251 | } else { |
| 1252 | request.result = false; |
| 1253 | if (ar.exception instanceof CommandException) { |
| 1254 | loge(command + ": CommandException: " + ar.exception); |
| 1255 | } else { |
| 1256 | loge(command + ": Unknown exception"); |
| 1257 | } |
| 1258 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1259 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1260 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | /** |
| 1264 | * Posts the specified command to be executed on the main thread, |
| 1265 | * waits for the request to complete, and returns the result. |
| 1266 | * @see #sendRequestAsync |
| 1267 | */ |
| 1268 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1269 | return sendRequest( |
| 1270 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1271 | } |
| 1272 | |
| 1273 | /** |
| 1274 | * Posts the specified command to be executed on the main thread, |
| 1275 | * waits for the request to complete, and returns the result. |
| 1276 | * @see #sendRequestAsync |
| 1277 | */ |
| 1278 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1279 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1280 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1281 | } |
| 1282 | |
| 1283 | /** |
| 1284 | * Posts the specified command to be executed on the main thread, |
| 1285 | * waits for the request to complete, and returns the result. |
| 1286 | * @see #sendRequestAsync |
| 1287 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1288 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1289 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1290 | } |
| 1291 | |
| 1292 | /** |
| 1293 | * Posts the specified command to be executed on the main thread, |
| 1294 | * waits for the request to complete, and returns the result. |
| 1295 | * @see #sendRequestAsync |
| 1296 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1297 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1298 | return sendRequest(command, argument, subId, null, workSource); |
| 1299 | } |
| 1300 | |
| 1301 | /** |
| 1302 | * Posts the specified command to be executed on the main thread, |
| 1303 | * waits for the request to complete, and returns the result. |
| 1304 | * @see #sendRequestAsync |
| 1305 | */ |
| 1306 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1307 | return sendRequest( |
| 1308 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1309 | } |
| 1310 | |
| 1311 | /** |
| 1312 | * Posts the specified command to be executed on the main thread, |
| 1313 | * waits for the request to complete, and returns the result. |
| 1314 | * @see #sendRequestAsync |
| 1315 | */ |
| 1316 | private Object sendRequest( |
| 1317 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1318 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1319 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1320 | } |
| 1321 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1322 | MainThreadRequest request = null; |
| 1323 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1324 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1325 | } else if (phone != null) { |
| 1326 | request = new MainThreadRequest(argument, phone, workSource); |
| 1327 | } else { |
| 1328 | request = new MainThreadRequest(argument, subId, workSource); |
| 1329 | } |
| 1330 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1331 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1332 | msg.sendToTarget(); |
| 1333 | |
| 1334 | // Wait for the request to complete |
| 1335 | synchronized (request) { |
| 1336 | while (request.result == null) { |
| 1337 | try { |
| 1338 | request.wait(); |
| 1339 | } catch (InterruptedException e) { |
| 1340 | // Do nothing, go back and wait until the request is complete |
| 1341 | } |
| 1342 | } |
| 1343 | } |
| 1344 | return request.result; |
| 1345 | } |
| 1346 | |
| 1347 | /** |
| 1348 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1349 | * Posts the specified command to be executed on the main thread, and |
| 1350 | * returns immediately. |
| 1351 | * @see #sendRequest |
| 1352 | */ |
| 1353 | private void sendRequestAsync(int command) { |
| 1354 | mMainThreadHandler.sendEmptyMessage(command); |
| 1355 | } |
| 1356 | |
| 1357 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1358 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1359 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1360 | */ |
| 1361 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1362 | sendRequestAsync(command, argument, null, null); |
| 1363 | } |
| 1364 | |
| 1365 | /** |
| 1366 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1367 | * @see {@link #sendRequest(int,Object)} |
| 1368 | */ |
| 1369 | private void sendRequestAsync( |
| 1370 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1371 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1372 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1373 | msg.sendToTarget(); |
| 1374 | } |
| 1375 | |
| 1376 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1377 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1378 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1379 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1380 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1381 | synchronized (PhoneInterfaceManager.class) { |
| 1382 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1383 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1384 | } else { |
| 1385 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1386 | } |
| 1387 | return sInstance; |
| 1388 | } |
| 1389 | } |
| 1390 | |
| 1391 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1392 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1393 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1394 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1395 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1396 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1397 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1398 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1399 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1400 | mTelephonySharedPreferences = |
| 1401 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1402 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1403 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1404 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1405 | publish(); |
| 1406 | } |
| 1407 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1408 | private Phone getDefaultPhone() { |
| 1409 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1410 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1411 | } |
| 1412 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1413 | private void publish() { |
| 1414 | if (DBG) log("publish: " + this); |
| 1415 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 1416 | TelephonyFrameworkInitializer |
| 1417 | .getTelephonyServiceManager() |
| 1418 | .getTelephonyServiceRegisterer() |
| 1419 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1420 | } |
| 1421 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1422 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1423 | if (request.phone != null) { |
| 1424 | return request.phone; |
| 1425 | } else { |
| 1426 | return getPhoneFromSubId(request.subId); |
| 1427 | } |
| 1428 | } |
| 1429 | |
| 1430 | private Phone getPhoneFromSubId(int subId) { |
| 1431 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1432 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1433 | } |
| 1434 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1435 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1436 | Phone phone = getPhoneFromRequest(request); |
| 1437 | return phone == null ? null : |
| 1438 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1439 | } |
| 1440 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1441 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1442 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1443 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1444 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1445 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1446 | private void sendEraseModemConfig(Phone phone) { |
| 1447 | if (phone != null) { |
| 1448 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 1449 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 1450 | final long identity = Binder.clearCallingIdentity(); |
| 1451 | try { |
| 1452 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 1453 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 1454 | } finally { |
| 1455 | Binder.restoreCallingIdentity(identity); |
| 1456 | } |
| 1457 | } |
| 1458 | } |
| 1459 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1460 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1461 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1462 | } |
| 1463 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1464 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1465 | if (DBG) log("dial: " + number); |
| 1466 | // No permission check needed here: This is just a wrapper around the |
| 1467 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1468 | // the UI before it does anything. |
| 1469 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1470 | final long identity = Binder.clearCallingIdentity(); |
| 1471 | try { |
| 1472 | String url = createTelUrl(number); |
| 1473 | if (url == null) { |
| 1474 | return; |
| 1475 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1476 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1477 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1478 | PhoneConstants.State state = mCM.getState(subId); |
| 1479 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1480 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1481 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1482 | mApp.startActivity(intent); |
| 1483 | } |
| 1484 | } finally { |
| 1485 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1486 | } |
| 1487 | } |
| 1488 | |
| 1489 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1490 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1491 | } |
| 1492 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1493 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1494 | if (DBG) log("call: " + number); |
| 1495 | |
| 1496 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1497 | // need to do a permission check since we're calling startActivity() |
| 1498 | // from the context of the phone app. |
| 1499 | enforceCallPermission(); |
| 1500 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 1501 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1502 | != AppOpsManager.MODE_ALLOWED) { |
| 1503 | return; |
| 1504 | } |
| 1505 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1506 | final long identity = Binder.clearCallingIdentity(); |
| 1507 | try { |
| 1508 | String url = createTelUrl(number); |
| 1509 | if (url == null) { |
| 1510 | return; |
| 1511 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1512 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1513 | boolean isValid = false; |
| 1514 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1515 | if (slist != null) { |
| 1516 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1517 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1518 | isValid = true; |
| 1519 | break; |
| 1520 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1521 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1522 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1523 | if (!isValid) { |
| 1524 | return; |
| 1525 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1526 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1527 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1528 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1529 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1530 | mApp.startActivity(intent); |
| 1531 | } finally { |
| 1532 | Binder.restoreCallingIdentity(identity); |
| 1533 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1534 | } |
| 1535 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1536 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1537 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1538 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1539 | } |
| 1540 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1541 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1542 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1543 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1544 | } |
| 1545 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1546 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1547 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1548 | |
| 1549 | final long identity = Binder.clearCallingIdentity(); |
| 1550 | try { |
| 1551 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1552 | checkSimPin.start(); |
| 1553 | return checkSimPin.unlockSim(null, pin); |
| 1554 | } finally { |
| 1555 | Binder.restoreCallingIdentity(identity); |
| 1556 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1557 | } |
| 1558 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1559 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1560 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1561 | |
| 1562 | final long identity = Binder.clearCallingIdentity(); |
| 1563 | try { |
| 1564 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1565 | checkSimPuk.start(); |
| 1566 | return checkSimPuk.unlockSim(puk, pin); |
| 1567 | } finally { |
| 1568 | Binder.restoreCallingIdentity(identity); |
| 1569 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1570 | } |
| 1571 | |
| 1572 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1573 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1574 | * a synchronous one. |
| 1575 | */ |
| 1576 | private static class UnlockSim extends Thread { |
| 1577 | |
| 1578 | private final IccCard mSimCard; |
| 1579 | |
| 1580 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1581 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1582 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1583 | |
| 1584 | // For replies from SimCard interface |
| 1585 | private Handler mHandler; |
| 1586 | |
| 1587 | // For async handler to identify request type |
| 1588 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1589 | |
| 1590 | public UnlockSim(IccCard simCard) { |
| 1591 | mSimCard = simCard; |
| 1592 | } |
| 1593 | |
| 1594 | @Override |
| 1595 | public void run() { |
| 1596 | Looper.prepare(); |
| 1597 | synchronized (UnlockSim.this) { |
| 1598 | mHandler = new Handler() { |
| 1599 | @Override |
| 1600 | public void handleMessage(Message msg) { |
| 1601 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1602 | switch (msg.what) { |
| 1603 | case SUPPLY_PIN_COMPLETE: |
| 1604 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1605 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1606 | mRetryCount = msg.arg1; |
| 1607 | if (ar.exception != null) { |
| 1608 | if (ar.exception instanceof CommandException && |
| 1609 | ((CommandException)(ar.exception)).getCommandError() |
| 1610 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1611 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1612 | } else { |
| 1613 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1614 | } |
| 1615 | } else { |
| 1616 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1617 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1618 | mDone = true; |
| 1619 | UnlockSim.this.notifyAll(); |
| 1620 | } |
| 1621 | break; |
| 1622 | } |
| 1623 | } |
| 1624 | }; |
| 1625 | UnlockSim.this.notifyAll(); |
| 1626 | } |
| 1627 | Looper.loop(); |
| 1628 | } |
| 1629 | |
| 1630 | /* |
| 1631 | * Use PIN or PUK to unlock SIM card |
| 1632 | * |
| 1633 | * If PUK is null, unlock SIM card with PIN |
| 1634 | * |
| 1635 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1636 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1637 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1638 | |
| 1639 | while (mHandler == null) { |
| 1640 | try { |
| 1641 | wait(); |
| 1642 | } catch (InterruptedException e) { |
| 1643 | Thread.currentThread().interrupt(); |
| 1644 | } |
| 1645 | } |
| 1646 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1647 | |
| 1648 | if (puk == null) { |
| 1649 | mSimCard.supplyPin(pin, callback); |
| 1650 | } else { |
| 1651 | mSimCard.supplyPuk(puk, pin, callback); |
| 1652 | } |
| 1653 | |
| 1654 | while (!mDone) { |
| 1655 | try { |
| 1656 | Log.d(LOG_TAG, "wait for done"); |
| 1657 | wait(); |
| 1658 | } catch (InterruptedException e) { |
| 1659 | // Restore the interrupted status |
| 1660 | Thread.currentThread().interrupt(); |
| 1661 | } |
| 1662 | } |
| 1663 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1664 | int[] resultArray = new int[2]; |
| 1665 | resultArray[0] = mResult; |
| 1666 | resultArray[1] = mRetryCount; |
| 1667 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1668 | } |
| 1669 | } |
| 1670 | |
| 1671 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1672 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1673 | |
| 1674 | } |
| 1675 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1676 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1677 | // No permission check needed here: this call is harmless, and it's |
| 1678 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1679 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1680 | final long identity = Binder.clearCallingIdentity(); |
| 1681 | try { |
| 1682 | final Phone phone = getPhone(subId); |
| 1683 | if (phone != null) { |
| 1684 | phone.updateServiceLocation(); |
| 1685 | } |
| 1686 | } finally { |
| 1687 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1688 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1689 | } |
| 1690 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1691 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1692 | @Override |
| 1693 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1694 | return isRadioOnWithFeature(callingPackage, null); |
| 1695 | } |
| 1696 | |
| 1697 | |
| 1698 | @Override |
| 1699 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 1700 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 1701 | callingFeatureId); |
| 1702 | } |
| 1703 | |
| 1704 | @Deprecated |
| 1705 | @Override |
| 1706 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 1707 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1708 | } |
| 1709 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1710 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1711 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 1712 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1713 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1714 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1715 | return false; |
| 1716 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1717 | |
| 1718 | final long identity = Binder.clearCallingIdentity(); |
| 1719 | try { |
| 1720 | return isRadioOnForSubscriber(subId); |
| 1721 | } finally { |
| 1722 | Binder.restoreCallingIdentity(identity); |
| 1723 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1724 | } |
| 1725 | |
| 1726 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1727 | final long identity = Binder.clearCallingIdentity(); |
| 1728 | try { |
| 1729 | final Phone phone = getPhone(subId); |
| 1730 | if (phone != null) { |
| 1731 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1732 | } else { |
| 1733 | return false; |
| 1734 | } |
| 1735 | } finally { |
| 1736 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1737 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1738 | } |
| 1739 | |
| 1740 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1741 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1742 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1743 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1744 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1745 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1746 | |
| 1747 | final long identity = Binder.clearCallingIdentity(); |
| 1748 | try { |
| 1749 | final Phone phone = getPhone(subId); |
| 1750 | if (phone != null) { |
| 1751 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1752 | } |
| 1753 | } finally { |
| 1754 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1755 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1756 | } |
| 1757 | |
| 1758 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1759 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1760 | } |
| 1761 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1762 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1763 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1764 | |
| 1765 | final long identity = Binder.clearCallingIdentity(); |
| 1766 | try { |
| 1767 | final Phone phone = getPhone(subId); |
| 1768 | if (phone == null) { |
| 1769 | return false; |
| 1770 | } |
| 1771 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1772 | toggleRadioOnOffForSubscriber(subId); |
| 1773 | } |
| 1774 | return true; |
| 1775 | } finally { |
| 1776 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1777 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1778 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1779 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1780 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 1781 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1782 | /* |
| 1783 | * If any of the Radios are available, it will need to be |
| 1784 | * shutdown. So return true if any Radio is available. |
| 1785 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1786 | final long identity = Binder.clearCallingIdentity(); |
| 1787 | try { |
| 1788 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1789 | Phone phone = PhoneFactory.getPhone(i); |
| 1790 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1791 | } |
| 1792 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1793 | return false; |
| 1794 | } finally { |
| 1795 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1796 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1797 | } |
| 1798 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1799 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1800 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1801 | enforceModifyPermission(); |
| 1802 | |
| 1803 | final long identity = Binder.clearCallingIdentity(); |
| 1804 | try { |
| 1805 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1806 | logv("Shutting down Phone " + i); |
| 1807 | shutdownRadioUsingPhoneId(i); |
| 1808 | } |
| 1809 | } finally { |
| 1810 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1811 | } |
| 1812 | } |
| 1813 | |
| 1814 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1815 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1816 | if (phone != null && phone.isRadioAvailable()) { |
| 1817 | phone.shutdownRadio(); |
| 1818 | } |
| 1819 | } |
| 1820 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1821 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 1822 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1823 | |
| 1824 | final long identity = Binder.clearCallingIdentity(); |
| 1825 | try { |
| 1826 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1827 | if (defaultPhone != null) { |
| 1828 | defaultPhone.setRadioPower(turnOn); |
| 1829 | return true; |
| 1830 | } else { |
| 1831 | loge("There's no default phone."); |
| 1832 | return false; |
| 1833 | } |
| 1834 | } finally { |
| 1835 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1836 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1837 | } |
| 1838 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1839 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1840 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1841 | |
| 1842 | final long identity = Binder.clearCallingIdentity(); |
| 1843 | try { |
| 1844 | final Phone phone = getPhone(subId); |
| 1845 | if (phone != null) { |
| 1846 | phone.setRadioPower(turnOn); |
| 1847 | return true; |
| 1848 | } else { |
| 1849 | return false; |
| 1850 | } |
| 1851 | } finally { |
| 1852 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1853 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1854 | } |
| 1855 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1856 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1857 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1858 | public boolean enableDataConnectivity() { |
| 1859 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1860 | |
| 1861 | final long identity = Binder.clearCallingIdentity(); |
| 1862 | try { |
| 1863 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1864 | final Phone phone = getPhone(subId); |
| 1865 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1866 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1867 | return true; |
| 1868 | } else { |
| 1869 | return false; |
| 1870 | } |
| 1871 | } finally { |
| 1872 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1873 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1874 | } |
| 1875 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1876 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1877 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1878 | public boolean disableDataConnectivity() { |
| 1879 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1880 | |
| 1881 | final long identity = Binder.clearCallingIdentity(); |
| 1882 | try { |
| 1883 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1884 | final Phone phone = getPhone(subId); |
| 1885 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1886 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1887 | return true; |
| 1888 | } else { |
| 1889 | return false; |
| 1890 | } |
| 1891 | } finally { |
| 1892 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1893 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1894 | } |
| 1895 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1896 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1897 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1898 | final long identity = Binder.clearCallingIdentity(); |
| 1899 | try { |
| 1900 | final Phone phone = getPhone(subId); |
| 1901 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 1902 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1903 | } else { |
| 1904 | return false; |
| 1905 | } |
| 1906 | } finally { |
| 1907 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1908 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1909 | } |
| 1910 | |
| 1911 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1912 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1913 | } |
| 1914 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1915 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1916 | enforceCallPermission(); |
| 1917 | |
| 1918 | final long identity = Binder.clearCallingIdentity(); |
| 1919 | try { |
| 1920 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1921 | return; |
| 1922 | } |
| 1923 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 1924 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 1925 | } finally { |
| 1926 | Binder.restoreCallingIdentity(identity); |
| 1927 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 1928 | }; |
| 1929 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1930 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1931 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1932 | |
| 1933 | final long identity = Binder.clearCallingIdentity(); |
| 1934 | try { |
| 1935 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1936 | return false; |
| 1937 | } |
| 1938 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 1939 | } finally { |
| 1940 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1941 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1942 | } |
| 1943 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1944 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 1945 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1946 | } |
| 1947 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 1948 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1949 | final long identity = Binder.clearCallingIdentity(); |
| 1950 | try { |
| 1951 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 1952 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 1953 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 1954 | } finally { |
| 1955 | Binder.restoreCallingIdentity(identity); |
| 1956 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1957 | } |
| 1958 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1959 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 1960 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1961 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 1962 | } |
| 1963 | |
| 1964 | @Override |
| 1965 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1966 | final long identity = Binder.clearCallingIdentity(); |
| 1967 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1968 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1969 | if (phone != null) { |
| 1970 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 1971 | } else { |
| 1972 | return PhoneConstantConversions.convertDataState( |
| 1973 | PhoneConstants.DataState.DISCONNECTED); |
| 1974 | } |
| 1975 | } finally { |
| 1976 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1977 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1978 | } |
| 1979 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1980 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 1981 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1982 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 1983 | } |
| 1984 | |
| 1985 | @Override |
| 1986 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1987 | final long identity = Binder.clearCallingIdentity(); |
| 1988 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 1989 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1990 | if (phone != null) { |
| 1991 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 1992 | } else { |
| 1993 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 1994 | } |
| 1995 | } finally { |
| 1996 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1997 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1998 | } |
| 1999 | |
| 2000 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2001 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2002 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2003 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2004 | |
| 2005 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2006 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2007 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2008 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2009 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2010 | .setCallingPid(Binder.getCallingPid()) |
| 2011 | .setCallingUid(Binder.getCallingUid()) |
| 2012 | .setMethod("getCellLocation") |
| 2013 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2014 | .build()); |
| 2015 | switch (locationResult) { |
| 2016 | case DENIED_HARD: |
| 2017 | throw new SecurityException("Not allowed to access cell location"); |
| 2018 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2019 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2020 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2021 | } |
| 2022 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2023 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2024 | final long identity = Binder.clearCallingIdentity(); |
| 2025 | try { |
| 2026 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2027 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2028 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2029 | } finally { |
| 2030 | Binder.restoreCallingIdentity(identity); |
| 2031 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2032 | } |
| 2033 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2034 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2035 | public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage, |
| 2036 | String callingFeatureId) { |
Jack Yu | 1e81ccd | 2019-09-26 11:48:33 -0700 | [diff] [blame] | 2037 | if (!TextUtils.isEmpty(callingPackage)) { |
| 2038 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2039 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2040 | callingFeatureId, "getNetworkCountryIsoForPhone")) { |
Jack Yu | 1e81ccd | 2019-09-26 11:48:33 -0700 | [diff] [blame] | 2041 | return ""; |
| 2042 | } |
| 2043 | } |
| 2044 | |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2045 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2046 | // registered cell info, so return a NULL country instead. |
| 2047 | final long identity = Binder.clearCallingIdentity(); |
| 2048 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2049 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2050 | // Get default phone in this case. |
| 2051 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2052 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2053 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 2054 | // Todo: fix this when we can get the actual cellular network info when the device |
| 2055 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2056 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2057 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(), |
| 2058 | mApp.getFeatureId())) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2059 | return ""; |
| 2060 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2061 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2062 | if (phone != null) { |
| 2063 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2064 | EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2065 | if (sst != null) { |
| 2066 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2067 | if (lt != null) { |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2068 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) { |
| 2069 | return lt.getCurrentCountry(); |
| 2070 | } else if (emergencyNumberTracker != null) { |
| 2071 | return emergencyNumberTracker.getEmergencyCountryIso(); |
| 2072 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2073 | } |
| 2074 | } |
| 2075 | } |
| 2076 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2077 | } finally { |
| 2078 | Binder.restoreCallingIdentity(identity); |
| 2079 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2080 | } |
| 2081 | |
| 2082 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2083 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2084 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2085 | } |
| 2086 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2087 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2088 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2089 | mApp.enforceCallingOrSelfPermission( |
| 2090 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2091 | |
| 2092 | final long identity = Binder.clearCallingIdentity(); |
| 2093 | try { |
| 2094 | final Phone phone = getPhone(subId); |
| 2095 | if (phone != null) { |
| 2096 | phone.enableLocationUpdates(); |
| 2097 | } |
| 2098 | } finally { |
| 2099 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2100 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2101 | } |
| 2102 | |
| 2103 | @Override |
| 2104 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2105 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2106 | } |
| 2107 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2108 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2109 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2110 | mApp.enforceCallingOrSelfPermission( |
| 2111 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2112 | |
| 2113 | final long identity = Binder.clearCallingIdentity(); |
| 2114 | try { |
| 2115 | final Phone phone = getPhone(subId); |
| 2116 | if (phone != null) { |
| 2117 | phone.disableLocationUpdates(); |
| 2118 | } |
| 2119 | } finally { |
| 2120 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2121 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2122 | } |
| 2123 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2124 | /** |
| 2125 | * Returns the target SDK version number for a given package name. |
| 2126 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2127 | * This call MUST be invoked before clearing the calling UID. |
| 2128 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2129 | * @return target SDK if the package is found or INT_MAX. |
| 2130 | */ |
| 2131 | private int getTargetSdk(String packageName) { |
| 2132 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2133 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 0150f0e | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2134 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2135 | if (ai != null) return ai.targetSdkVersion; |
| 2136 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2137 | loge("Failed to get package info for pkg=" |
| 2138 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2139 | } |
| 2140 | return Integer.MAX_VALUE; |
| 2141 | } |
| 2142 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2143 | @Override |
| 2144 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2145 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2146 | String callingFeatureId) { |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2147 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2148 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2149 | throw new SecurityException( |
| 2150 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2151 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2152 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2153 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2154 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2155 | return null; |
| 2156 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2157 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2158 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2159 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2160 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2161 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2162 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2163 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2164 | for (CellInfo ci : info) { |
| 2165 | if (ci instanceof CellInfoGsm) { |
| 2166 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2167 | } else if (ci instanceof CellInfoWcdma) { |
| 2168 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2169 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2170 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2171 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2172 | } |
| 2173 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2174 | private List<CellInfo> getCachedCellInfo() { |
| 2175 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2176 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2177 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2178 | if (info != null) cellInfos.addAll(info); |
| 2179 | } |
| 2180 | return cellInfos; |
| 2181 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2182 | |
| 2183 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2184 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2185 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2186 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2187 | |
| 2188 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2189 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2190 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2191 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2192 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2193 | .setCallingPid(Binder.getCallingPid()) |
| 2194 | .setCallingUid(Binder.getCallingUid()) |
| 2195 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2196 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2197 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2198 | .build()); |
| 2199 | switch (locationResult) { |
| 2200 | case DENIED_HARD: |
| 2201 | throw new SecurityException("Not allowed to access cell info"); |
| 2202 | case DENIED_SOFT: |
| 2203 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2204 | } |
| 2205 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2206 | final int targetSdk = getTargetSdk(callingPackage); |
| 2207 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2208 | return getCachedCellInfo(); |
| 2209 | } |
| 2210 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2211 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2212 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2213 | final long identity = Binder.clearCallingIdentity(); |
| 2214 | try { |
| 2215 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2216 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2217 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2218 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2219 | if (info != null) cellInfos.addAll(info); |
| 2220 | } |
| 2221 | return cellInfos; |
| 2222 | } finally { |
| 2223 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2224 | } |
| 2225 | } |
| 2226 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2227 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2228 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2229 | String callingFeatureId) { |
| 2230 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2231 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2232 | } |
| 2233 | |
| 2234 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2235 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2236 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2237 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2238 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2239 | } |
| 2240 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2241 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2242 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2243 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2244 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2245 | |
| 2246 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2247 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2248 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2249 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2250 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2251 | .setCallingPid(Binder.getCallingPid()) |
| 2252 | .setCallingUid(Binder.getCallingUid()) |
| 2253 | .setMethod("requestCellInfoUpdate") |
| 2254 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2255 | .build()); |
| 2256 | switch (locationResult) { |
| 2257 | case DENIED_HARD: |
| 2258 | throw new SecurityException("Not allowed to access cell info"); |
| 2259 | case DENIED_SOFT: |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2260 | try { |
| 2261 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2262 | } catch (RemoteException re) { |
| 2263 | // Drop without consequences |
| 2264 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2265 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2266 | } |
| 2267 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2268 | |
| 2269 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2270 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2271 | |
| 2272 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2273 | } |
| 2274 | |
| 2275 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2276 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2277 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2278 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2279 | |
| 2280 | final long identity = Binder.clearCallingIdentity(); |
| 2281 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2282 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2283 | } finally { |
| 2284 | Binder.restoreCallingIdentity(identity); |
| 2285 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2286 | } |
| 2287 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2288 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2289 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2290 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2291 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2292 | return null; |
| 2293 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2294 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2295 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2296 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2297 | return null; |
| 2298 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2299 | |
| 2300 | final long identity = Binder.clearCallingIdentity(); |
| 2301 | try { |
| 2302 | return phone.getImei(); |
| 2303 | } finally { |
| 2304 | Binder.restoreCallingIdentity(identity); |
| 2305 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2306 | } |
| 2307 | |
| 2308 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2309 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2310 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2311 | String tac = null; |
| 2312 | if (phone != null) { |
| 2313 | String imei = phone.getImei(); |
| 2314 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2315 | } |
| 2316 | return tac; |
| 2317 | } |
| 2318 | |
| 2319 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2320 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2321 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2322 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2323 | return null; |
| 2324 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2325 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2326 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2327 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2328 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2329 | return null; |
| 2330 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2331 | |
| 2332 | final long identity = Binder.clearCallingIdentity(); |
| 2333 | try { |
| 2334 | return phone.getMeid(); |
| 2335 | } finally { |
| 2336 | Binder.restoreCallingIdentity(identity); |
| 2337 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2338 | } |
| 2339 | |
| 2340 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2341 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2342 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2343 | String manufacturerCode = null; |
| 2344 | if (phone != null) { |
| 2345 | String meid = phone.getMeid(); |
| 2346 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2347 | } |
| 2348 | return manufacturerCode; |
| 2349 | } |
| 2350 | |
| 2351 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2352 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2353 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2354 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2355 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2356 | return null; |
| 2357 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2358 | int subId = phone.getSubId(); |
| 2359 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2360 | mApp, subId, callingPackage, callingFeatureId, |
| 2361 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2362 | return null; |
| 2363 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2364 | |
| 2365 | final long identity = Binder.clearCallingIdentity(); |
| 2366 | try { |
| 2367 | return phone.getDeviceSvn(); |
| 2368 | } finally { |
| 2369 | Binder.restoreCallingIdentity(identity); |
| 2370 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2371 | } |
| 2372 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2373 | @Override |
| 2374 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2375 | final long identity = Binder.clearCallingIdentity(); |
| 2376 | try { |
| 2377 | final Phone phone = getPhone(subId); |
| 2378 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2379 | } finally { |
| 2380 | Binder.restoreCallingIdentity(identity); |
| 2381 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2382 | } |
| 2383 | |
| 2384 | @Override |
| 2385 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2386 | final long identity = Binder.clearCallingIdentity(); |
| 2387 | try { |
| 2388 | final Phone phone = getPhone(subId); |
| 2389 | return phone == null ? null : phone.getCarrierName(); |
| 2390 | } finally { |
| 2391 | Binder.restoreCallingIdentity(identity); |
| 2392 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2393 | } |
| 2394 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2395 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2396 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2397 | final long identity = Binder.clearCallingIdentity(); |
| 2398 | try { |
| 2399 | final Phone phone = getPhone(subId); |
| 2400 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2401 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2402 | } finally { |
| 2403 | Binder.restoreCallingIdentity(identity); |
| 2404 | } |
| 2405 | } |
| 2406 | |
| 2407 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2408 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2409 | final long identity = Binder.clearCallingIdentity(); |
| 2410 | try { |
| 2411 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2412 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2413 | } finally { |
| 2414 | Binder.restoreCallingIdentity(identity); |
| 2415 | } |
| 2416 | } |
| 2417 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2418 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2419 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2420 | if (!isSubscriptionMccMnc) { |
| 2421 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2422 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2423 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2424 | if (phone == null) { |
| 2425 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2426 | } |
| 2427 | final long identity = Binder.clearCallingIdentity(); |
| 2428 | try { |
| 2429 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2430 | } finally { |
| 2431 | Binder.restoreCallingIdentity(identity); |
| 2432 | } |
| 2433 | } |
| 2434 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2435 | // |
| 2436 | // Internal helper methods. |
| 2437 | // |
| 2438 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2439 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2440 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2441 | * |
| 2442 | * @throws SecurityException if the caller does not have the required permission |
| 2443 | */ |
| 2444 | private void enforceModifyPermission() { |
| 2445 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2446 | } |
| 2447 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 2448 | private void enforceActiveEmergencySessionPermission() { |
| 2449 | mApp.enforceCallingOrSelfPermission( |
| 2450 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 2451 | } |
| 2452 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2453 | /** |
| 2454 | * Make sure the caller has the CALL_PHONE permission. |
| 2455 | * |
| 2456 | * @throws SecurityException if the caller does not have the required permission |
| 2457 | */ |
| 2458 | private void enforceCallPermission() { |
| 2459 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2460 | } |
| 2461 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 2462 | private void enforceSettingsPermission() { |
| 2463 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2464 | } |
| 2465 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2466 | private String createTelUrl(String number) { |
| 2467 | if (TextUtils.isEmpty(number)) { |
| 2468 | return null; |
| 2469 | } |
| 2470 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2471 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2472 | } |
| 2473 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2474 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2475 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2476 | } |
| 2477 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2478 | private static void logv(String msg) { |
| 2479 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2480 | } |
| 2481 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2482 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2483 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2484 | } |
| 2485 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2486 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2487 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2488 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2489 | } |
| 2490 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2491 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2492 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2493 | final long identity = Binder.clearCallingIdentity(); |
| 2494 | try { |
| 2495 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2496 | if (phone == null) { |
| 2497 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2498 | } else { |
| 2499 | return phone.getPhoneType(); |
| 2500 | } |
| 2501 | } finally { |
| 2502 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2503 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2504 | } |
| 2505 | |
| 2506 | /** |
| 2507 | * Returns the CDMA ERI icon index to display |
| 2508 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2509 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2510 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 2511 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 2512 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2513 | } |
| 2514 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2515 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2516 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 2517 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2518 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2519 | mApp, subId, callingPackage, callingFeatureId, |
| 2520 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2521 | return -1; |
| 2522 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2523 | |
| 2524 | final long identity = Binder.clearCallingIdentity(); |
| 2525 | try { |
| 2526 | final Phone phone = getPhone(subId); |
| 2527 | if (phone != null) { |
| 2528 | return phone.getCdmaEriIconIndex(); |
| 2529 | } else { |
| 2530 | return -1; |
| 2531 | } |
| 2532 | } finally { |
| 2533 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2534 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2535 | } |
| 2536 | |
| 2537 | /** |
| 2538 | * Returns the CDMA ERI icon mode, |
| 2539 | * 0 - ON |
| 2540 | * 1 - FLASHING |
| 2541 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2542 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2543 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 2544 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 2545 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2546 | } |
| 2547 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2548 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2549 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 2550 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2551 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2552 | mApp, subId, callingPackage, callingFeatureId, |
| 2553 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2554 | return -1; |
| 2555 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2556 | |
| 2557 | final long identity = Binder.clearCallingIdentity(); |
| 2558 | try { |
| 2559 | final Phone phone = getPhone(subId); |
| 2560 | if (phone != null) { |
| 2561 | return phone.getCdmaEriIconMode(); |
| 2562 | } else { |
| 2563 | return -1; |
| 2564 | } |
| 2565 | } finally { |
| 2566 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2567 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2568 | } |
| 2569 | |
| 2570 | /** |
| 2571 | * Returns the CDMA ERI text, |
| 2572 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2573 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2574 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 2575 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 2576 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2577 | } |
| 2578 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2579 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2580 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 2581 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2582 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2583 | mApp, subId, callingPackage, callingFeatureId, |
| 2584 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2585 | return null; |
| 2586 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2587 | |
| 2588 | final long identity = Binder.clearCallingIdentity(); |
| 2589 | try { |
| 2590 | final Phone phone = getPhone(subId); |
| 2591 | if (phone != null) { |
| 2592 | return phone.getCdmaEriText(); |
| 2593 | } else { |
| 2594 | return null; |
| 2595 | } |
| 2596 | } finally { |
| 2597 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2598 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2599 | } |
| 2600 | |
| 2601 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2602 | * Returns the CDMA MDN. |
| 2603 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2604 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2605 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2606 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2607 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2608 | |
| 2609 | final long identity = Binder.clearCallingIdentity(); |
| 2610 | try { |
| 2611 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2612 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2613 | return phone.getLine1Number(); |
| 2614 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2615 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2616 | return null; |
| 2617 | } |
| 2618 | } finally { |
| 2619 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2620 | } |
| 2621 | } |
| 2622 | |
| 2623 | /** |
| 2624 | * Returns the CDMA MIN. |
| 2625 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2626 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2627 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2628 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2629 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2630 | |
| 2631 | final long identity = Binder.clearCallingIdentity(); |
| 2632 | try { |
| 2633 | final Phone phone = getPhone(subId); |
| 2634 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2635 | return phone.getCdmaMin(); |
| 2636 | } else { |
| 2637 | return null; |
| 2638 | } |
| 2639 | } finally { |
| 2640 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2641 | } |
| 2642 | } |
| 2643 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2644 | @Override |
| 2645 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2646 | INumberVerificationCallback callback, String callingPackage) { |
| 2647 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2648 | != PERMISSION_GRANTED) { |
| 2649 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2650 | } |
| 2651 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2652 | |
| 2653 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2654 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2655 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2656 | } |
| 2657 | |
| 2658 | if (range == null) { |
| 2659 | throw new NullPointerException("Range must be non-null"); |
| 2660 | } |
| 2661 | |
| 2662 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2663 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2664 | |
| 2665 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2666 | } |
| 2667 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2668 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2669 | * Returns true if CDMA provisioning needs to run. |
| 2670 | */ |
| 2671 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2672 | final long identity = Binder.clearCallingIdentity(); |
| 2673 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2674 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2675 | } finally { |
| 2676 | Binder.restoreCallingIdentity(identity); |
| 2677 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2678 | } |
| 2679 | |
| 2680 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2681 | * Sets the voice mail number of a given subId. |
| 2682 | */ |
| 2683 | @Override |
| 2684 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 2685 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2686 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2687 | |
| 2688 | final long identity = Binder.clearCallingIdentity(); |
| 2689 | try { |
| 2690 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2691 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2692 | return success; |
| 2693 | } finally { |
| 2694 | Binder.restoreCallingIdentity(identity); |
| 2695 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2696 | } |
| 2697 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2698 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2699 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2700 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 2701 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 2702 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2703 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2704 | throw new SecurityException("caller must be system dialer"); |
| 2705 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2706 | |
| 2707 | final long identity = Binder.clearCallingIdentity(); |
| 2708 | try { |
| 2709 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2710 | if (phoneAccountHandle == null) { |
| 2711 | return null; |
| 2712 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2713 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2714 | } finally { |
| 2715 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2716 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2717 | } |
| 2718 | |
| 2719 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2720 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 2721 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2722 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2723 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2724 | mApp, subId, callingPackage, callingFeatureId, |
| 2725 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2726 | return null; |
| 2727 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2728 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2729 | final long identity = Binder.clearCallingIdentity(); |
| 2730 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2731 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2732 | } finally { |
| 2733 | Binder.restoreCallingIdentity(identity); |
| 2734 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2735 | } |
| 2736 | |
| 2737 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2738 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2739 | VisualVoicemailSmsFilterSettings settings) { |
| 2740 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2741 | |
| 2742 | final long identity = Binder.clearCallingIdentity(); |
| 2743 | try { |
| 2744 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2745 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2746 | } finally { |
| 2747 | Binder.restoreCallingIdentity(identity); |
| 2748 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2749 | } |
| 2750 | |
| 2751 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2752 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2753 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2754 | |
| 2755 | final long identity = Binder.clearCallingIdentity(); |
| 2756 | try { |
| 2757 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2758 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2759 | } finally { |
| 2760 | Binder.restoreCallingIdentity(identity); |
| 2761 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2762 | } |
| 2763 | |
| 2764 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2765 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2766 | String callingPackage, int subId) { |
| 2767 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2768 | |
| 2769 | final long identity = Binder.clearCallingIdentity(); |
| 2770 | try { |
| 2771 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2772 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2773 | } finally { |
| 2774 | Binder.restoreCallingIdentity(identity); |
| 2775 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2776 | } |
| 2777 | |
| 2778 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2779 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2780 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2781 | |
| 2782 | final long identity = Binder.clearCallingIdentity(); |
| 2783 | try { |
| 2784 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2785 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2786 | } finally { |
| 2787 | Binder.restoreCallingIdentity(identity); |
| 2788 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2789 | } |
| 2790 | |
| 2791 | @Override |
| 2792 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2793 | String number, int port, String text, PendingIntent sentIntent) { |
| 2794 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2795 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2796 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2797 | SmsController smsController = PhoneFactory.getSmsController(); |
| 2798 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text, |
| 2799 | sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2800 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2801 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2802 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2803 | * Sets the voice activation state of a given subId. |
| 2804 | */ |
| 2805 | @Override |
| 2806 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2807 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2808 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2809 | |
| 2810 | final long identity = Binder.clearCallingIdentity(); |
| 2811 | try { |
| 2812 | final Phone phone = getPhone(subId); |
| 2813 | if (phone != null) { |
| 2814 | phone.setVoiceActivationState(activationState); |
| 2815 | } else { |
| 2816 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2817 | } |
| 2818 | } finally { |
| 2819 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2820 | } |
| 2821 | } |
| 2822 | |
| 2823 | /** |
| 2824 | * Sets the data activation state of a given subId. |
| 2825 | */ |
| 2826 | @Override |
| 2827 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2828 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2829 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2830 | |
| 2831 | final long identity = Binder.clearCallingIdentity(); |
| 2832 | try { |
| 2833 | final Phone phone = getPhone(subId); |
| 2834 | if (phone != null) { |
| 2835 | phone.setDataActivationState(activationState); |
| 2836 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 2837 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2838 | } |
| 2839 | } finally { |
| 2840 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2841 | } |
| 2842 | } |
| 2843 | |
| 2844 | /** |
| 2845 | * Returns the voice activation state of a given subId. |
| 2846 | */ |
| 2847 | @Override |
| 2848 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2849 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2850 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2851 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2852 | final long identity = Binder.clearCallingIdentity(); |
| 2853 | try { |
| 2854 | if (phone != null) { |
| 2855 | return phone.getVoiceActivationState(); |
| 2856 | } else { |
| 2857 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2858 | } |
| 2859 | } finally { |
| 2860 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2861 | } |
| 2862 | } |
| 2863 | |
| 2864 | /** |
| 2865 | * Returns the data activation state of a given subId. |
| 2866 | */ |
| 2867 | @Override |
| 2868 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2869 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2870 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2871 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2872 | final long identity = Binder.clearCallingIdentity(); |
| 2873 | try { |
| 2874 | if (phone != null) { |
| 2875 | return phone.getDataActivationState(); |
| 2876 | } else { |
| 2877 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2878 | } |
| 2879 | } finally { |
| 2880 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2881 | } |
| 2882 | } |
| 2883 | |
| 2884 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2885 | * Returns the unread count of voicemails for a subId |
| 2886 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2887 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2888 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 2889 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2890 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2891 | mApp, subId, callingPackage, callingFeatureId, |
| 2892 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2893 | return 0; |
| 2894 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2895 | final long identity = Binder.clearCallingIdentity(); |
| 2896 | try { |
| 2897 | final Phone phone = getPhone(subId); |
| 2898 | if (phone != null) { |
| 2899 | return phone.getVoiceMessageCount(); |
| 2900 | } else { |
| 2901 | return 0; |
| 2902 | } |
| 2903 | } finally { |
| 2904 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2905 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2906 | } |
| 2907 | |
| 2908 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2909 | * returns true, if the device is in a state where both voice and data |
| 2910 | * are supported simultaneously. This can change based on location or network condition. |
| 2911 | */ |
| 2912 | @Override |
| 2913 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2914 | final long identity = Binder.clearCallingIdentity(); |
| 2915 | try { |
| 2916 | final Phone phone = getPhone(subId); |
| 2917 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 2918 | } finally { |
| 2919 | Binder.restoreCallingIdentity(identity); |
| 2920 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2921 | } |
| 2922 | |
| 2923 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2924 | * Send the dialer code if called from the current default dialer or the caller has |
| 2925 | * carrier privilege. |
| 2926 | * @param inputCode The dialer code to send |
| 2927 | */ |
| 2928 | @Override |
| 2929 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2930 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2931 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 2932 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 2933 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2934 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 2935 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2936 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2937 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2938 | |
| 2939 | final long identity = Binder.clearCallingIdentity(); |
| 2940 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2941 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2942 | } finally { |
| 2943 | Binder.restoreCallingIdentity(identity); |
| 2944 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 2945 | } |
| 2946 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2947 | @Override |
| 2948 | public int getNetworkSelectionMode(int subId) { |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 2949 | if (!isActiveSubscription(subId)) { |
| 2950 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 2951 | } |
| 2952 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 2953 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 2954 | } |
| 2955 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2956 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 2957 | public boolean isInEmergencySmsMode() { |
| 2958 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 2959 | final long identity = Binder.clearCallingIdentity(); |
| 2960 | try { |
| 2961 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2962 | if (phone.isInEmergencySmsMode()) { |
| 2963 | return true; |
| 2964 | } |
| 2965 | } |
| 2966 | } finally { |
| 2967 | Binder.restoreCallingIdentity(identity); |
| 2968 | } |
| 2969 | return false; |
| 2970 | } |
| 2971 | |
| 2972 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2973 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 2974 | throws RemoteException { |
| 2975 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 2976 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 2977 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 2978 | "IMS not available on device."); |
| 2979 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2980 | final long token = Binder.clearCallingIdentity(); |
| 2981 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2982 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2983 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2984 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 2985 | } catch (ImsException e) { |
| 2986 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2987 | } finally { |
| 2988 | Binder.restoreCallingIdentity(token); |
| 2989 | } |
| 2990 | } |
| 2991 | |
| 2992 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 2993 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
| 2994 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 2995 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2996 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 2997 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 2998 | final long token = Binder.clearCallingIdentity(); |
| 2999 | try { |
| 3000 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3001 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3002 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3003 | } catch (ImsException e) { |
| 3004 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3005 | + "is inactive, ignoring unregister."); |
| 3006 | // If the subscription is no longer active, just return, since the callback |
| 3007 | // will already have been removed internally. |
| 3008 | } finally { |
| 3009 | Binder.restoreCallingIdentity(token); |
| 3010 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3011 | } |
| 3012 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3013 | /** |
| 3014 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3015 | */ |
| 3016 | @Override |
| 3017 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3018 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3019 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3020 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3021 | "IMS not available on device."); |
| 3022 | } |
| 3023 | final long token = Binder.clearCallingIdentity(); |
| 3024 | try { |
| 3025 | Phone phone = getPhone(subId); |
| 3026 | if (phone == null) { |
| 3027 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3028 | + subId + "'"); |
| 3029 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3030 | } |
| 3031 | phone.getImsRegistrationState(regState -> { |
| 3032 | try { |
| 3033 | consumer.accept((regState == null) |
| 3034 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3035 | } catch (RemoteException e) { |
| 3036 | // Ignore if the remote process is no longer available to call back. |
| 3037 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3038 | } |
| 3039 | }); |
| 3040 | } finally { |
| 3041 | Binder.restoreCallingIdentity(token); |
| 3042 | } |
| 3043 | } |
| 3044 | |
| 3045 | /** |
| 3046 | * Get the transport type for the IMS service registration state. |
| 3047 | */ |
| 3048 | @Override |
| 3049 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
| 3050 | enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType"); |
| 3051 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3052 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3053 | "IMS not available on device."); |
| 3054 | } |
| 3055 | final long token = Binder.clearCallingIdentity(); |
| 3056 | try { |
| 3057 | Phone phone = getPhone(subId); |
| 3058 | if (phone == null) { |
| 3059 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3060 | + subId + "'"); |
| 3061 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3062 | } |
| 3063 | phone.getImsRegistrationTech(regTech -> { |
| 3064 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3065 | int regTechConverted = (regTech == null) |
| 3066 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3067 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3068 | regTechConverted); |
| 3069 | try { |
| 3070 | consumer.accept(regTechConverted); |
| 3071 | } catch (RemoteException e) { |
| 3072 | // Ignore if the remote process is no longer available to call back. |
| 3073 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3074 | } |
| 3075 | }); |
| 3076 | } finally { |
| 3077 | Binder.restoreCallingIdentity(token); |
| 3078 | } |
| 3079 | } |
| 3080 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3081 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3082 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3083 | throws RemoteException { |
| 3084 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3085 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3086 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3087 | "IMS not available on device."); |
| 3088 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3089 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3090 | final long token = Binder.clearCallingIdentity(); |
| 3091 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3092 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3093 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3094 | } catch (ImsException e) { |
| 3095 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3096 | } finally { |
| 3097 | Binder.restoreCallingIdentity(token); |
| 3098 | } |
| 3099 | } |
| 3100 | |
| 3101 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3102 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
| 3103 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3104 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3105 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3106 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3107 | |
| 3108 | final long token = Binder.clearCallingIdentity(); |
| 3109 | try { |
| 3110 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3111 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3112 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3113 | } catch (ImsException e) { |
| 3114 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3115 | + "is inactive, ignoring unregister."); |
| 3116 | // If the subscription is no longer active, just return, since the callback |
| 3117 | // will already have been removed internally. |
| 3118 | } finally { |
| 3119 | Binder.restoreCallingIdentity(token); |
| 3120 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3121 | } |
| 3122 | |
| 3123 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3124 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3125 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3126 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3127 | final long token = Binder.clearCallingIdentity(); |
| 3128 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3129 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3130 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3131 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3132 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3133 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3134 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3135 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3136 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3137 | } finally { |
| 3138 | Binder.restoreCallingIdentity(token); |
| 3139 | } |
| 3140 | } |
| 3141 | |
| 3142 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3143 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3144 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3145 | final long token = Binder.clearCallingIdentity(); |
| 3146 | try { |
| 3147 | Phone phone = getPhone(subId); |
| 3148 | if (phone == null) return false; |
| 3149 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 3150 | } finally { |
| 3151 | Binder.restoreCallingIdentity(token); |
| 3152 | } |
| 3153 | } |
| 3154 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3155 | /** |
| 3156 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3157 | * subscription. |
| 3158 | * @param subId The subscription to use to check the configuration. |
| 3159 | * @param callback The callback that will be used to send the result. |
| 3160 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3161 | * @param transportType The transport type of the MmTelFeature capability. |
| 3162 | */ |
| 3163 | @Override |
| 3164 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3165 | int transportType) { |
| 3166 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3167 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3168 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3169 | "IMS not available on device."); |
| 3170 | } |
| 3171 | final long token = Binder.clearCallingIdentity(); |
| 3172 | try { |
| 3173 | int slotId = getSlotIndex(subId); |
| 3174 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3175 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3176 | + subId + "'"); |
| 3177 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3178 | } |
| 3179 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3180 | transportType, aBoolean -> { |
| 3181 | try { |
| 3182 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3183 | } catch (RemoteException e) { |
| 3184 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3185 | + "running. Ignore"); |
| 3186 | } |
| 3187 | }); |
| 3188 | } finally { |
| 3189 | Binder.restoreCallingIdentity(token); |
| 3190 | } |
| 3191 | } |
| 3192 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3193 | @Override |
| 3194 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
| 3195 | enforceReadPrivilegedPermission("enforceReadPrivilegedPermission"); |
| 3196 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3197 | final long token = Binder.clearCallingIdentity(); |
| 3198 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3199 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3200 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3201 | } catch (ImsException e) { |
| 3202 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3203 | } finally { |
| 3204 | Binder.restoreCallingIdentity(token); |
| 3205 | } |
| 3206 | } |
| 3207 | |
| 3208 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3209 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3210 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3211 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3212 | final long identity = Binder.clearCallingIdentity(); |
| 3213 | try { |
| 3214 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3215 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3216 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3217 | } catch (ImsException e) { |
| 3218 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3219 | } finally { |
| 3220 | Binder.restoreCallingIdentity(identity); |
| 3221 | } |
| 3222 | } |
| 3223 | |
| 3224 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3225 | public boolean isVtSettingEnabled(int subId) { |
| 3226 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3227 | final long identity = Binder.clearCallingIdentity(); |
| 3228 | try { |
| 3229 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3230 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3231 | } catch (ImsException e) { |
| 3232 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3233 | } finally { |
| 3234 | Binder.restoreCallingIdentity(identity); |
| 3235 | } |
| 3236 | } |
| 3237 | |
| 3238 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3239 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3240 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3241 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3242 | final long identity = Binder.clearCallingIdentity(); |
| 3243 | try { |
| 3244 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3245 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3246 | } catch (ImsException e) { |
| 3247 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3248 | } finally { |
| 3249 | Binder.restoreCallingIdentity(identity); |
| 3250 | } |
| 3251 | } |
| 3252 | |
| 3253 | @Override |
| 3254 | public boolean isVoWiFiSettingEnabled(int subId) { |
| 3255 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 3256 | final long identity = Binder.clearCallingIdentity(); |
| 3257 | try { |
| 3258 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3259 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3260 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3261 | } catch (ImsException e) { |
| 3262 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3263 | } finally { |
| 3264 | Binder.restoreCallingIdentity(identity); |
| 3265 | } |
| 3266 | } |
| 3267 | |
| 3268 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3269 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3270 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3271 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3272 | final long identity = Binder.clearCallingIdentity(); |
| 3273 | try { |
| 3274 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3275 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3276 | } catch (ImsException e) { |
| 3277 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3278 | } finally { |
| 3279 | Binder.restoreCallingIdentity(identity); |
| 3280 | } |
| 3281 | } |
| 3282 | |
| 3283 | @Override |
| 3284 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
| 3285 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 3286 | final long identity = Binder.clearCallingIdentity(); |
| 3287 | try { |
| 3288 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3289 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3290 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3291 | } catch (ImsException e) { |
| 3292 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3293 | } finally { |
| 3294 | Binder.restoreCallingIdentity(identity); |
| 3295 | } |
| 3296 | } |
| 3297 | |
| 3298 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3299 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3300 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3301 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3302 | final long identity = Binder.clearCallingIdentity(); |
| 3303 | try { |
| 3304 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3305 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3306 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3307 | } catch (ImsException e) { |
| 3308 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3309 | } finally { |
| 3310 | Binder.restoreCallingIdentity(identity); |
| 3311 | } |
| 3312 | } |
| 3313 | |
| 3314 | @Override |
| 3315 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3316 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3317 | "setVoWiFiNonPersistent"); |
| 3318 | final long identity = Binder.clearCallingIdentity(); |
| 3319 | try { |
| 3320 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3321 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3322 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3323 | } catch (ImsException e) { |
| 3324 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3325 | } finally { |
| 3326 | Binder.restoreCallingIdentity(identity); |
| 3327 | } |
| 3328 | } |
| 3329 | |
| 3330 | @Override |
| 3331 | public int getVoWiFiModeSetting(int subId) { |
| 3332 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 3333 | final long identity = Binder.clearCallingIdentity(); |
| 3334 | try { |
| 3335 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3336 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3337 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3338 | } catch (ImsException e) { |
| 3339 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3340 | } finally { |
| 3341 | Binder.restoreCallingIdentity(identity); |
| 3342 | } |
| 3343 | } |
| 3344 | |
| 3345 | @Override |
| 3346 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3347 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3348 | "setVoWiFiModeSetting"); |
| 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 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3353 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
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 |
| 3362 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3363 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3364 | final long identity = Binder.clearCallingIdentity(); |
| 3365 | try { |
| 3366 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3367 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3368 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
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 | |
| 3376 | @Override |
| 3377 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3378 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3379 | "setVoWiFiRoamingModeSetting"); |
| 3380 | final long identity = Binder.clearCallingIdentity(); |
| 3381 | try { |
| 3382 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3383 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3384 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3385 | } catch (ImsException e) { |
| 3386 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3387 | } finally { |
| 3388 | Binder.restoreCallingIdentity(identity); |
| 3389 | } |
| 3390 | } |
| 3391 | |
| 3392 | @Override |
| 3393 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3394 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3395 | "setRttCapabilityEnabled"); |
| 3396 | final long identity = Binder.clearCallingIdentity(); |
| 3397 | try { |
| 3398 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3399 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3400 | } catch (ImsException e) { |
| 3401 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3402 | } finally { |
| 3403 | Binder.restoreCallingIdentity(identity); |
| 3404 | } |
| 3405 | } |
| 3406 | |
| 3407 | @Override |
| 3408 | public boolean isTtyOverVolteEnabled(int subId) { |
| 3409 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 3410 | final long identity = Binder.clearCallingIdentity(); |
| 3411 | try { |
| 3412 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3413 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3414 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3415 | } catch (ImsException e) { |
| 3416 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3417 | } finally { |
| 3418 | Binder.restoreCallingIdentity(identity); |
| 3419 | } |
| 3420 | } |
| 3421 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3422 | @Override |
| 3423 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3424 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3425 | final long identity = Binder.clearCallingIdentity(); |
| 3426 | try { |
| 3427 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3428 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3429 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3430 | } catch (ImsException e) { |
| 3431 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3432 | } finally { |
| 3433 | Binder.restoreCallingIdentity(identity); |
| 3434 | } |
| 3435 | } |
| 3436 | |
| 3437 | @Override |
| 3438 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3439 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3440 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3441 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3442 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3443 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3444 | try { |
| 3445 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3446 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3447 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3448 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3449 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3450 | + "is inactive, ignoring unregister."); |
| 3451 | // If the subscription is no longer active, just return, since the callback will already |
| 3452 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3453 | } finally { |
| 3454 | Binder.restoreCallingIdentity(identity); |
| 3455 | } |
| 3456 | } |
| 3457 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3458 | |
| 3459 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 3460 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3461 | message); |
| 3462 | } |
| 3463 | |
| 3464 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 3465 | boolean isMmtelCapability) { |
| 3466 | Phone phone = getPhone(subId); |
| 3467 | if (phone == null) { |
| 3468 | loge("phone instance null for subid " + subId); |
| 3469 | return false; |
| 3470 | } |
| 3471 | if (isMmtelCapability) { |
| 3472 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3473 | return false; |
| 3474 | } |
| 3475 | } else { |
| 3476 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3477 | return false; |
| 3478 | } |
| 3479 | } |
| 3480 | return true; |
| 3481 | } |
| 3482 | |
| 3483 | @Override |
| 3484 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 3485 | boolean isProvisioned) { |
| 3486 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 3487 | |
| 3488 | final long identity = Binder.clearCallingIdentity(); |
| 3489 | try { |
| 3490 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3491 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3492 | return; |
| 3493 | } |
| 3494 | |
| 3495 | // this capability requires provisioning, route to the correct API. |
| 3496 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3497 | switch (capability) { |
| 3498 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3499 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3500 | ims.setEabProvisioned(isProvisioned); |
| 3501 | break; |
| 3502 | default: { |
| 3503 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3504 | + "rcs capability '" + capability + "', which does not require " |
| 3505 | + "provisioning."); |
| 3506 | } |
| 3507 | } |
| 3508 | } finally { |
| 3509 | Binder.restoreCallingIdentity(identity); |
| 3510 | } |
| 3511 | |
| 3512 | } |
| 3513 | |
| 3514 | |
| 3515 | @Override |
| 3516 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 3517 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 3518 | final long identity = Binder.clearCallingIdentity(); |
| 3519 | try { |
| 3520 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3521 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3522 | return true; |
| 3523 | } |
| 3524 | |
| 3525 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3526 | switch (capability) { |
| 3527 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3528 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3529 | return ims.isEabProvisionedOnDevice(); |
| 3530 | |
| 3531 | default: { |
| 3532 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 3533 | + "capability '" + capability + "', which does not require " |
| 3534 | + "provisioning."); |
| 3535 | } |
| 3536 | } |
| 3537 | |
| 3538 | } finally { |
| 3539 | Binder.restoreCallingIdentity(identity); |
| 3540 | } |
| 3541 | } |
| 3542 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3543 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3544 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3545 | boolean isProvisioned) { |
| 3546 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3547 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3548 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3549 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3550 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3551 | final long identity = Binder.clearCallingIdentity(); |
| 3552 | try { |
| 3553 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3554 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3555 | return; |
| 3556 | } |
| 3557 | |
| 3558 | // this capability requires provisioning, route to the correct API. |
| 3559 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3560 | switch (capability) { |
| 3561 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3562 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3563 | ims.setVolteProvisioned(isProvisioned); |
| 3564 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3565 | ims.setWfcProvisioned(isProvisioned); |
| 3566 | } |
| 3567 | break; |
| 3568 | } |
| 3569 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3570 | // There is currently no difference in VT provisioning type. |
| 3571 | ims.setVtProvisioned(isProvisioned); |
| 3572 | break; |
| 3573 | } |
| 3574 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3575 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3576 | // change the capability of the feature instead if needed. |
| 3577 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3578 | == isProvisioned) { |
| 3579 | // No change in provisioning. |
| 3580 | return; |
| 3581 | } |
| 3582 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3583 | try { |
| 3584 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3585 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3586 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3587 | + ", Exception" + e.getMessage()); |
| 3588 | } |
| 3589 | break; |
| 3590 | } |
| 3591 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3592 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3593 | + "MmTel capability '" + capability + "', which does not require " |
| 3594 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3595 | } |
| 3596 | } |
| 3597 | |
| 3598 | } finally { |
| 3599 | Binder.restoreCallingIdentity(identity); |
| 3600 | } |
| 3601 | } |
| 3602 | |
| 3603 | @Override |
| 3604 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3605 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3606 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3607 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3608 | } |
| 3609 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3610 | final long identity = Binder.clearCallingIdentity(); |
| 3611 | try { |
| 3612 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3613 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3614 | return true; |
| 3615 | } |
| 3616 | |
| 3617 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3618 | switch (capability) { |
| 3619 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3620 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3621 | return ims.isVolteProvisionedOnDevice(); |
| 3622 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3623 | return ims.isWfcProvisionedOnDevice(); |
| 3624 | } |
| 3625 | // This should never happen, since we are checking tech above to make sure it |
| 3626 | // is either LTE or IWLAN. |
| 3627 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3628 | + "capability."); |
| 3629 | } |
| 3630 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3631 | // There is currently no difference in VT provisioning type. |
| 3632 | return ims.isVtProvisionedOnDevice(); |
| 3633 | } |
| 3634 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3635 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3636 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3637 | } |
| 3638 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3639 | throw new IllegalArgumentException( |
| 3640 | "Tried to get provisioning for MmTel capability '" + capability |
| 3641 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3642 | } |
| 3643 | } |
| 3644 | |
| 3645 | } finally { |
| 3646 | Binder.restoreCallingIdentity(identity); |
| 3647 | } |
| 3648 | } |
| 3649 | |
| 3650 | @Override |
| 3651 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3652 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3653 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3654 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3655 | } |
| 3656 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3657 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3658 | return (provisionedBits & capability) > 0; |
| 3659 | } |
| 3660 | |
| 3661 | @Override |
| 3662 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3663 | boolean isProvisioned) { |
| 3664 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3665 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3666 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3667 | } |
| 3668 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3669 | "setProvisioningStatusForCapability"); |
| 3670 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3671 | // If the current provisioning status for capability already matches isProvisioned, |
| 3672 | // do nothing. |
| 3673 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3674 | return; |
| 3675 | } |
| 3676 | if (isProvisioned) { |
| 3677 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3678 | } else { |
| 3679 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3680 | } |
| 3681 | } |
| 3682 | |
| 3683 | /** |
| 3684 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 3685 | * technology. The bitfield should mirror the bitfield defined by |
| 3686 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 3687 | */ |
| 3688 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 3689 | String key = getMmTelProvisioningKey(subId, tech); |
| 3690 | // Default is no capabilities are provisioned. |
| 3691 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 3692 | } |
| 3693 | |
| 3694 | /** |
| 3695 | * Sets the MmTel capability provisioning bitfield (defined by |
| 3696 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 3697 | * technology specified. |
| 3698 | * |
| 3699 | * Note: This is a synchronous command and should not be called on UI thread. |
| 3700 | */ |
| 3701 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 3702 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 3703 | String key = getMmTelProvisioningKey(subId, tech); |
| 3704 | editor.putInt(key, newField); |
| 3705 | editor.commit(); |
| 3706 | } |
| 3707 | |
| 3708 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 3709 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 3710 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 3711 | } |
| 3712 | |
| 3713 | /** |
| 3714 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 3715 | * carrier associated with the subscription id. |
| 3716 | */ |
| 3717 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 3718 | int capability) { |
| 3719 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 3720 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 3721 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 3722 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3723 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 3724 | false); |
| 3725 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 3726 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 3727 | |
| 3728 | // First check to make sure that the capability requires provisioning. |
| 3729 | switch (capability) { |
| 3730 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 3731 | // intentional fallthrough |
| 3732 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3733 | if (requireVoiceVtProvisioning) { |
| 3734 | // Voice and Video requires provisioning |
| 3735 | return true; |
| 3736 | } |
| 3737 | break; |
| 3738 | } |
| 3739 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3740 | if (requireUtProvisioning) { |
| 3741 | // UT requires provisioning |
| 3742 | return true; |
| 3743 | } |
| 3744 | break; |
| 3745 | } |
| 3746 | } |
| 3747 | return false; |
| 3748 | } |
| 3749 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3750 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 3751 | int capability) { |
| 3752 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 3753 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 3754 | |
| 3755 | boolean requireRcsProvisioning = c.getBoolean( |
| 3756 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 3757 | |
| 3758 | // First check to make sure that the capability requires provisioning. |
| 3759 | switch (capability) { |
| 3760 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3761 | // intentional fallthrough |
| 3762 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 3763 | if (requireRcsProvisioning) { |
| 3764 | // OPTION or PRESENCE requires provisioning |
| 3765 | return true; |
| 3766 | } |
| 3767 | break; |
| 3768 | } |
| 3769 | } |
| 3770 | return false; |
| 3771 | } |
| 3772 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3773 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3774 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3775 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3776 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3777 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3778 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 3779 | final long identity = Binder.clearCallingIdentity(); |
| 3780 | try { |
| 3781 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3782 | int slotId = getSlotIndex(subId); |
| 3783 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3784 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 3785 | + subId + "' for key:" + key); |
| 3786 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 3787 | } |
| 3788 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3789 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3790 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 3791 | + subId + "' for key:" + key); |
| 3792 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3793 | } finally { |
| 3794 | Binder.restoreCallingIdentity(identity); |
| 3795 | } |
| 3796 | } |
| 3797 | |
| 3798 | @Override |
| 3799 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3800 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3801 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3802 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3803 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 3804 | final long identity = Binder.clearCallingIdentity(); |
| 3805 | try { |
| 3806 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3807 | int slotId = getSlotIndex(subId); |
| 3808 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3809 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 3810 | + subId + "' for key:" + key); |
| 3811 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 3812 | } |
| 3813 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3814 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3815 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 3816 | + subId + "' for key:" + key); |
| 3817 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3818 | } finally { |
| 3819 | Binder.restoreCallingIdentity(identity); |
| 3820 | } |
| 3821 | } |
| 3822 | |
| 3823 | @Override |
| 3824 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3825 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3826 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3827 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3828 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3829 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3830 | final long identity = Binder.clearCallingIdentity(); |
| 3831 | try { |
| 3832 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3833 | int slotId = getSlotIndex(subId); |
| 3834 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3835 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 3836 | + subId + "' for key:" + key); |
| 3837 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3838 | } |
| 3839 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3840 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3841 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 3842 | + "' for key:" + key); |
| 3843 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3844 | } finally { |
| 3845 | Binder.restoreCallingIdentity(identity); |
| 3846 | } |
| 3847 | } |
| 3848 | |
| 3849 | @Override |
| 3850 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3851 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3852 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3853 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3854 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3855 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3856 | final long identity = Binder.clearCallingIdentity(); |
| 3857 | try { |
| 3858 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3859 | int slotId = getSlotIndex(subId); |
| 3860 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3861 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 3862 | + subId + "' for key:" + key); |
| 3863 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3864 | } |
| 3865 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3866 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3867 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 3868 | + "' for key:" + key); |
| 3869 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3870 | } finally { |
| 3871 | Binder.restoreCallingIdentity(identity); |
| 3872 | } |
| 3873 | } |
| 3874 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3875 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3876 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3877 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3878 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 3879 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3880 | } |
| 3881 | return slotId; |
| 3882 | } |
| 3883 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3884 | private int getSlotIndex(int subId) { |
| 3885 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 3886 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 3887 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 3888 | } |
| 3889 | return slotId; |
| 3890 | } |
| 3891 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3892 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 3893 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3894 | */ |
| 3895 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3896 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 3897 | String callingFeatureId) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 3898 | final int targetSdk = getTargetSdk(callingPackage); |
| 3899 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3900 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 3901 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 3902 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3903 | mApp, subId, callingPackage, callingFeatureId, |
| 3904 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3905 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3906 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3907 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3908 | final long identity = Binder.clearCallingIdentity(); |
| 3909 | try { |
| 3910 | final Phone phone = getPhone(subId); |
| 3911 | if (phone != null) { |
| 3912 | return phone.getServiceState().getDataNetworkType(); |
| 3913 | } else { |
| 3914 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3915 | } |
| 3916 | } finally { |
| 3917 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3918 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3919 | } |
| 3920 | |
| 3921 | /** |
| 3922 | * Returns the data network type |
| 3923 | */ |
| 3924 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3925 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 3926 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3927 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3928 | } |
| 3929 | |
| 3930 | /** |
| 3931 | * Returns the data network type for a subId |
| 3932 | */ |
| 3933 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3934 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 3935 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3936 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3937 | mApp, subId, callingPackage, callingFeatureId, |
| 3938 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3939 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3940 | } |
| 3941 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3942 | final long identity = Binder.clearCallingIdentity(); |
| 3943 | try { |
| 3944 | final Phone phone = getPhone(subId); |
| 3945 | if (phone != null) { |
| 3946 | return phone.getServiceState().getDataNetworkType(); |
| 3947 | } else { |
| 3948 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3949 | } |
| 3950 | } finally { |
| 3951 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3952 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3953 | } |
| 3954 | |
| 3955 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3956 | * Returns the Voice network type for a subId |
| 3957 | */ |
| 3958 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3959 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 3960 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3961 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3962 | mApp, subId, callingPackage, callingFeatureId, |
| 3963 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 3964 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3965 | } |
| 3966 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3967 | final long identity = Binder.clearCallingIdentity(); |
| 3968 | try { |
| 3969 | final Phone phone = getPhone(subId); |
| 3970 | if (phone != null) { |
| 3971 | return phone.getServiceState().getVoiceNetworkType(); |
| 3972 | } else { |
| 3973 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 3974 | } |
| 3975 | } finally { |
| 3976 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3977 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3978 | } |
| 3979 | |
| 3980 | /** |
| 3981 | * @return true if a ICC card is present |
| 3982 | */ |
| 3983 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3984 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3985 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 3986 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3987 | } |
| 3988 | |
| 3989 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3990 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3991 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3992 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3993 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3994 | final long identity = Binder.clearCallingIdentity(); |
| 3995 | try { |
| 3996 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3997 | if (phone != null) { |
| 3998 | return phone.getIccCard().hasIccCard(); |
| 3999 | } else { |
| 4000 | return false; |
| 4001 | } |
| 4002 | } finally { |
| 4003 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4004 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4005 | } |
| 4006 | |
| 4007 | /** |
| 4008 | * Return if the current radio is LTE on CDMA. This |
| 4009 | * is a tri-state return value as for a period of time |
| 4010 | * the mode may be unknown. |
| 4011 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4012 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4013 | * @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] | 4014 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4015 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4016 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4017 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4018 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4019 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4020 | } |
| 4021 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4022 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4023 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4024 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4025 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4026 | mApp, subId, callingPackage, callingFeatureId, |
| 4027 | "getLteOnCdmaModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4028 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4029 | } |
| 4030 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4031 | final long identity = Binder.clearCallingIdentity(); |
| 4032 | try { |
| 4033 | final Phone phone = getPhone(subId); |
| 4034 | if (phone == null) { |
| 4035 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4036 | } else { |
| 4037 | return phone.getLteOnCdmaMode(); |
| 4038 | } |
| 4039 | } finally { |
| 4040 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4041 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4042 | } |
| 4043 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4044 | /** |
| 4045 | * {@hide} |
| 4046 | * Returns Default subId, 0 in the case of single standby. |
| 4047 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4048 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4049 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4050 | } |
| 4051 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4052 | private int getSlotForDefaultSubscription() { |
| 4053 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4054 | } |
| 4055 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4056 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4057 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4058 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4059 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4060 | private boolean isActiveSubscription(int subId) { |
| 4061 | return mSubscriptionController.isActiveSubId(subId); |
| 4062 | } |
| 4063 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4064 | /** |
| 4065 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4066 | */ |
| 4067 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4068 | final long identity = Binder.clearCallingIdentity(); |
| 4069 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4070 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4071 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4072 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4073 | } finally { |
| 4074 | Binder.restoreCallingIdentity(identity); |
| 4075 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4076 | } |
| 4077 | |
| 4078 | /** |
| 4079 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4080 | */ |
| 4081 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4082 | final long identity = Binder.clearCallingIdentity(); |
| 4083 | try { |
| 4084 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4085 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4086 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4087 | } finally { |
| 4088 | Binder.restoreCallingIdentity(identity); |
| 4089 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4090 | } |
| 4091 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4092 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4093 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4094 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4095 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4096 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4097 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4098 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4099 | if (phoneId == -1) { |
| 4100 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4101 | + " does not correspond to an active phone"); |
| 4102 | } |
| 4103 | return PhoneFactory.getPhone(phoneId); |
| 4104 | } |
| 4105 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4106 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4107 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4108 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4109 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4110 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4111 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4112 | if (DBG) { |
| 4113 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4114 | } |
| 4115 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4116 | p2); |
| 4117 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4118 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4119 | |
| 4120 | @Override |
| 4121 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4122 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4123 | enforceModifyPermission(); |
| 4124 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4125 | if (DBG) { |
| 4126 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4127 | } |
| 4128 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4129 | callingPackage, aid, p2); |
| 4130 | } |
| 4131 | |
| 4132 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4133 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4134 | final long identity = Binder.clearCallingIdentity(); |
| 4135 | try { |
| 4136 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4137 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4138 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4139 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4140 | if (bestComponent == null |
| 4141 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4142 | loge("The calling package is not allowed to access ISD-R."); |
| 4143 | throw new SecurityException( |
| 4144 | "The calling package is not allowed to access ISD-R."); |
| 4145 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4146 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4147 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4148 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4149 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4150 | null /* workSource */); |
| 4151 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4152 | return response; |
| 4153 | } finally { |
| 4154 | Binder.restoreCallingIdentity(identity); |
| 4155 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4156 | } |
| 4157 | |
| 4158 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4159 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4160 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4161 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4162 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4163 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4164 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4165 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4166 | @Override |
| 4167 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4168 | enforceModifyPermission(); |
| 4169 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4170 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4171 | channel); |
| 4172 | } |
| 4173 | |
| 4174 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4175 | final long identity = Binder.clearCallingIdentity(); |
| 4176 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4177 | if (channel < 0) { |
| 4178 | return false; |
| 4179 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4180 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4181 | null /* workSource */); |
| 4182 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4183 | return success; |
| 4184 | } finally { |
| 4185 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4186 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4187 | } |
| 4188 | |
| 4189 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4190 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4191 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4192 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4193 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4194 | if (DBG) { |
| 4195 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4196 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4197 | + p3 + " data=" + data); |
| 4198 | } |
| 4199 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4200 | command, p1, p2, p3, data); |
| 4201 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4202 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4203 | @Override |
| 4204 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4205 | int command, int p1, int p2, int p3, String data) { |
| 4206 | enforceModifyPermission(); |
| 4207 | if (DBG) { |
| 4208 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4209 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4210 | + p3 + " data=" + data); |
| 4211 | } |
| 4212 | return iccTransmitApduLogicalChannelWithPermission( |
| 4213 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4214 | data); |
| 4215 | } |
| 4216 | |
| 4217 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4218 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4219 | final long identity = Binder.clearCallingIdentity(); |
| 4220 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4221 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4222 | return ""; |
| 4223 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4224 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4225 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4226 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4227 | null /* workSource */); |
| 4228 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4229 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4230 | // Append the returned status code to the end of the response payload. |
| 4231 | String s = Integer.toHexString( |
| 4232 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4233 | if (response.payload != null) { |
| 4234 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4235 | } |
| 4236 | return s; |
| 4237 | } finally { |
| 4238 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4239 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4240 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4241 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4242 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4243 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4244 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4245 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4246 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4247 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4248 | if (DBG) { |
| 4249 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4250 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4251 | } |
| 4252 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4253 | cla, command, p1, p2, p3, data); |
| 4254 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4255 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4256 | @Override |
| 4257 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4258 | int command, int p1, int p2, int p3, String data) { |
| 4259 | enforceModifyPermission(); |
| 4260 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4261 | if (DBG) { |
| 4262 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4263 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4264 | + " data=" + data); |
| 4265 | } |
| 4266 | |
| 4267 | return iccTransmitApduBasicChannelWithPermission( |
| 4268 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4269 | p2, p3, data); |
| 4270 | } |
| 4271 | |
| 4272 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4273 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4274 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4275 | final long identity = Binder.clearCallingIdentity(); |
| 4276 | try { |
| 4277 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4278 | && TextUtils.equals(ISDR_AID, data)) { |
| 4279 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4280 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4281 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4282 | if (bestComponent == null |
| 4283 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4284 | loge("The calling package is not allowed to select ISD-R."); |
| 4285 | throw new SecurityException( |
| 4286 | "The calling package is not allowed to select ISD-R."); |
| 4287 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4288 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4289 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4290 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4291 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4292 | null /* workSource */); |
| 4293 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4294 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4295 | // Append the returned status code to the end of the response payload. |
| 4296 | String s = Integer.toHexString( |
| 4297 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4298 | if (response.payload != null) { |
| 4299 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4300 | } |
| 4301 | return s; |
| 4302 | } finally { |
| 4303 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4304 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4305 | } |
| 4306 | |
| 4307 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4308 | 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] | 4309 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4310 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4311 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4312 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4313 | final long identity = Binder.clearCallingIdentity(); |
| 4314 | try { |
| 4315 | if (DBG) { |
| 4316 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4317 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4318 | } |
| 4319 | |
| 4320 | IccIoResult response = |
| 4321 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4322 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4323 | subId); |
| 4324 | |
| 4325 | if (DBG) { |
| 4326 | log("Exchange SIM_IO [R]" + response); |
| 4327 | } |
| 4328 | |
| 4329 | byte[] result = null; |
| 4330 | int length = 2; |
| 4331 | if (response.payload != null) { |
| 4332 | length = 2 + response.payload.length; |
| 4333 | result = new byte[length]; |
| 4334 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4335 | } else { |
| 4336 | result = new byte[length]; |
| 4337 | } |
| 4338 | |
| 4339 | result[length - 1] = (byte) response.sw2; |
| 4340 | result[length - 2] = (byte) response.sw1; |
| 4341 | return result; |
| 4342 | } finally { |
| 4343 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4344 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4345 | } |
| 4346 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4347 | /** |
| 4348 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4349 | * on a particular subscription |
| 4350 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4351 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 4352 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4353 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4354 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4355 | return null; |
| 4356 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4357 | |
| 4358 | final long identity = Binder.clearCallingIdentity(); |
| 4359 | try { |
| 4360 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4361 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4362 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4363 | return null; |
| 4364 | } |
| 4365 | Object response = sendRequest( |
| 4366 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4367 | if (response instanceof String[]) { |
| 4368 | return (String[]) response; |
| 4369 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4370 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4371 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4372 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4373 | } finally { |
| 4374 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4375 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4376 | } |
| 4377 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4378 | /** |
| 4379 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 4380 | * subscription. |
| 4381 | * |
| 4382 | * @param subId the id of the subscription. |
| 4383 | * @param appType the uicc app type, must be USIM or SIM. |
| 4384 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 4385 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4386 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4387 | * @return number of fplmns that is successfully written to the SIM. |
| 4388 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4389 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 4390 | String callingFeatureId) { |
| 4391 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 4392 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4393 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 4394 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 4395 | } |
| 4396 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 4397 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4398 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 4399 | } |
| 4400 | if (fplmns == null) { |
| 4401 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 4402 | } |
| 4403 | for (String fplmn : fplmns) { |
| 4404 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 4405 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 4406 | } |
| 4407 | } |
| 4408 | final long identity = Binder.clearCallingIdentity(); |
| 4409 | try { |
| 4410 | Object response = sendRequest( |
| 4411 | CMD_SET_FORBIDDEN_PLMNS, |
| 4412 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 4413 | subId); |
| 4414 | return (int) response; |
| 4415 | } finally { |
| 4416 | Binder.restoreCallingIdentity(identity); |
| 4417 | } |
| 4418 | } |
| 4419 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4420 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4421 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4422 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4423 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -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 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4428 | if (response.payload == null) { |
| 4429 | return ""; |
| 4430 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4431 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4432 | // Append the returned status code to the end of the response payload. |
| 4433 | String s = Integer.toHexString( |
| 4434 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4435 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4436 | return s; |
| 4437 | } finally { |
| 4438 | Binder.restoreCallingIdentity(identity); |
| 4439 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4440 | } |
| 4441 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4442 | /** |
| 4443 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4444 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4445 | * |
| 4446 | * @param itemID the ID of the item to read |
| 4447 | * @return the NV item as a String, or null on error. |
| 4448 | */ |
| 4449 | @Override |
| 4450 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4451 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4452 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4453 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4454 | |
| 4455 | final long identity = Binder.clearCallingIdentity(); |
| 4456 | try { |
| 4457 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4458 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4459 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4460 | return value; |
| 4461 | } finally { |
| 4462 | Binder.restoreCallingIdentity(identity); |
| 4463 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4464 | } |
| 4465 | |
| 4466 | /** |
| 4467 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4468 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4469 | * |
| 4470 | * @param itemID the ID of the item to read |
| 4471 | * @param itemValue the value to write, as a String |
| 4472 | * @return true on success; false on any failure |
| 4473 | */ |
| 4474 | @Override |
| 4475 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4476 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4477 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4478 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4479 | |
| 4480 | final long identity = Binder.clearCallingIdentity(); |
| 4481 | try { |
| 4482 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4483 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4484 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4485 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4486 | return success; |
| 4487 | } finally { |
| 4488 | Binder.restoreCallingIdentity(identity); |
| 4489 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4490 | } |
| 4491 | |
| 4492 | /** |
| 4493 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4494 | * Used for device configuration by some CDMA operators. |
| 4495 | * |
| 4496 | * @param preferredRoamingList byte array containing the new PRL |
| 4497 | * @return true on success; false on any failure |
| 4498 | */ |
| 4499 | @Override |
| 4500 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4501 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4502 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4503 | |
| 4504 | final long identity = Binder.clearCallingIdentity(); |
| 4505 | try { |
| 4506 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4507 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4508 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4509 | return success; |
| 4510 | } finally { |
| 4511 | Binder.restoreCallingIdentity(identity); |
| 4512 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4513 | } |
| 4514 | |
| 4515 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4516 | * 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] | 4517 | * Used for device configuration by some CDMA operators. |
| 4518 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4519 | * @param slotIndex - device slot. |
| 4520 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4521 | * @return true on success; false on any failure |
| 4522 | */ |
| 4523 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4524 | public boolean resetModemConfig(int slotIndex) { |
| 4525 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4526 | if (phone != null) { |
| 4527 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4528 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4529 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4530 | final long identity = Binder.clearCallingIdentity(); |
| 4531 | try { |
| 4532 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4533 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4534 | return success; |
| 4535 | } finally { |
| 4536 | Binder.restoreCallingIdentity(identity); |
| 4537 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4538 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4539 | return false; |
| 4540 | } |
| 4541 | |
| 4542 | /** |
| 4543 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4544 | * |
| 4545 | * @param slotIndex - device slot. |
| 4546 | * |
| 4547 | * @return true on success; false on any failure |
| 4548 | */ |
| 4549 | @Override |
| 4550 | public boolean rebootModem(int slotIndex) { |
| 4551 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4552 | if (phone != null) { |
| 4553 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4554 | mApp, phone.getSubId(), "rebootModem"); |
| 4555 | |
| 4556 | final long identity = Binder.clearCallingIdentity(); |
| 4557 | try { |
| 4558 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4559 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4560 | return success; |
| 4561 | } finally { |
| 4562 | Binder.restoreCallingIdentity(identity); |
| 4563 | } |
| 4564 | } |
| 4565 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4566 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4567 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4568 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 4569 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4570 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4571 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4572 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4573 | return new String[0]; |
| 4574 | } |
| 4575 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4576 | final long identity = Binder.clearCallingIdentity(); |
| 4577 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4578 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4579 | } finally { |
| 4580 | Binder.restoreCallingIdentity(identity); |
| 4581 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4582 | } |
| 4583 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4584 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4585 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4586 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4587 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4588 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4589 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4590 | |
| 4591 | final long identity = Binder.clearCallingIdentity(); |
| 4592 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4593 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4594 | // may happen if the device does not support IMS. |
| 4595 | return; |
| 4596 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4597 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4598 | } finally { |
| 4599 | Binder.restoreCallingIdentity(identity); |
| 4600 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4601 | } |
| 4602 | |
| 4603 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4604 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4605 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4606 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4607 | public void disableIms(int slotId) { |
| 4608 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4609 | |
| 4610 | final long identity = Binder.clearCallingIdentity(); |
| 4611 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4612 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4613 | // may happen if the device does not support IMS. |
| 4614 | return; |
| 4615 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4616 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4617 | } finally { |
| 4618 | Binder.restoreCallingIdentity(identity); |
| 4619 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4620 | } |
| 4621 | |
| 4622 | /** |
| 4623 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4624 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4625 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4626 | */ |
| 4627 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4628 | IImsServiceFeatureCallback callback) { |
| 4629 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4630 | |
| 4631 | final long identity = Binder.clearCallingIdentity(); |
| 4632 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4633 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4634 | // may happen if the device does not support IMS. |
| 4635 | return null; |
| 4636 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4637 | return mImsResolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4638 | } finally { |
| 4639 | Binder.restoreCallingIdentity(identity); |
| 4640 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4641 | } |
| 4642 | |
| 4643 | /** |
| 4644 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4645 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4646 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4647 | * listener for feature updates. |
| 4648 | */ |
| 4649 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4650 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4651 | |
| 4652 | final long identity = Binder.clearCallingIdentity(); |
| 4653 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4654 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4655 | // may happen if the device does not support IMS. |
| 4656 | return null; |
| 4657 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4658 | return mImsResolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4659 | } finally { |
| 4660 | Binder.restoreCallingIdentity(identity); |
| 4661 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4662 | } |
| 4663 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4664 | /** |
| 4665 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4666 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4667 | */ |
| 4668 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 4669 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4670 | |
| 4671 | final long identity = Binder.clearCallingIdentity(); |
| 4672 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4673 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4674 | // may happen if the device does not support IMS. |
| 4675 | return null; |
| 4676 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4677 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4678 | } finally { |
| 4679 | Binder.restoreCallingIdentity(identity); |
| 4680 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4681 | } |
| 4682 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4683 | /** |
| 4684 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4685 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4686 | */ |
| 4687 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 4688 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4689 | |
| 4690 | final long identity = Binder.clearCallingIdentity(); |
| 4691 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4692 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4693 | // may happen if the device does not support IMS. |
| 4694 | return null; |
| 4695 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4696 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4697 | } finally { |
| 4698 | Binder.restoreCallingIdentity(identity); |
| 4699 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4700 | } |
| 4701 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 4702 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4703 | * Sets the ImsService Package Name that Telephony will bind to. |
| 4704 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4705 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 4706 | * @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] | 4707 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4708 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 4709 | * @param packageName The name of the package that the current configuration will be replaced |
| 4710 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4711 | * @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] | 4712 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4713 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 4714 | int[] featureTypes, String packageName) { |
| 4715 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 4716 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4717 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4718 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4719 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4720 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4721 | final long identity = Binder.clearCallingIdentity(); |
| 4722 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4723 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4724 | // may happen if the device does not support IMS. |
| 4725 | return false; |
| 4726 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4727 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 4728 | for (int featureType : featureTypes) { |
| 4729 | featureConfig.put(featureType, packageName); |
| 4730 | } |
| 4731 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 4732 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4733 | } finally { |
| 4734 | Binder.restoreCallingIdentity(identity); |
| 4735 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4736 | } |
| 4737 | |
| 4738 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4739 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4740 | * |
| 4741 | * @param slotId The slot that the ImsService is associated with. |
| 4742 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 4743 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4744 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4745 | * @return the package name of the ImsService configuration. |
| 4746 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4747 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 4748 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4749 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4750 | TelephonyPermissions |
| 4751 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4752 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4753 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4754 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4755 | final long identity = Binder.clearCallingIdentity(); |
| 4756 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4757 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4758 | // may happen if the device does not support IMS. |
| 4759 | return ""; |
| 4760 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 4761 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4762 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 4763 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4764 | } finally { |
| 4765 | Binder.restoreCallingIdentity(identity); |
| 4766 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4767 | } |
| 4768 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4769 | /** |
| 4770 | * Get the MmTelFeature state associated with the requested subscription id. |
| 4771 | * @param subId The subscription that the MmTelFeature is associated with. |
| 4772 | * @param callback A callback with an integer containing the |
| 4773 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 4774 | */ |
| 4775 | @Override |
| 4776 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 4777 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 4778 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4779 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4780 | "IMS not available on device."); |
| 4781 | } |
| 4782 | final long token = Binder.clearCallingIdentity(); |
| 4783 | try { |
| 4784 | int slotId = getSlotIndex(subId); |
| 4785 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4786 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 4787 | + subId + "'"); |
| 4788 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4789 | } |
| 4790 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 4791 | try { |
| 4792 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 4793 | } catch (RemoteException e) { |
| 4794 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 4795 | + "Ignore"); |
| 4796 | } |
| 4797 | }); |
| 4798 | } finally { |
| 4799 | Binder.restoreCallingIdentity(token); |
| 4800 | } |
| 4801 | } |
| 4802 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4803 | public void setImsRegistrationState(boolean registered) { |
| 4804 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4805 | |
| 4806 | final long identity = Binder.clearCallingIdentity(); |
| 4807 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4808 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4809 | } finally { |
| 4810 | Binder.restoreCallingIdentity(identity); |
| 4811 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4812 | } |
| 4813 | |
| 4814 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4815 | * Set the network selection mode to automatic. |
| 4816 | * |
| 4817 | */ |
| 4818 | @Override |
| 4819 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4820 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4821 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4822 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4823 | if (!isActiveSubscription(subId)) { |
| 4824 | return; |
| 4825 | } |
| 4826 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4827 | final long identity = Binder.clearCallingIdentity(); |
| 4828 | try { |
| 4829 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 4830 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 4831 | } finally { |
| 4832 | Binder.restoreCallingIdentity(identity); |
| 4833 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4834 | } |
| 4835 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4836 | /** |
| 4837 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 4838 | * |
| 4839 | * @param subId the id of the subscription. |
| 4840 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 4841 | * the operator to attach to. |
| 4842 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 4843 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 4844 | * normal network selection next time. |
| 4845 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4846 | */ |
| 4847 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4848 | public boolean setNetworkSelectionModeManual( |
| 4849 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4850 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4851 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4852 | |
| 4853 | if (!isActiveSubscription(subId)) { |
| 4854 | return false; |
| 4855 | } |
| 4856 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4857 | final long identity = Binder.clearCallingIdentity(); |
| 4858 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4859 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4860 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4861 | if (DBG) { |
| 4862 | log("setNetworkSelectionModeManual: subId: " + subId |
| 4863 | + " operator: " + operatorInfo); |
| 4864 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4865 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 4866 | } finally { |
| 4867 | Binder.restoreCallingIdentity(identity); |
| 4868 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4869 | } |
| 4870 | |
| 4871 | /** |
| 4872 | * Scans for available networks. |
| 4873 | */ |
| 4874 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 4875 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 4876 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4877 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4878 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4879 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4880 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4881 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4882 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 4883 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4884 | .setCallingPid(Binder.getCallingPid()) |
| 4885 | .setCallingUid(Binder.getCallingUid()) |
| 4886 | .setMethod("getCellNetworkScanResults") |
| 4887 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4888 | .build()); |
| 4889 | switch (locationResult) { |
| 4890 | case DENIED_HARD: |
| 4891 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 4892 | case DENIED_SOFT: |
| 4893 | return null; |
| 4894 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4895 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4896 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4897 | try { |
| 4898 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 4899 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4900 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4901 | } finally { |
| 4902 | Binder.restoreCallingIdentity(identity); |
| 4903 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4904 | } |
| 4905 | |
| 4906 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4907 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4908 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4909 | * @param subId id of the subscription |
| 4910 | * @param request contains the radio access networks with bands/channels to scan |
| 4911 | * @param messenger callback messenger for scan results or errors |
| 4912 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4913 | * @return the id of the requested scan which can be used to stop the scan. |
| 4914 | */ |
| 4915 | @Override |
| 4916 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 4917 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4918 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4919 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4920 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 4921 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 4922 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 4923 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 4924 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 4925 | .setCallingPid(Binder.getCallingPid()) |
| 4926 | .setCallingUid(Binder.getCallingUid()) |
| 4927 | .setMethod("requestNetworkScan") |
| 4928 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 4929 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4930 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 4931 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4932 | if (e != null) { |
| 4933 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 4934 | throw e; |
| 4935 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 4936 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4937 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 4938 | } |
| 4939 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4940 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4941 | int callingUid = Binder.getCallingUid(); |
| 4942 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 4943 | final long identity = Binder.clearCallingIdentity(); |
| 4944 | try { |
| 4945 | return mNetworkScanRequestTracker.startNetworkScan( |
| 4946 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4947 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 4948 | } finally { |
| 4949 | Binder.restoreCallingIdentity(identity); |
| 4950 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4951 | } |
| 4952 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4953 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 4954 | NetworkScanRequest request, int subId) { |
| 4955 | boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid()) |
| 4956 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 4957 | boolean hasNetworkScanPermission = |
| 4958 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 4959 | == PERMISSION_GRANTED; |
| 4960 | |
| 4961 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 4962 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 4963 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4964 | } |
| 4965 | |
| 4966 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 4967 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4968 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 4969 | return new SecurityException("Specific channels must not be" |
| 4970 | + " scanned without location access."); |
| 4971 | } |
| 4972 | } |
| 4973 | } |
| 4974 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 4975 | return null; |
| 4976 | } |
| 4977 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4978 | /** |
| 4979 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 4980 | * |
| 4981 | * @param subId id of the subscription |
| 4982 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4983 | */ |
| 4984 | @Override |
| 4985 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4986 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4987 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4988 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4989 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4990 | final long identity = Binder.clearCallingIdentity(); |
| 4991 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 4992 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4993 | } finally { |
| 4994 | Binder.restoreCallingIdentity(identity); |
| 4995 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 4996 | } |
| 4997 | |
| 4998 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 4999 | * Get the calculated preferred network type. |
| 5000 | * Used for debugging incorrect network type. |
| 5001 | * |
| 5002 | * @return the preferred network type, defined in RILConstants.java. |
| 5003 | */ |
| 5004 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5005 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5006 | final Phone defaultPhone = getDefaultPhone(); |
| 5007 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5008 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5009 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5010 | } |
| 5011 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5012 | final long identity = Binder.clearCallingIdentity(); |
| 5013 | try { |
| 5014 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5015 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5016 | } finally { |
| 5017 | Binder.restoreCallingIdentity(identity); |
| 5018 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5019 | } |
| 5020 | |
| 5021 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5022 | * Get the preferred network type. |
| 5023 | * Used for device configuration by some CDMA operators. |
| 5024 | * |
| 5025 | * @return the preferred network type, defined in RILConstants.java. |
| 5026 | */ |
| 5027 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5028 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5029 | TelephonyPermissions |
| 5030 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5031 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5032 | |
| 5033 | final long identity = Binder.clearCallingIdentity(); |
| 5034 | try { |
| 5035 | if (DBG) log("getPreferredNetworkType"); |
| 5036 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5037 | int networkType = (result != null ? result[0] : -1); |
| 5038 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5039 | return networkType; |
| 5040 | } finally { |
| 5041 | Binder.restoreCallingIdentity(identity); |
| 5042 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5043 | } |
| 5044 | |
| 5045 | /** |
| 5046 | * Set the preferred network type. |
| 5047 | * Used for device configuration by some CDMA operators. |
| 5048 | * |
| 5049 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5050 | * @return true on success; false on any failure. |
| 5051 | */ |
| 5052 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5053 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5054 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5055 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5056 | |
| 5057 | final long identity = Binder.clearCallingIdentity(); |
| 5058 | try { |
| 5059 | if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType); |
| 5060 | Boolean success = (Boolean) sendRequest( |
| 5061 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 5062 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 5063 | if (success) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5064 | Settings.Global.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5065 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 5066 | } |
| 5067 | return success; |
| 5068 | } finally { |
| 5069 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5070 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5071 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5072 | |
| 5073 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5074 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5075 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5076 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 5077 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5078 | * @hide |
| 5079 | */ |
| 5080 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 5081 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5082 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5083 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5084 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5085 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5086 | if (phone != null) { |
| 5087 | return phone.hasMatchedTetherApnSetting(); |
| 5088 | } else { |
| 5089 | return false; |
| 5090 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5091 | } finally { |
| 5092 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5093 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5094 | } |
| 5095 | |
| 5096 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5097 | * Set mobile data enabled |
| 5098 | * Used by the user through settings etc to turn on/off mobile data |
| 5099 | * |
| 5100 | * @param enable {@code true} turn turn data on, else {@code false} |
| 5101 | */ |
| 5102 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5103 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5104 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5105 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5106 | |
| 5107 | final long identity = Binder.clearCallingIdentity(); |
| 5108 | try { |
| 5109 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5110 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5111 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5112 | if (phone != null) { |
| 5113 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5114 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5115 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5116 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5117 | } |
| 5118 | } finally { |
| 5119 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5120 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5121 | } |
| 5122 | |
| 5123 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5124 | * Get the user enabled state of Mobile Data. |
| 5125 | * |
| 5126 | * TODO: remove and use isUserDataEnabled. |
| 5127 | * This can't be removed now because some vendor codes |
| 5128 | * calls through ITelephony directly while they should |
| 5129 | * use TelephonyManager. |
| 5130 | * |
| 5131 | * @return true on enabled |
| 5132 | */ |
| 5133 | @Override |
| 5134 | public boolean getDataEnabled(int subId) { |
| 5135 | return isUserDataEnabled(subId); |
| 5136 | } |
| 5137 | |
| 5138 | /** |
| 5139 | * Get whether mobile data is enabled per user setting. |
| 5140 | * |
| 5141 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 5142 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5143 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 5144 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5145 | * |
| 5146 | * @return {@code true} if data is enabled else {@code false} |
| 5147 | */ |
| 5148 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5149 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5150 | try { |
| 5151 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 5152 | null); |
| 5153 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5154 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5155 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5156 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5157 | |
| 5158 | final long identity = Binder.clearCallingIdentity(); |
| 5159 | try { |
| 5160 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5161 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5162 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5163 | if (phone != null) { |
| 5164 | boolean retVal = phone.isUserDataEnabled(); |
| 5165 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5166 | return retVal; |
| 5167 | } else { |
| 5168 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5169 | return false; |
| 5170 | } |
| 5171 | } finally { |
| 5172 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5173 | } |
| 5174 | } |
| 5175 | |
| 5176 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5177 | * Checks if the device is capable of mobile data by considering whether whether the |
| 5178 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 5179 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5180 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5181 | * @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] | 5182 | */ |
| 5183 | @Override |
| 5184 | public boolean isDataEnabled(int subId) { |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5185 | enforceReadPrivilegedPermission("isDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5186 | |
| 5187 | final long identity = Binder.clearCallingIdentity(); |
| 5188 | try { |
| 5189 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5190 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5191 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5192 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5193 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5194 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5195 | return retVal; |
| 5196 | } else { |
| 5197 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5198 | return false; |
| 5199 | } |
| 5200 | } finally { |
| 5201 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5202 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5203 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5204 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5205 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, |
| 5206 | Phone phone) { |
| 5207 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5208 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5209 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5210 | || subController == null) return privilegeFromSim; |
| 5211 | |
| 5212 | int uid = Binder.getCallingUid(); |
| 5213 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 5214 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 5215 | |
| 5216 | final long identity = Binder.clearCallingIdentity(); |
| 5217 | try { |
| 5218 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5219 | SubscriptionManager subManager = (SubscriptionManager) |
| 5220 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5221 | for (String pkg : packages) { |
| 5222 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 5223 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5224 | } |
| 5225 | } |
| 5226 | return privilegeFromSim; |
| 5227 | } finally { |
| 5228 | Binder.restoreCallingIdentity(identity); |
| 5229 | } |
| 5230 | } |
| 5231 | |
| 5232 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 5233 | String pkgName) { |
| 5234 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5235 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5236 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5237 | || subController == null) return privilegeFromSim; |
| 5238 | |
| 5239 | final long identity = Binder.clearCallingIdentity(); |
| 5240 | try { |
| 5241 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5242 | SubscriptionManager subManager = (SubscriptionManager) |
| 5243 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5244 | return subManager.canManageSubscription(subInfo, pkgName) |
| 5245 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 5246 | } finally { |
| 5247 | Binder.restoreCallingIdentity(identity); |
| 5248 | } |
| 5249 | } |
| 5250 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5251 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5252 | public int getCarrierPrivilegeStatus(int subId) { |
| 5253 | final Phone phone = getPhone(subId); |
| 5254 | if (phone == null) { |
| 5255 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 5256 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5257 | } |
| 5258 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5259 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 5260 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5261 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5262 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5263 | |
| 5264 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5265 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
| 5266 | phone.getContext().getPackageManager()), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5267 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5268 | |
| 5269 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5270 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5271 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5272 | final Phone phone = getPhone(subId); |
| 5273 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5274 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5275 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5276 | } |
| 5277 | UiccProfile profile = |
| 5278 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 5279 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5280 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5281 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5282 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5283 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5284 | profile.getCarrierPrivilegeStatusForUid( |
| 5285 | phone.getContext().getPackageManager(), uid), phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5286 | } |
| 5287 | |
| 5288 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5289 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 5290 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5291 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5292 | } |
| 5293 | |
| 5294 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 5295 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5296 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5297 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5298 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5299 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5300 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5301 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5302 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5303 | } |
| 5304 | |
| 5305 | @Override |
| 5306 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5307 | if (TextUtils.isEmpty(pkgName)) |
| 5308 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5309 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5310 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5311 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 5312 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 5313 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5314 | continue; |
| 5315 | } |
| 5316 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5317 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5318 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5319 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5320 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 5321 | break; |
| 5322 | } |
| 5323 | } |
| 5324 | |
| 5325 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5326 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 5327 | |
| 5328 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 5329 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 5330 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 5331 | loge("phoneId " + phoneId + " is not valid."); |
| 5332 | return null; |
| 5333 | } |
| 5334 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5335 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5336 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5337 | return null ; |
| 5338 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5339 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5340 | } |
| 5341 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5342 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5343 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5344 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5345 | List<String> privilegedPackages = new ArrayList<>(); |
| 5346 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5347 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 5348 | // has UICC in that slot. |
| 5349 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5350 | if (card.hasCarrierPrivilegeRules()) { |
| 5351 | if (packages == null) { |
| 5352 | // Only check packages in user 0 for now |
| 5353 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5354 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 5355 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 5356 | | PackageManager.GET_SIGNING_CERTIFICATES, |
| 5357 | UserHandle.USER_SYSTEM); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5358 | } |
| 5359 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 5360 | PackageInfo pkgInfo = packages.get(p); |
| 5361 | if (pkgInfo != null && pkgInfo.packageName != null |
| 5362 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5363 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5364 | privilegedPackages.add(pkgInfo.packageName); |
| 5365 | } |
| 5366 | } |
| 5367 | } |
| 5368 | } |
| 5369 | return privilegedPackages; |
| 5370 | } |
| 5371 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5372 | @Override |
| 5373 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5374 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 5375 | |
| 5376 | final long identity = Binder.clearCallingIdentity(); |
| 5377 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5378 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5379 | try { |
| 5380 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5381 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 5382 | } |
| 5383 | } finally { |
| 5384 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5385 | } |
| 5386 | return privilegedPackages; |
| 5387 | } |
| 5388 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5389 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5390 | final Phone phone = getPhone(subId); |
| 5391 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5392 | if (card == null) { |
| 5393 | loge("getIccId: No UICC"); |
| 5394 | return null; |
| 5395 | } |
| 5396 | String iccId = card.getIccId(); |
| 5397 | if (TextUtils.isEmpty(iccId)) { |
| 5398 | loge("getIccId: ICC ID is null or empty."); |
| 5399 | return null; |
| 5400 | } |
| 5401 | return iccId; |
| 5402 | } |
| 5403 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5404 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5405 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 5406 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5407 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5408 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5409 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5410 | final long identity = Binder.clearCallingIdentity(); |
| 5411 | try { |
| 5412 | final String iccId = getIccId(subId); |
| 5413 | final Phone phone = getPhone(subId); |
| 5414 | if (phone == null) { |
| 5415 | return false; |
| 5416 | } |
| 5417 | final String subscriberId = phone.getSubscriberId(); |
| 5418 | |
| 5419 | if (DBG_MERGE) { |
| 5420 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 5421 | + subscriberId + " to " + number); |
| 5422 | } |
| 5423 | |
| 5424 | if (TextUtils.isEmpty(iccId)) { |
| 5425 | return false; |
| 5426 | } |
| 5427 | |
| 5428 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 5429 | |
| 5430 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5431 | if (alphaTag == null) { |
| 5432 | editor.remove(alphaTagPrefKey); |
| 5433 | } else { |
| 5434 | editor.putString(alphaTagPrefKey, alphaTag); |
| 5435 | } |
| 5436 | |
| 5437 | // Record both the line number and IMSI for this ICCID, since we need to |
| 5438 | // track all merged IMSIs based on line number |
| 5439 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5440 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5441 | if (number == null) { |
| 5442 | editor.remove(numberPrefKey); |
| 5443 | editor.remove(subscriberPrefKey); |
| 5444 | } else { |
| 5445 | editor.putString(numberPrefKey, number); |
| 5446 | editor.putString(subscriberPrefKey, subscriberId); |
| 5447 | } |
| 5448 | |
| 5449 | editor.commit(); |
| 5450 | return true; |
| 5451 | } finally { |
| 5452 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5453 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5454 | } |
| 5455 | |
| 5456 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5457 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 5458 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 5459 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5460 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5461 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5462 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5463 | return null; |
| 5464 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5465 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5466 | final long identity = Binder.clearCallingIdentity(); |
| 5467 | try { |
| 5468 | String iccId = getIccId(subId); |
| 5469 | if (iccId != null) { |
| 5470 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5471 | if (DBG_MERGE) { |
| 5472 | log("getLine1NumberForDisplay returning " |
| 5473 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 5474 | } |
| 5475 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5476 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5477 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 5478 | return null; |
| 5479 | } finally { |
| 5480 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5481 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5482 | } |
| 5483 | |
| 5484 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5485 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 5486 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5487 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5488 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5489 | return null; |
| 5490 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5491 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5492 | final long identity = Binder.clearCallingIdentity(); |
| 5493 | try { |
| 5494 | String iccId = getIccId(subId); |
| 5495 | if (iccId != null) { |
| 5496 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5497 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 5498 | } |
| 5499 | return null; |
| 5500 | } finally { |
| 5501 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5502 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5503 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5504 | |
| 5505 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5506 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 5507 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5508 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 5509 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5510 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5511 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5512 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5513 | return null; |
| 5514 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5515 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5516 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 5517 | // the process, where TelephonyManager was instantiated. |
| 5518 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5519 | final long identity = Binder.clearCallingIdentity(); |
| 5520 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5521 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5522 | final TelephonyManager tele = TelephonyManager.from(context); |
| 5523 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 5524 | |
| 5525 | // Figure out what subscribers are currently active |
| 5526 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5527 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5528 | // Only consider subs which match the current subId |
| 5529 | // This logic can be simplified. See b/131189269 for progress. |
| 5530 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5531 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 5532 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5533 | |
| 5534 | // First pass, find a number override for an active subscriber |
| 5535 | String mergeNumber = null; |
| 5536 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 5537 | for (String key : prefs.keySet()) { |
| 5538 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 5539 | final String subscriberId = (String) prefs.get(key); |
| 5540 | if (activeSubscriberIds.contains(subscriberId)) { |
| 5541 | final String iccId = key.substring( |
| 5542 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 5543 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5544 | mergeNumber = (String) prefs.get(numberKey); |
| 5545 | if (DBG_MERGE) { |
| 5546 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 5547 | + " for active subscriber " + subscriberId); |
| 5548 | } |
| 5549 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 5550 | break; |
| 5551 | } |
| 5552 | } |
| 5553 | } |
| 5554 | } |
| 5555 | |
| 5556 | // Shortcut when no active merged subscribers |
| 5557 | if (TextUtils.isEmpty(mergeNumber)) { |
| 5558 | return null; |
| 5559 | } |
| 5560 | |
| 5561 | // Second pass, find all subscribers under that line override |
| 5562 | final ArraySet<String> result = new ArraySet<>(); |
| 5563 | for (String key : prefs.keySet()) { |
| 5564 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 5565 | final String number = (String) prefs.get(key); |
| 5566 | if (mergeNumber.equals(number)) { |
| 5567 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 5568 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5569 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 5570 | if (!TextUtils.isEmpty(subscriberId)) { |
| 5571 | result.add(subscriberId); |
| 5572 | } |
| 5573 | } |
| 5574 | } |
| 5575 | } |
| 5576 | |
| 5577 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 5578 | Arrays.sort(resultArray); |
| 5579 | if (DBG_MERGE) { |
| 5580 | Slog.d(LOG_TAG, |
| 5581 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 5582 | } |
| 5583 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5584 | } finally { |
| 5585 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5586 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5587 | } |
| 5588 | |
| 5589 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 5590 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 5591 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 5592 | |
| 5593 | final long identity = Binder.clearCallingIdentity(); |
| 5594 | try { |
| 5595 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 5596 | TelephonyManager.class); |
| 5597 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 5598 | if (subscriberId == null) { |
| 5599 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 5600 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 5601 | + subId); |
| 5602 | } |
| 5603 | return null; |
| 5604 | } |
| 5605 | |
| 5606 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 5607 | .getSubscriptionInfo(subId); |
| 5608 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 5609 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 5610 | if (groupUuid == null) { |
| 5611 | return new String[]{subscriberId}; |
| 5612 | } |
| 5613 | |
| 5614 | // Get all subscriberIds from the group. |
| 5615 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 5616 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5617 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 5618 | mApp.getFeatureId()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 5619 | for (SubscriptionInfo subInfo : groupInfos) { |
| 5620 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 5621 | if (subscriberId != null) { |
| 5622 | mergedSubscriberIds.add(subscriberId); |
| 5623 | } |
| 5624 | } |
| 5625 | |
| 5626 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 5627 | } finally { |
| 5628 | Binder.restoreCallingIdentity(identity); |
| 5629 | |
| 5630 | } |
| 5631 | } |
| 5632 | |
| 5633 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5634 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5635 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5636 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5637 | |
| 5638 | final long identity = Binder.clearCallingIdentity(); |
| 5639 | try { |
| 5640 | final Phone phone = getPhone(subId); |
| 5641 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 5642 | } finally { |
| 5643 | Binder.restoreCallingIdentity(identity); |
| 5644 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5645 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 5646 | |
| 5647 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5648 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5649 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 5650 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5651 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 5652 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5653 | |
| 5654 | final long identity = Binder.clearCallingIdentity(); |
| 5655 | try { |
| 5656 | final Phone phone = getPhone(subId); |
| 5657 | if (phone == null) { |
| 5658 | return false; |
| 5659 | } |
| 5660 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 5661 | cdmaNonRoamingList); |
| 5662 | } finally { |
| 5663 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5664 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5665 | } |
| 5666 | |
| 5667 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5668 | @Deprecated |
| 5669 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 5670 | enforceModifyPermission(); |
| 5671 | |
| 5672 | int returnValue = 0; |
| 5673 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5674 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5675 | if(result.exception == null) { |
| 5676 | if (result.result != null) { |
| 5677 | byte[] responseData = (byte[])(result.result); |
| 5678 | if(responseData.length > oemResp.length) { |
| 5679 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 5680 | responseData.length + "bytes. Buffer Size is " + |
| 5681 | oemResp.length + "bytes."); |
| 5682 | } |
| 5683 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 5684 | returnValue = responseData.length; |
| 5685 | } |
| 5686 | } else { |
| 5687 | CommandException ex = (CommandException) result.exception; |
| 5688 | returnValue = ex.getCommandError().ordinal(); |
| 5689 | if(returnValue > 0) returnValue *= -1; |
| 5690 | } |
| 5691 | } catch (RuntimeException e) { |
| 5692 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 5693 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 5694 | if(returnValue > 0) returnValue *= -1; |
| 5695 | } |
| 5696 | |
| 5697 | return returnValue; |
| 5698 | } |
| 5699 | |
| 5700 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5701 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 5702 | try { |
| 5703 | ProxyController.getInstance().setRadioCapability(rafs); |
| 5704 | } catch (RuntimeException e) { |
| 5705 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 5706 | } |
| 5707 | } |
| 5708 | |
| 5709 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5710 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5711 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5712 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5713 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5714 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5715 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5716 | final long identity = Binder.clearCallingIdentity(); |
| 5717 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5718 | TelephonyPermissions |
| 5719 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5720 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 5721 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5722 | } finally { |
| 5723 | Binder.restoreCallingIdentity(identity); |
| 5724 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5725 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5726 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5727 | |
| 5728 | @Override |
| 5729 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5730 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5731 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5732 | |
| 5733 | final long identity = Binder.clearCallingIdentity(); |
| 5734 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5735 | ImsManager.getInstance(defaultPhone.getContext(), |
| 5736 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5737 | } finally { |
| 5738 | Binder.restoreCallingIdentity(identity); |
| 5739 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5740 | } |
| 5741 | |
| 5742 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5743 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5744 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5745 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5746 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5747 | return false; |
| 5748 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5749 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5750 | final long identity = Binder.clearCallingIdentity(); |
| 5751 | try { |
| 5752 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 5753 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 5754 | // In the long run, we may instead need to check if there exists a connection service |
| 5755 | // which can support video calling. |
| 5756 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5757 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5758 | return imsManager.isVtEnabledByPlatform() |
| 5759 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 5760 | && imsManager.isVtEnabledByUser(); |
| 5761 | } finally { |
| 5762 | Binder.restoreCallingIdentity(identity); |
| 5763 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5764 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 5765 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5766 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5767 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 5768 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5769 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5770 | mApp, subId, callingPackage, callingFeatureId, |
| 5771 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5772 | return false; |
| 5773 | } |
| 5774 | |
| 5775 | final long identity = Binder.clearCallingIdentity(); |
| 5776 | try { |
| 5777 | CarrierConfigManager configManager = |
| 5778 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5779 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5780 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 5781 | } finally { |
| 5782 | Binder.restoreCallingIdentity(identity); |
| 5783 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5784 | } |
| 5785 | |
| 5786 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5787 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5788 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5789 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5790 | return false; |
| 5791 | } |
| 5792 | |
| 5793 | final long identity = Binder.clearCallingIdentity(); |
| 5794 | try { |
| 5795 | CarrierConfigManager configManager = |
| 5796 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5797 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5798 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 5799 | } finally { |
| 5800 | Binder.restoreCallingIdentity(identity); |
| 5801 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5802 | } |
| 5803 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5804 | @Override |
| 5805 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 5806 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 5807 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5808 | } |
| 5809 | |
| 5810 | @Override |
| 5811 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5812 | final long identity = Binder.clearCallingIdentity(); |
| 5813 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5814 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5815 | } finally { |
| 5816 | Binder.restoreCallingIdentity(identity); |
| 5817 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 5818 | } |
| 5819 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5820 | /** |
| 5821 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 5822 | * support for the feature and device firmware support. |
| 5823 | * |
| 5824 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 5825 | */ |
| 5826 | @Override |
| 5827 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5828 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5829 | final Phone phone = getPhone(subscriptionId); |
| 5830 | if (phone == null) { |
| 5831 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 5832 | return false; |
| 5833 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5834 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5835 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5836 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 5837 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5838 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5839 | return isCarrierSupported && isDeviceSupported; |
| 5840 | } finally { |
| 5841 | Binder.restoreCallingIdentity(identity); |
| 5842 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 5843 | } |
| 5844 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 5845 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 5846 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 5847 | * RTT setting, will return true if the device and carrier both support RTT. |
| 5848 | * 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] | 5849 | */ |
| 5850 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5851 | final long identity = Binder.clearCallingIdentity(); |
| 5852 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 5853 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 5854 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 5855 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 5856 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 5857 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 5858 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5859 | } finally { |
| 5860 | Binder.restoreCallingIdentity(identity); |
| 5861 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 5862 | } |
| 5863 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5864 | @Deprecated |
| 5865 | @Override |
| 5866 | public String getDeviceId(String callingPackage) { |
| 5867 | return getDeviceIdWithFeature(callingPackage, null); |
| 5868 | } |
| 5869 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5870 | /** |
| 5871 | * Returns the unique device ID of phone, for example, the IMEI for |
| 5872 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 5873 | * |
| 5874 | * <p>Requires Permission: |
| 5875 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 5876 | */ |
| 5877 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5878 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5879 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5880 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5881 | return null; |
| 5882 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5883 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 5884 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5885 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5886 | return null; |
| 5887 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5888 | |
| 5889 | final long identity = Binder.clearCallingIdentity(); |
| 5890 | try { |
| 5891 | return phone.getDeviceId(); |
| 5892 | } finally { |
| 5893 | Binder.restoreCallingIdentity(identity); |
| 5894 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 5895 | } |
| 5896 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5897 | /** |
| 5898 | * {@hide} |
| 5899 | * Returns the IMS Registration Status on a particular subid |
| 5900 | * |
| 5901 | * @param subId |
| 5902 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5903 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 5904 | Phone phone = getPhone(subId); |
| 5905 | if (phone != null) { |
| 5906 | return phone.isImsRegistered(); |
| 5907 | } else { |
| 5908 | return false; |
| 5909 | } |
| 5910 | } |
| 5911 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5912 | @Override |
| 5913 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5914 | final long identity = Binder.clearCallingIdentity(); |
| 5915 | try { |
| 5916 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 5917 | } finally { |
| 5918 | Binder.restoreCallingIdentity(identity); |
| 5919 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 5920 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 5921 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 5922 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 5923 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5924 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 5925 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5926 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 5927 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 5928 | } |
| 5929 | final long identity = Binder.clearCallingIdentity(); |
| 5930 | try { |
| 5931 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 5932 | } finally { |
| 5933 | Binder.restoreCallingIdentity(identity); |
| 5934 | } |
| 5935 | } |
| 5936 | |
| 5937 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 5938 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 5939 | final long identity = Binder.clearCallingIdentity(); |
| 5940 | try { |
| 5941 | Phone phone = getPhone(subscriptionId); |
| 5942 | if (phone == null) { |
| 5943 | return null; |
| 5944 | } |
| 5945 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 5946 | } finally { |
| 5947 | Binder.restoreCallingIdentity(identity); |
| 5948 | } |
| 5949 | } |
| 5950 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5951 | /** |
| 5952 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5953 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5954 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5955 | final long identity = Binder.clearCallingIdentity(); |
| 5956 | try { |
| 5957 | Phone phone = getPhone(subId); |
| 5958 | if (phone != null) { |
| 5959 | return phone.isWifiCallingEnabled(); |
| 5960 | } else { |
| 5961 | return false; |
| 5962 | } |
| 5963 | } finally { |
| 5964 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5965 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 5966 | } |
| 5967 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5968 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5969 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 5970 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5971 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5972 | final long identity = Binder.clearCallingIdentity(); |
| 5973 | try { |
| 5974 | Phone phone = getPhone(subId); |
| 5975 | if (phone != null) { |
| 5976 | return phone.isVideoEnabled(); |
| 5977 | } else { |
| 5978 | return false; |
| 5979 | } |
| 5980 | } finally { |
| 5981 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 5982 | } |
| 5983 | } |
| 5984 | |
| 5985 | /** |
| 5986 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 5987 | * defined in {@link ImsRegistrationImplBase}. |
| 5988 | */ |
| 5989 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5990 | final long identity = Binder.clearCallingIdentity(); |
| 5991 | try { |
| 5992 | Phone phone = getPhone(subId); |
| 5993 | if (phone != null) { |
| 5994 | return phone.getImsRegistrationTech(); |
| 5995 | } else { |
| 5996 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 5997 | } |
| 5998 | } finally { |
| 5999 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6000 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6001 | } |
| 6002 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6003 | @Override |
| 6004 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 6005 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6006 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 6007 | return; |
| 6008 | } |
| 6009 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6010 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6011 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6012 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6013 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 6014 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6015 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6016 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6017 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6018 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 6019 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6020 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6021 | // There has been issues when Sms raw table somehow stores orphan |
| 6022 | // fragments. They lead to garbled message when new fragments come |
| 6023 | // in and combined with those stale ones. In case this happens again, |
| 6024 | // user can reset all network settings which will clean up this table. |
| 6025 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6026 | // Clean up IMS settings as well here. |
| 6027 | int slotId = getSlotIndex(subId); |
| 6028 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6029 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 6030 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 6031 | |
| 6032 | // Erase modem config if erase modem on network setting is enabled. |
| 6033 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 6034 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 6035 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 6036 | sendEraseModemConfig(getDefaultPhone()); |
| 6037 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6038 | } finally { |
| 6039 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6040 | } |
| 6041 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6042 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6043 | private void cleanUpSmsRawTable(Context context) { |
| 6044 | ContentResolver resolver = context.getContentResolver(); |
| 6045 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 6046 | resolver.delete(uri, null, null); |
| 6047 | } |
| 6048 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6049 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6050 | public String getSimLocaleForSubscriber(int subId) { |
| 6051 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 6052 | final Phone phone = getPhone(subId); |
| 6053 | if (phone == null) { |
| 6054 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 6055 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6056 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6057 | final long identity = Binder.clearCallingIdentity(); |
| 6058 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6059 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6060 | phone.getContext().getOpPackageName(), phone.getContext().getFeatureId()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 6061 | if (info == null) { |
| 6062 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 6063 | return null; |
| 6064 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6065 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 6066 | // preferences (EF-PL and EF-LI)... |
| 6067 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6068 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6069 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 6070 | if (localeFromDefaultSim != null) { |
| 6071 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 6072 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 6073 | + localeFromDefaultSim); |
| 6074 | return localeFromDefaultSim.toLanguageTag(); |
| 6075 | } else { |
| 6076 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6077 | } |
| 6078 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6079 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6080 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 6081 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 6082 | // the SIM and carrier preferences does not include a country we add the country |
| 6083 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 6084 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6085 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6086 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6087 | return mccLocale.toLanguageTag(); |
| 6088 | } |
| 6089 | |
| 6090 | if (DBG) log("No locale found - returning null"); |
| 6091 | return null; |
| 6092 | } finally { |
| 6093 | Binder.restoreCallingIdentity(identity); |
| 6094 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6095 | } |
| 6096 | |
| 6097 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6098 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
| 6099 | mApp.getFeatureId()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6100 | } |
| 6101 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6102 | /** |
| 6103 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 6104 | */ |
| 6105 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6106 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
| 6107 | mApp.getFeatureId()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6108 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6109 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6110 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6111 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6112 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6113 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6114 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 6115 | * representing the state of the modem. |
| 6116 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6117 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 6118 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6119 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6120 | */ |
| 6121 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6122 | public void requestModemActivityInfo(ResultReceiver result) { |
| 6123 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6124 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6125 | |
| 6126 | final long identity = Binder.clearCallingIdentity(); |
| 6127 | try { |
| 6128 | ModemActivityInfo ret = null; |
| 6129 | synchronized (mLastModemActivityInfo) { |
| 6130 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 6131 | CMD_GET_MODEM_ACTIVITY_INFO, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6132 | null, workSource); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6133 | if (isModemActivityInfoValid(info)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6134 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6135 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6136 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6137 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6138 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6139 | } |
| 6140 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6141 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 6142 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6143 | mLastModemActivityInfo.setIdleTimeMillis( |
| 6144 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6145 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 6146 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 6147 | info.getReceiveTimeMillis() + mLastModemActivityInfo |
| 6148 | .getReceiveTimeMillis()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6149 | } |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6150 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6151 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 6152 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 6153 | mLastModemActivityInfo.getIdleTimeMillis(), |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6154 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 6155 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6156 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6157 | Bundle bundle = new Bundle(); |
| 6158 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 6159 | result.send(0, bundle); |
| 6160 | } finally { |
| 6161 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6162 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6163 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6164 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6165 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 6166 | // less than total activity duration. |
| 6167 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 6168 | if (info == null) { |
| 6169 | return false; |
| 6170 | } |
| 6171 | int activityDurationMs = |
| 6172 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 6173 | int totalTxTimeMs = 0; |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6174 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6175 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 6176 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6177 | } |
| 6178 | return (info.isValid() |
| 6179 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 6180 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6181 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6182 | && (totalTxTimeMs <= activityDurationMs)); |
| 6183 | } |
| 6184 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6185 | /** |
| 6186 | * {@hide} |
| 6187 | * Returns the service state information on specified subscription. |
| 6188 | */ |
| 6189 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6190 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 6191 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6192 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6193 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6194 | return null; |
| 6195 | } |
| 6196 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6197 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 6198 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6199 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6200 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6201 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6202 | .setCallingPid(Binder.getCallingPid()) |
| 6203 | .setCallingUid(Binder.getCallingUid()) |
| 6204 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6205 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6206 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6207 | .build()); |
| 6208 | |
| 6209 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 6210 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6211 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6212 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6213 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6214 | .setCallingPid(Binder.getCallingPid()) |
| 6215 | .setCallingUid(Binder.getCallingUid()) |
| 6216 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6217 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6218 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6219 | .build()); |
| 6220 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 6221 | boolean hasFinePermission = |
| 6222 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6223 | boolean hasCoarsePermission = |
| 6224 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6225 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6226 | final long identity = Binder.clearCallingIdentity(); |
| 6227 | try { |
| 6228 | final Phone phone = getPhone(subId); |
| 6229 | if (phone == null) { |
| 6230 | return null; |
| 6231 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6232 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6233 | ServiceState ss = phone.getServiceState(); |
| 6234 | |
| 6235 | // Scrub out the location info in ServiceState depending on what level of access |
| 6236 | // the caller has. |
| 6237 | if (hasFinePermission) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 6238 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 6239 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6240 | } finally { |
| 6241 | Binder.restoreCallingIdentity(identity); |
| 6242 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6243 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6244 | |
| 6245 | /** |
| 6246 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 6247 | * |
| 6248 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6249 | * voicemail ringtone. |
| 6250 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 6251 | * PhoneAccount. |
| 6252 | */ |
| 6253 | @Override |
| 6254 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6255 | final long identity = Binder.clearCallingIdentity(); |
| 6256 | try { |
| 6257 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6258 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6259 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6260 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6261 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6262 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 6263 | } finally { |
| 6264 | Binder.restoreCallingIdentity(identity); |
| 6265 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6266 | } |
| 6267 | |
| 6268 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6269 | * Sets the per-account voicemail ringtone. |
| 6270 | * |
| 6271 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6272 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6273 | * |
| 6274 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6275 | * voicemail ringtone. |
| 6276 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 6277 | * PhoneAccount. |
| 6278 | */ |
| 6279 | @Override |
| 6280 | public void setVoicemailRingtoneUri(String callingPackage, |
| 6281 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6282 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6283 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6284 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6285 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6286 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6287 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6288 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6289 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6290 | |
| 6291 | final long identity = Binder.clearCallingIdentity(); |
| 6292 | try { |
| 6293 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6294 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6295 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6296 | } |
| 6297 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 6298 | } finally { |
| 6299 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6300 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6301 | } |
| 6302 | |
| 6303 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6304 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 6305 | * |
| 6306 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6307 | * voicemail vibration setting. |
| 6308 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 6309 | */ |
| 6310 | @Override |
| 6311 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6312 | final long identity = Binder.clearCallingIdentity(); |
| 6313 | try { |
| 6314 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6315 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6316 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6317 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6318 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6319 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 6320 | } finally { |
| 6321 | Binder.restoreCallingIdentity(identity); |
| 6322 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6323 | } |
| 6324 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6325 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6326 | * Sets the per-account voicemail vibration. |
| 6327 | * |
| 6328 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6329 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6330 | * |
| 6331 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6332 | * voicemail vibration setting. |
| 6333 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 6334 | * specific PhoneAccount. |
| 6335 | */ |
| 6336 | @Override |
| 6337 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 6338 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6339 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6340 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6341 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6342 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6343 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6344 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6345 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6346 | } |
| 6347 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6348 | final long identity = Binder.clearCallingIdentity(); |
| 6349 | try { |
| 6350 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6351 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6352 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6353 | } |
| 6354 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 6355 | } finally { |
| 6356 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6357 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6358 | } |
| 6359 | |
| 6360 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6361 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 6362 | * |
| 6363 | * @throws SecurityException if the caller does not have the required permission |
| 6364 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6365 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6366 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6367 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6368 | } |
| 6369 | |
| 6370 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6371 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 6372 | * permission. |
| 6373 | * |
| 6374 | * @throws SecurityException if the caller does not have the required permission |
| 6375 | */ |
| 6376 | private void enforceSendSmsPermission() { |
| 6377 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 6378 | } |
| 6379 | |
| 6380 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6381 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6382 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6383 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6384 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6385 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6386 | final long identity = Binder.clearCallingIdentity(); |
| 6387 | try { |
| 6388 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6389 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6390 | if (componentName == null) { |
| 6391 | throw new SecurityException( |
| 6392 | "Caller not current active visual voicemail package[null]"); |
| 6393 | } |
| 6394 | String vvmPackage = componentName.getPackageName(); |
| 6395 | if (!callingPackage.equals(vvmPackage)) { |
| 6396 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 6397 | + vvmPackage + "]"); |
| 6398 | } |
| 6399 | } finally { |
| 6400 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6401 | } |
| 6402 | } |
| 6403 | |
| 6404 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6405 | * Return the application ID for the app type. |
| 6406 | * |
| 6407 | * @param subId the subscription ID that this request applies to. |
| 6408 | * @param appType the uicc app type. |
| 6409 | * @return Application ID for specificied app type, or null if no uicc. |
| 6410 | */ |
| 6411 | @Override |
| 6412 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6413 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6414 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6415 | |
| 6416 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6417 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6418 | if (phone == null) { |
| 6419 | return null; |
| 6420 | } |
| 6421 | String aid = null; |
| 6422 | try { |
| 6423 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 6424 | .getApplicationByType(appType).getAid(); |
| 6425 | } catch (Exception e) { |
| 6426 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 6427 | } |
| 6428 | return aid; |
| 6429 | } finally { |
| 6430 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6431 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6432 | } |
| 6433 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6434 | /** |
| 6435 | * Return the Electronic Serial Number. |
| 6436 | * |
| 6437 | * @param subId the subscription ID that this request applies to. |
| 6438 | * @return ESN or null if error. |
| 6439 | */ |
| 6440 | @Override |
| 6441 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6442 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6443 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6444 | |
| 6445 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6446 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6447 | if (phone == null) { |
| 6448 | return null; |
| 6449 | } |
| 6450 | String esn = null; |
| 6451 | try { |
| 6452 | esn = phone.getEsn(); |
| 6453 | } catch (Exception e) { |
| 6454 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 6455 | } |
| 6456 | return esn; |
| 6457 | } finally { |
| 6458 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6459 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6460 | } |
| 6461 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6462 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6463 | * Return the Preferred Roaming List Version. |
| 6464 | * |
| 6465 | * @param subId the subscription ID that this request applies to. |
| 6466 | * @return PRLVersion or null if error. |
| 6467 | */ |
| 6468 | @Override |
| 6469 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6470 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6471 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6472 | |
| 6473 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6474 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6475 | if (phone == null) { |
| 6476 | return null; |
| 6477 | } |
| 6478 | String cdmaPrlVersion = null; |
| 6479 | try { |
| 6480 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 6481 | } catch (Exception e) { |
| 6482 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 6483 | } |
| 6484 | return cdmaPrlVersion; |
| 6485 | } finally { |
| 6486 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6487 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6488 | } |
| 6489 | |
| 6490 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6491 | * Get snapshot of Telephony histograms |
| 6492 | * @return List of Telephony histograms |
| 6493 | * @hide |
| 6494 | */ |
| 6495 | @Override |
| 6496 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6497 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6498 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6499 | |
| 6500 | final long identity = Binder.clearCallingIdentity(); |
| 6501 | try { |
| 6502 | return RIL.getTelephonyRILTimingHistograms(); |
| 6503 | } finally { |
| 6504 | Binder.restoreCallingIdentity(identity); |
| 6505 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6506 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6507 | |
| 6508 | /** |
| 6509 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6510 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 6511 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6512 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6513 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6514 | * @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] | 6515 | */ |
| 6516 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6517 | @TelephonyManager.SetCarrierRestrictionResult |
| 6518 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6519 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6520 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6521 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6522 | if (carrierRestrictionRules == null) { |
| 6523 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 6524 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6525 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6526 | final long identity = Binder.clearCallingIdentity(); |
| 6527 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6528 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6529 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6530 | } finally { |
| 6531 | Binder.restoreCallingIdentity(identity); |
| 6532 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6533 | } |
| 6534 | |
| 6535 | /** |
| 6536 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6537 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 6538 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6539 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6540 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6541 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6542 | */ |
| 6543 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6544 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6545 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6546 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6547 | |
| 6548 | final long identity = Binder.clearCallingIdentity(); |
| 6549 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6550 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 6551 | if (response instanceof CarrierRestrictionRules) { |
| 6552 | return (CarrierRestrictionRules) response; |
| 6553 | } |
| 6554 | // Response is an Exception of some kind, |
| 6555 | // which is signalled to the user as a NULL retval |
| 6556 | return null; |
| 6557 | } catch (Exception e) { |
| 6558 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 6559 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6560 | } finally { |
| 6561 | Binder.restoreCallingIdentity(identity); |
| 6562 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6563 | } |
| 6564 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6565 | /** |
| 6566 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 6567 | * @param subId the subscription ID that this action applies to. |
| 6568 | * @param enabled control enable or disable metered apns. |
| 6569 | * {@hide} |
| 6570 | */ |
| 6571 | @Override |
| 6572 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 6573 | enforceModifyPermission(); |
| 6574 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6575 | |
| 6576 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6577 | if (phone == null) { |
| 6578 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 6579 | return; |
| 6580 | } |
| 6581 | try { |
| 6582 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 6583 | } catch (Exception e) { |
| 6584 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6585 | } finally { |
| 6586 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6587 | } |
| 6588 | } |
| 6589 | |
| 6590 | /** |
| 6591 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 6592 | * @param subId the subscription ID that this action applies to. |
| 6593 | * @param enabled control enable or disable radio. |
| 6594 | * {@hide} |
| 6595 | */ |
| 6596 | @Override |
| 6597 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 6598 | enforceModifyPermission(); |
| 6599 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6600 | |
| 6601 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6602 | if (phone == null) { |
| 6603 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 6604 | return; |
| 6605 | } |
| 6606 | try { |
| 6607 | phone.carrierActionSetRadioEnabled(enabled); |
| 6608 | } catch (Exception e) { |
| 6609 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6610 | } finally { |
| 6611 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6612 | } |
| 6613 | } |
| 6614 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6615 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6616 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 6617 | * network status based on which carrier apps could apply actions accordingly, |
| 6618 | * enable/disable default url handler for example. |
| 6619 | * |
| 6620 | * @param subId the subscription ID that this action applies to. |
| 6621 | * @param report control start/stop reporting the default network status. |
| 6622 | * {@hide} |
| 6623 | */ |
| 6624 | @Override |
| 6625 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 6626 | enforceModifyPermission(); |
| 6627 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6628 | |
| 6629 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6630 | if (phone == null) { |
| 6631 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 6632 | return; |
| 6633 | } |
| 6634 | try { |
| 6635 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 6636 | } catch (Exception e) { |
| 6637 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6638 | } finally { |
| 6639 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6640 | } |
| 6641 | } |
| 6642 | |
| 6643 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 6644 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 6645 | * @param subId the subscription ID that this action applies to. |
| 6646 | * {@hide} |
| 6647 | */ |
| 6648 | @Override |
| 6649 | public void carrierActionResetAll(int subId) { |
| 6650 | enforceModifyPermission(); |
| 6651 | final Phone phone = getPhone(subId); |
| 6652 | if (phone == null) { |
| 6653 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 6654 | return; |
| 6655 | } |
| 6656 | try { |
| 6657 | phone.carrierActionResetAll(); |
| 6658 | } catch (Exception e) { |
| 6659 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 6660 | } |
| 6661 | } |
| 6662 | |
| 6663 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6664 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 6665 | * bug report is being generated. |
| 6666 | */ |
| 6667 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 6668 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6669 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 6670 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 6671 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 6672 | + Binder.getCallingPid() |
| 6673 | + ", uid=" + Binder.getCallingUid() |
| 6674 | + "without permission " |
| 6675 | + android.Manifest.permission.DUMP); |
| 6676 | return; |
| 6677 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6678 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6679 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6680 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6681 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 6682 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 6683 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 6684 | @NonNull String[] args) { |
| 6685 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 6686 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 6687 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6688 | } |
| 6689 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6690 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6691 | * Get aggregated video call data usage since boot. |
| 6692 | * |
| 6693 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 6694 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6695 | * {@hide} |
| 6696 | */ |
| 6697 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6698 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6699 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 6700 | null); |
| 6701 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6702 | final long identity = Binder.clearCallingIdentity(); |
| 6703 | try { |
| 6704 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 6705 | // records the delta with the corresponding network identity. |
| 6706 | // We just return the total video call data usage snapshot since boot. |
| 6707 | Phone phone = getPhone(subId); |
| 6708 | if (phone != null) { |
| 6709 | return phone.getVtDataUsage(perUidStats); |
| 6710 | } |
| 6711 | return null; |
| 6712 | } finally { |
| 6713 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6714 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6715 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6716 | |
| 6717 | /** |
| 6718 | * Policy control of data connection. Usually used when data limit is passed. |
| 6719 | * @param enabled True if enabling the data, otherwise disabling. |
| 6720 | * @param subId Subscription index |
| 6721 | * {@hide} |
| 6722 | */ |
| 6723 | @Override |
| 6724 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 6725 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6726 | |
| 6727 | final long identity = Binder.clearCallingIdentity(); |
| 6728 | try { |
| 6729 | Phone phone = getPhone(subId); |
| 6730 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6731 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6732 | } |
| 6733 | } finally { |
| 6734 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6735 | } |
| 6736 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6737 | |
| 6738 | /** |
| 6739 | * Get Client request stats |
| 6740 | * @return List of Client Request Stats |
| 6741 | * @hide |
| 6742 | */ |
| 6743 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6744 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 6745 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6746 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6747 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6748 | return null; |
| 6749 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6750 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6751 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6752 | final long identity = Binder.clearCallingIdentity(); |
| 6753 | try { |
| 6754 | if (phone != null) { |
| 6755 | return phone.getClientRequestStats(); |
| 6756 | } |
| 6757 | |
| 6758 | return null; |
| 6759 | } finally { |
| 6760 | Binder.restoreCallingIdentity(identity); |
| 6761 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6762 | } |
| 6763 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6764 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6765 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6766 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6767 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6768 | |
| 6769 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6770 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6771 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6772 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6773 | * @param state State of SIM (power down, power up, pass through) |
| 6774 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 6775 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 6776 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6777 | * |
| 6778 | **/ |
| 6779 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 6780 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6781 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6782 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6783 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6784 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6785 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6786 | final long identity = Binder.clearCallingIdentity(); |
| 6787 | try { |
| 6788 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6789 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6790 | } |
| 6791 | } finally { |
| 6792 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 6793 | } |
| 6794 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6795 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6796 | private boolean isUssdApiAllowed(int subId) { |
| 6797 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6798 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 6799 | if (configManager == null) { |
| 6800 | return false; |
| 6801 | } |
| 6802 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 6803 | if (pb == null) { |
| 6804 | return false; |
| 6805 | } |
| 6806 | return pb.getBoolean( |
| 6807 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 6808 | } |
| 6809 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6810 | /** |
| 6811 | * Check if phone is in emergency callback mode |
| 6812 | * @return true if phone is in emergency callback mode |
| 6813 | * @param subId sub id |
| 6814 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 6815 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6816 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6817 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6818 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6819 | |
| 6820 | final long identity = Binder.clearCallingIdentity(); |
| 6821 | try { |
| 6822 | if (phone != null) { |
| 6823 | return phone.isInEcm(); |
| 6824 | } else { |
| 6825 | return false; |
| 6826 | } |
| 6827 | } finally { |
| 6828 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 6829 | } |
| 6830 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6831 | |
| 6832 | /** |
| 6833 | * Get the current signal strength information for the given subscription. |
| 6834 | * Because this information is not updated when the device is in a low power state |
| 6835 | * it should not be relied-upon to be current. |
| 6836 | * @param subId Subscription index |
| 6837 | * @return the most recent cached signal strength info from the modem |
| 6838 | */ |
| 6839 | @Override |
| 6840 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6841 | final long identity = Binder.clearCallingIdentity(); |
| 6842 | try { |
| 6843 | Phone p = getPhone(subId); |
| 6844 | if (p == null) { |
| 6845 | return null; |
| 6846 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6847 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6848 | return p.getSignalStrength(); |
| 6849 | } finally { |
| 6850 | Binder.restoreCallingIdentity(identity); |
| 6851 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 6852 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6853 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6854 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 6855 | * Get the current modem radio state for the given slot. |
| 6856 | * @param slotIndex slot index. |
| 6857 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6858 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 6859 | * @return the current radio power state from the modem |
| 6860 | */ |
| 6861 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6862 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 6863 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 6864 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6865 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 6866 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 6867 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6868 | } |
| 6869 | |
| 6870 | final long identity = Binder.clearCallingIdentity(); |
| 6871 | try { |
| 6872 | return phone.getRadioPowerState(); |
| 6873 | } finally { |
| 6874 | Binder.restoreCallingIdentity(identity); |
| 6875 | } |
| 6876 | } |
| 6877 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 6878 | } |
| 6879 | |
| 6880 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6881 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 6882 | * |
| 6883 | * <p>Requires one of the following permissions: |
| 6884 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 6885 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 6886 | * privileges. |
| 6887 | * |
| 6888 | * @param subId subscription id |
| 6889 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 6890 | * {@code false}. |
| 6891 | */ |
| 6892 | @Override |
| 6893 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6894 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6895 | null /* message */); |
| 6896 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6897 | boolean isEnabled = false; |
| 6898 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6899 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6900 | Phone phone = getPhone(subId); |
| 6901 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6902 | } catch (Exception e) { |
| 6903 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 6904 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6905 | } finally { |
| 6906 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6907 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6908 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6909 | } |
| 6910 | |
| 6911 | |
| 6912 | /** |
| 6913 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 6914 | * |
| 6915 | * <p> Requires permission: |
| 6916 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 6917 | * privileges. |
| 6918 | * |
| 6919 | * @param subId subscription id |
| 6920 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 6921 | */ |
| 6922 | @Override |
| 6923 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6924 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6925 | mApp, subId, "setDataRoamingEnabled"); |
| 6926 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6927 | final long identity = Binder.clearCallingIdentity(); |
| 6928 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 6929 | Phone phone = getPhone(subId); |
| 6930 | if (phone != null) { |
| 6931 | phone.setDataRoamingEnabled(isEnabled); |
| 6932 | } |
| 6933 | } finally { |
| 6934 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 6935 | } |
| 6936 | } |
| 6937 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 6938 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6939 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 6940 | TelephonyPermissions |
| 6941 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 6942 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 6943 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6944 | boolean isAllowed = true; |
| 6945 | final long identity = Binder.clearCallingIdentity(); |
| 6946 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 6947 | Phone phone = getPhone(subId); |
| 6948 | if (phone != null) { |
| 6949 | isAllowed = phone.isCspPlmnEnabled(); |
| 6950 | } |
| 6951 | } finally { |
| 6952 | Binder.restoreCallingIdentity(identity); |
| 6953 | } |
| 6954 | return isAllowed; |
| 6955 | } |
| 6956 | |
| 6957 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6958 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6959 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6960 | try { |
| 6961 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6962 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6963 | } catch (SecurityException e) { |
| 6964 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 6965 | // has carrier privileges on an active UICC |
| 6966 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 6967 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6968 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 6969 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6970 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 6971 | |
| 6972 | final long identity = Binder.clearCallingIdentity(); |
| 6973 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6974 | UiccController uiccController = UiccController.getInstance(); |
| 6975 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6976 | if (hasReadPermission) { |
| 6977 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 6978 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 6979 | |
| 6980 | // Remove private info if the caller doesn't have access |
| 6981 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 6982 | for (UiccCardInfo cardInfo : cardInfos) { |
| 6983 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 6984 | // is available |
| 6985 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 6986 | if (card == null || card.getUiccProfile() == null) { |
| 6987 | // assume no access if the card or profile is unavailable |
| 6988 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6989 | continue; |
| 6990 | } |
| 6991 | UiccProfile profile = card.getUiccProfile(); |
| 6992 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 6993 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6994 | filteredInfos.add(cardInfo); |
| 6995 | } else { |
| 6996 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 6997 | } |
| 6998 | } |
| 6999 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7000 | } finally { |
| 7001 | Binder.restoreCallingIdentity(identity); |
| 7002 | } |
| 7003 | } |
| 7004 | |
| 7005 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7006 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7007 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7008 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7009 | final long identity = Binder.clearCallingIdentity(); |
| 7010 | try { |
| 7011 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 7012 | if (slots == null) { |
| 7013 | Rlog.i(LOG_TAG, "slots is null."); |
| 7014 | return null; |
| 7015 | } |
| 7016 | |
| 7017 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 7018 | for (int i = 0; i < slots.length; i++) { |
| 7019 | UiccSlot slot = slots[i]; |
| 7020 | if (slot == null) { |
| 7021 | continue; |
| 7022 | } |
| 7023 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7024 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7025 | UiccCard card = slot.getUiccCard(); |
| 7026 | if (card != null) { |
| 7027 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7028 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 7029 | cardId = slot.getEid(); |
| 7030 | if (TextUtils.isEmpty(cardId)) { |
| 7031 | cardId = slot.getIccId(); |
| 7032 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7033 | } |
| 7034 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 7035 | if (cardId != null) { |
| 7036 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 7037 | // if cardId is an EID, it's all digits so this is fine |
| 7038 | cardId = IccUtils.stripTrailingFs(cardId); |
| 7039 | } |
| 7040 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7041 | int cardState = 0; |
| 7042 | switch (slot.getCardState()) { |
| 7043 | case CARDSTATE_ABSENT: |
| 7044 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 7045 | break; |
| 7046 | case CARDSTATE_PRESENT: |
| 7047 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 7048 | break; |
| 7049 | case CARDSTATE_ERROR: |
| 7050 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 7051 | break; |
| 7052 | case CARDSTATE_RESTRICTED: |
| 7053 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 7054 | break; |
| 7055 | default: |
| 7056 | break; |
| 7057 | |
| 7058 | } |
| 7059 | |
| 7060 | infos[i] = new UiccSlotInfo( |
| 7061 | slot.isActive(), |
| 7062 | slot.isEuicc(), |
| 7063 | cardId, |
| 7064 | cardState, |
| 7065 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 7066 | slot.isExtendedApduSupported(), |
| 7067 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7068 | } |
| 7069 | return infos; |
| 7070 | } finally { |
| 7071 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 7072 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7073 | } |
| 7074 | |
| 7075 | @Override |
| 7076 | public boolean switchSlots(int[] physicalSlots) { |
| 7077 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7078 | |
| 7079 | final long identity = Binder.clearCallingIdentity(); |
| 7080 | try { |
| 7081 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 7082 | } finally { |
| 7083 | Binder.restoreCallingIdentity(identity); |
| 7084 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7085 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7086 | |
| 7087 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7088 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7089 | final long identity = Binder.clearCallingIdentity(); |
| 7090 | try { |
| 7091 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 7092 | } finally { |
| 7093 | Binder.restoreCallingIdentity(identity); |
| 7094 | } |
| 7095 | } |
| 7096 | |
| 7097 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7098 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 7099 | enforceModifyPermission(); |
| 7100 | final Phone phone = getPhone(subId); |
| 7101 | if (phone == null) { |
| 7102 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 7103 | return; |
| 7104 | } |
| 7105 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7106 | final long identity = Binder.clearCallingIdentity(); |
| 7107 | try { |
| 7108 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 7109 | } finally { |
| 7110 | Binder.restoreCallingIdentity(identity); |
| 7111 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7112 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7113 | |
| 7114 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 7115 | * A test API to reload the UICC profile. |
| 7116 | * |
| 7117 | * <p>Requires that the calling app has permission |
| 7118 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7119 | * @hide |
| 7120 | */ |
| 7121 | @Override |
| 7122 | public void refreshUiccProfile(int subId) { |
| 7123 | enforceModifyPermission(); |
| 7124 | |
| 7125 | final long identity = Binder.clearCallingIdentity(); |
| 7126 | try { |
| 7127 | Phone phone = getPhone(subId); |
| 7128 | if (phone == null) { |
| 7129 | return; |
| 7130 | } |
| 7131 | UiccCard uiccCard = phone.getUiccCard(); |
| 7132 | if (uiccCard == null) { |
| 7133 | return; |
| 7134 | } |
| 7135 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7136 | if (uiccProfile == null) { |
| 7137 | return; |
| 7138 | } |
| 7139 | uiccProfile.refresh(); |
| 7140 | } finally { |
| 7141 | Binder.restoreCallingIdentity(identity); |
| 7142 | } |
| 7143 | } |
| 7144 | |
| 7145 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7146 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 7147 | */ |
| 7148 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7149 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7150 | } |
| 7151 | |
| 7152 | /** |
| 7153 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 7154 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 7155 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 7156 | */ |
| 7157 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 7158 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7159 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7160 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7161 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 7162 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 7163 | return isDataRoamingEnabled; |
| 7164 | } |
| 7165 | |
| 7166 | /** |
| 7167 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 7168 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 7169 | */ |
| 7170 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7171 | List<Integer> list = TelephonyProperties.default_network(); |
| 7172 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 7173 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 7174 | return list.get(phoneId); |
| 7175 | } |
| 7176 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7177 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7178 | |
| 7179 | @Override |
| 7180 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7181 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7182 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7183 | |
| 7184 | final long identity = Binder.clearCallingIdentity(); |
| 7185 | try { |
| 7186 | final Phone phone = getPhone(subId); |
| 7187 | if (phone == null) { |
| 7188 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 7189 | return; |
| 7190 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7191 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 7192 | carrierPrivilegeRules, apn); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7193 | } finally { |
| 7194 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7195 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7196 | } |
| 7197 | |
| 7198 | @Override |
| 7199 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7200 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7201 | |
| 7202 | final long identity = Binder.clearCallingIdentity(); |
| 7203 | try { |
| 7204 | final Phone phone = getPhone(subId); |
| 7205 | if (phone == null) { |
| 7206 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 7207 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 7208 | } |
| 7209 | return phone.getCarrierIdListVersion(); |
| 7210 | } finally { |
| 7211 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7212 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7213 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7214 | |
| 7215 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7216 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 7217 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7218 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7219 | mApp, subId, callingPackage, callingFeatureId, |
| 7220 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7221 | return -1; |
| 7222 | } |
| 7223 | |
| 7224 | final long identity = Binder.clearCallingIdentity(); |
| 7225 | try { |
| 7226 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 7227 | } finally { |
| 7228 | Binder.restoreCallingIdentity(identity); |
| 7229 | } |
| 7230 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7231 | |
| 7232 | @Override |
| 7233 | public int getCdmaRoamingMode(int subId) { |
| 7234 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7235 | mApp, subId, "getCdmaRoamingMode"); |
| 7236 | |
| 7237 | final long identity = Binder.clearCallingIdentity(); |
| 7238 | try { |
| 7239 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 7240 | } finally { |
| 7241 | Binder.restoreCallingIdentity(identity); |
| 7242 | } |
| 7243 | } |
| 7244 | |
| 7245 | @Override |
| 7246 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 7247 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7248 | mApp, subId, "setCdmaRoamingMode"); |
| 7249 | |
| 7250 | final long identity = Binder.clearCallingIdentity(); |
| 7251 | try { |
| 7252 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 7253 | } finally { |
| 7254 | Binder.restoreCallingIdentity(identity); |
| 7255 | } |
| 7256 | } |
| 7257 | |
| 7258 | @Override |
| 7259 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 7260 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7261 | mApp, subId, "setCdmaSubscriptionMode"); |
| 7262 | |
| 7263 | final long identity = Binder.clearCallingIdentity(); |
| 7264 | try { |
| 7265 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 7266 | } finally { |
| 7267 | Binder.restoreCallingIdentity(identity); |
| 7268 | } |
| 7269 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 7270 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7271 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7272 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7273 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7274 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7275 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 7276 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7277 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7278 | } |
| 7279 | final long identity = Binder.clearCallingIdentity(); |
| 7280 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7281 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 7282 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7283 | if (phone.getEmergencyNumberTracker() != null |
| 7284 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 7285 | emergencyNumberListInternal.put( |
| 7286 | phone.getSubId(), |
| 7287 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 7288 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7289 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7290 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7291 | } finally { |
| 7292 | Binder.restoreCallingIdentity(identity); |
| 7293 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7294 | } |
| 7295 | |
| 7296 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7297 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7298 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7299 | if (!exactMatch) { |
| 7300 | TelephonyPermissions |
| 7301 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7302 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7303 | } |
| 7304 | final long identity = Binder.clearCallingIdentity(); |
| 7305 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7306 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7307 | if (phone.getEmergencyNumberTracker() != null |
| 7308 | && phone.getEmergencyNumberTracker() != null) { |
| 7309 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 7310 | number, exactMatch)) { |
| 7311 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7312 | } |
| 7313 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7314 | } |
| 7315 | return false; |
| 7316 | } finally { |
| 7317 | Binder.restoreCallingIdentity(identity); |
| 7318 | } |
| 7319 | } |
| 7320 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 7321 | /** |
| 7322 | * Update emergency number list for test mode. |
| 7323 | */ |
| 7324 | @Override |
| 7325 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 7326 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7327 | "updateEmergencyNumberListTestMode"); |
| 7328 | |
| 7329 | final long identity = Binder.clearCallingIdentity(); |
| 7330 | try { |
| 7331 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7332 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7333 | if (tracker != null) { |
| 7334 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 7335 | } |
| 7336 | } |
| 7337 | } finally { |
| 7338 | Binder.restoreCallingIdentity(identity); |
| 7339 | } |
| 7340 | } |
| 7341 | |
| 7342 | /** |
| 7343 | * Get the full emergency number list for test mode. |
| 7344 | */ |
| 7345 | @Override |
| 7346 | public List<String> getEmergencyNumberListTestMode() { |
| 7347 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7348 | "getEmergencyNumberListTestMode"); |
| 7349 | |
| 7350 | final long identity = Binder.clearCallingIdentity(); |
| 7351 | try { |
| 7352 | Set<String> emergencyNumbers = new HashSet<>(); |
| 7353 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7354 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7355 | if (tracker != null) { |
| 7356 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 7357 | emergencyNumbers.add(num.getNumber()); |
| 7358 | } |
| 7359 | } |
| 7360 | } |
| 7361 | return new ArrayList<>(emergencyNumbers); |
| 7362 | } finally { |
| 7363 | Binder.restoreCallingIdentity(identity); |
| 7364 | } |
| 7365 | } |
| 7366 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7367 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7368 | public int getEmergencyNumberDbVersion(int subId) { |
| 7369 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 7370 | |
| 7371 | final long identity = Binder.clearCallingIdentity(); |
| 7372 | try { |
| 7373 | final Phone phone = getPhone(subId); |
| 7374 | if (phone == null) { |
| 7375 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 7376 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 7377 | } |
| 7378 | return phone.getEmergencyNumberDbVersion(); |
| 7379 | } finally { |
| 7380 | Binder.restoreCallingIdentity(identity); |
| 7381 | } |
| 7382 | } |
| 7383 | |
| 7384 | @Override |
| 7385 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 7386 | enforceModifyPermission(); |
| 7387 | |
| 7388 | final long identity = Binder.clearCallingIdentity(); |
| 7389 | try { |
| 7390 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7391 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7392 | if (tracker != null) { |
| 7393 | tracker.updateOtaEmergencyNumberDatabase(); |
| 7394 | } |
| 7395 | } |
| 7396 | } finally { |
| 7397 | Binder.restoreCallingIdentity(identity); |
| 7398 | } |
| 7399 | } |
| 7400 | |
| 7401 | @Override |
| 7402 | public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) { |
| 7403 | enforceActiveEmergencySessionPermission(); |
| 7404 | |
| 7405 | final long identity = Binder.clearCallingIdentity(); |
| 7406 | try { |
| 7407 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7408 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7409 | if (tracker != null) { |
| 7410 | tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath); |
| 7411 | } |
| 7412 | } |
| 7413 | } finally { |
| 7414 | Binder.restoreCallingIdentity(identity); |
| 7415 | } |
| 7416 | } |
| 7417 | |
| 7418 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7419 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 7420 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 7421 | Phone phone = getPhone(subId); |
| 7422 | if (phone == null) { |
| 7423 | return null; |
| 7424 | } |
| 7425 | final long identity = Binder.clearCallingIdentity(); |
| 7426 | try { |
| 7427 | UiccProfile profile = UiccController.getInstance() |
| 7428 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 7429 | if (profile != null) { |
| 7430 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 7431 | } |
| 7432 | } finally { |
| 7433 | Binder.restoreCallingIdentity(identity); |
| 7434 | } |
| 7435 | return null; |
| 7436 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 7437 | |
| 7438 | /** |
| 7439 | * Enable or disable a modem stack. |
| 7440 | */ |
| 7441 | @Override |
| 7442 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 7443 | enforceModifyPermission(); |
| 7444 | |
| 7445 | final long identity = Binder.clearCallingIdentity(); |
| 7446 | try { |
| 7447 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7448 | if (phone == null) { |
| 7449 | return false; |
| 7450 | } else { |
| 7451 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 7452 | } |
| 7453 | } finally { |
| 7454 | Binder.restoreCallingIdentity(identity); |
| 7455 | } |
| 7456 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7457 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7458 | /** |
| 7459 | * Whether a modem stack is enabled or not. |
| 7460 | */ |
| 7461 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7462 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 7463 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7464 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7465 | if (phone == null) return false; |
| 7466 | |
| 7467 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7468 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 7469 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7470 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7471 | } |
| 7472 | |
| 7473 | final long identity = Binder.clearCallingIdentity(); |
| 7474 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 7475 | try { |
| 7476 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 7477 | } catch (NoSuchElementException ex) { |
| 7478 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 7479 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7480 | } finally { |
| 7481 | Binder.restoreCallingIdentity(identity); |
| 7482 | } |
| 7483 | } |
| 7484 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7485 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7486 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7487 | enforceModifyPermission(); |
| 7488 | |
| 7489 | final long identity = Binder.clearCallingIdentity(); |
| 7490 | try { |
| 7491 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7492 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7493 | .commit(); |
| 7494 | } finally { |
| 7495 | Binder.restoreCallingIdentity(identity); |
| 7496 | } |
| 7497 | } |
| 7498 | |
| 7499 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7500 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7501 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7502 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7503 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 7504 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7505 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7506 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7507 | |
| 7508 | final long identity = Binder.clearCallingIdentity(); |
| 7509 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7510 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7511 | } finally { |
| 7512 | Binder.restoreCallingIdentity(identity); |
| 7513 | } |
| 7514 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7515 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7516 | @TelephonyManager.IsMultiSimSupportedResult |
| 7517 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7518 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 7519 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 7520 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7521 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 7522 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7523 | } |
| 7524 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 7525 | // supported by the modem, indicate that it is restricted. |
| 7526 | PhoneCapability staticCapability = |
| 7527 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 7528 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7529 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 7530 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7531 | } |
| 7532 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7533 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 7534 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7535 | } |
| 7536 | // Check if support of multiple SIMs is restricted by carrier |
| 7537 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7538 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7539 | } |
| 7540 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7541 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7542 | } |
| 7543 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7544 | /** |
| 7545 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7546 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 7547 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 7548 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7549 | * @param numOfSims number of active sims we want to switch to |
| 7550 | */ |
| 7551 | @Override |
| 7552 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7553 | if (numOfSims == 1) { |
| 7554 | enforceModifyPermission(); |
| 7555 | } else { |
| 7556 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7557 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 7558 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7559 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7560 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7561 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7562 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7563 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7564 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 7565 | return; |
| 7566 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7567 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 7568 | } finally { |
| 7569 | Binder.restoreCallingIdentity(identity); |
| 7570 | } |
| 7571 | } |
| 7572 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 7573 | @Override |
| 7574 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 7575 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 7576 | Phone phone = getPhone(subId); |
| 7577 | if (phone == null) { |
| 7578 | return false; |
| 7579 | } |
| 7580 | final long identity = Binder.clearCallingIdentity(); |
| 7581 | try { |
| 7582 | UiccCard uiccCard = phone.getUiccCard(); |
| 7583 | if (uiccCard == null) { |
| 7584 | return false; |
| 7585 | } |
| 7586 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7587 | if (uiccProfile == null) { |
| 7588 | return false; |
| 7589 | } |
| 7590 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 7591 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 7592 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 7593 | } |
| 7594 | return false; |
| 7595 | } finally { |
| 7596 | Binder.restoreCallingIdentity(identity); |
| 7597 | } |
| 7598 | } |
| 7599 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7600 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7601 | * Get whether making changes to modem configurations will trigger reboot. |
| 7602 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 7603 | */ |
| 7604 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7605 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 7606 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7607 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7608 | mApp, subId, callingPackage, callingFeatureId, |
| 7609 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7610 | return false; |
| 7611 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 7612 | final long identity = Binder.clearCallingIdentity(); |
| 7613 | try { |
| 7614 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 7615 | } finally { |
| 7616 | Binder.restoreCallingIdentity(identity); |
| 7617 | } |
| 7618 | } |
| 7619 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 7620 | private void updateModemStateMetrics() { |
| 7621 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 7622 | // TODO: check the state for each modem if the api is ready. |
| 7623 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 7624 | } |
| 7625 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 7626 | @Override |
| 7627 | public int[] getSlotsMapping() { |
| 7628 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 7629 | |
| 7630 | final long identity = Binder.clearCallingIdentity(); |
| 7631 | try { |
| 7632 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 7633 | // All logical slots should have a mapping to a physical slot. |
| 7634 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 7635 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 7636 | for (int i = 0; i < slotInfos.length; i++) { |
| 7637 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 7638 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 7639 | } |
| 7640 | } |
| 7641 | return logicalSlotsMapping; |
| 7642 | } finally { |
| 7643 | Binder.restoreCallingIdentity(identity); |
| 7644 | } |
| 7645 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 7646 | |
| 7647 | /** |
| 7648 | * Get the IRadio HAL Version |
| 7649 | */ |
| 7650 | @Override |
| 7651 | public int getRadioHalVersion() { |
| 7652 | Phone phone = getDefaultPhone(); |
| 7653 | if (phone == null) return -1; |
| 7654 | HalVersion hv = phone.getHalVersion(); |
| 7655 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 7656 | return hv.major * 100 + hv.minor; |
| 7657 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7658 | |
| 7659 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7660 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 7661 | * corresponding network requests on a subId. |
| 7662 | * |
| 7663 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7664 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7665 | * 2) APN is un-metered for this subscription, or |
| 7666 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 7667 | * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7668 | * |
| 7669 | * @return whether data is allowed for a apn type. |
| 7670 | * |
| 7671 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7672 | */ |
| 7673 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7674 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 7675 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 7676 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7677 | |
| 7678 | // Now that all security checks passes, perform the operation as ourselves. |
| 7679 | final long identity = Binder.clearCallingIdentity(); |
| 7680 | try { |
| 7681 | Phone phone = getPhone(subId); |
| 7682 | if (phone == null) return false; |
| 7683 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7684 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7685 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 7686 | } finally { |
| 7687 | Binder.restoreCallingIdentity(identity); |
| 7688 | } |
| 7689 | } |
| 7690 | |
| 7691 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7692 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7693 | enforceReadPrivilegedPermission("isApnMetered"); |
| 7694 | |
| 7695 | // Now that all security checks passes, perform the operation as ourselves. |
| 7696 | final long identity = Binder.clearCallingIdentity(); |
| 7697 | try { |
| 7698 | Phone phone = getPhone(subId); |
| 7699 | if (phone == null) return true; // By default return true. |
| 7700 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7701 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7702 | } finally { |
| 7703 | Binder.restoreCallingIdentity(identity); |
| 7704 | } |
| 7705 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 7706 | |
| 7707 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 7708 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
| 7709 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 7710 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 7711 | if (iccRecords == null) { |
| 7712 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 7713 | return false; |
| 7714 | } |
| 7715 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 7716 | } |
| 7717 | |
| 7718 | @Override |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 7719 | public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) { |
| 7720 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 7721 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
| 7722 | if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) { |
| 7723 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 7724 | } |
| 7725 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 7726 | Intent intent = new Intent(); |
| 7727 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 7728 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 7729 | // Bring up choose default SMS subscription dialog right now |
| 7730 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 7731 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 7732 | mApp.startActivity(intent); |
| 7733 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 7734 | |
| 7735 | @Override |
| 7736 | public String getMmsUAProfUrl(int subId) { |
| 7737 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 7738 | final long identity = Binder.clearCallingIdentity(); |
| 7739 | try { |
| 7740 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 7741 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 7742 | } finally { |
| 7743 | Binder.restoreCallingIdentity(identity); |
| 7744 | } |
| 7745 | } |
| 7746 | |
| 7747 | @Override |
| 7748 | public String getMmsUserAgent(int subId) { |
| 7749 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 7750 | final long identity = Binder.clearCallingIdentity(); |
| 7751 | try { |
| 7752 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 7753 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 7754 | } finally { |
| 7755 | Binder.restoreCallingIdentity(identity); |
| 7756 | } |
| 7757 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 7758 | |
| 7759 | @Override |
| 7760 | public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) { |
| 7761 | enforceModifyPermission(); |
| 7762 | |
| 7763 | // Now that all security checks passes, perform the operation as ourselves. |
| 7764 | final long identity = Binder.clearCallingIdentity(); |
| 7765 | try { |
| 7766 | Phone phone = getPhone(subId); |
| 7767 | if (phone == null) return false; |
| 7768 | |
| 7769 | return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow); |
| 7770 | } finally { |
| 7771 | Binder.restoreCallingIdentity(identity); |
| 7772 | } |
| 7773 | } |
| 7774 | |
| 7775 | @Override |
| 7776 | public boolean isDataAllowedInVoiceCall(int subId) { |
| 7777 | enforceReadPrivilegedPermission("isDataAllowedInVoiceCall"); |
| 7778 | |
| 7779 | // Now that all security checks passes, perform the operation as ourselves. |
| 7780 | final long identity = Binder.clearCallingIdentity(); |
| 7781 | try { |
| 7782 | Phone phone = getPhone(subId); |
| 7783 | if (phone == null) return false; |
| 7784 | |
| 7785 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 7786 | } finally { |
| 7787 | Binder.restoreCallingIdentity(identity); |
| 7788 | } |
| 7789 | } |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 7790 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 7791 | @Override |
| 7792 | public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) { |
| 7793 | enforceModifyPermission(); |
| 7794 | |
| 7795 | // Now that all security checks passes, perform the operation as ourselves. |
| 7796 | final long identity = Binder.clearCallingIdentity(); |
| 7797 | try { |
| 7798 | Phone phone = getPhone(subId); |
| 7799 | if (phone == null) return false; |
| 7800 | |
| 7801 | return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow); |
| 7802 | } finally { |
| 7803 | Binder.restoreCallingIdentity(identity); |
| 7804 | } |
| 7805 | } |
| 7806 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 7807 | /** |
| 7808 | * Updates whether conference event pacakge handling is enabled. |
| 7809 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 7810 | * otherwise. |
| 7811 | */ |
| 7812 | @Override |
| 7813 | public void setCepEnabled(boolean isCepEnabled) { |
| 7814 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 7815 | |
| 7816 | final long identity = Binder.clearCallingIdentity(); |
| 7817 | try { |
| 7818 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 7819 | for (Phone phone : PhoneFactory.getPhones()) { |
| 7820 | Phone defaultPhone = phone.getImsPhone(); |
| 7821 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 7822 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 7823 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 7824 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 7825 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 7826 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 7827 | + imsPhone.getMsisdn()); |
| 7828 | } |
| 7829 | } |
| 7830 | } finally { |
| 7831 | Binder.restoreCallingIdentity(identity); |
| 7832 | } |
| 7833 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 7834 | } |