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; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 52 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 53 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 54 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 55 | import android.os.ServiceSpecificException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 56 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 57 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 58 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 59 | import android.preference.PreferenceManager; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 60 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 61 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 62 | import android.provider.Telephony; |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 63 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 64 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 65 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 66 | import android.telecom.TelecomManager; |
Chen Xu | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 67 | import android.telephony.Annotation.ApnType; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 68 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 69 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 70 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 71 | import android.telephony.CellIdentityCdma; |
| 72 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 73 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 74 | import android.telephony.CellInfoGsm; |
| 75 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 76 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 77 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 78 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 79 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 80 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 81 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 82 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 83 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 84 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 85 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 86 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 87 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 88 | import android.telephony.SignalStrength; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 89 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 90 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 91 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 92 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 93 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 94 | import android.telephony.TelephonyScanManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 95 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 96 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 97 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 98 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 99 | import android.telephony.data.ApnSetting; |
| 100 | import android.telephony.emergency.EmergencyNumber; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 101 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 102 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 103 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 104 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 105 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 106 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 107 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 108 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 109 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 110 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 111 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 112 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 113 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 114 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 115 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 116 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 117 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 118 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 119 | import android.util.Pair; |
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; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame^] | 132 | import com.android.internal.telephony.IBooleanConsumer; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 134 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 136 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 142 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 151 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 152 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 156 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 158 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 159 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 162 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 164 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 165 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 168 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 169 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 170 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 172 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 173 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 174 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 175 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 176 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 177 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 178 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 179 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 180 | import java.io.FileDescriptor; |
| 181 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 182 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 183 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 184 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 185 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 186 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 187 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 188 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 189 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 190 | import java.util.Set; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame^] | 191 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 192 | |
| 193 | /** |
| 194 | * Implementation of the ITelephony interface. |
| 195 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 196 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 197 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 198 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 199 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 200 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 201 | |
| 202 | // Message codes used with mMainThreadHandler |
| 203 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 204 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 205 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 206 | private static final int CMD_OPEN_CHANNEL = 9; |
| 207 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 208 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 209 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 210 | private static final int CMD_NV_READ_ITEM = 13; |
| 211 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 212 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 213 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 214 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 215 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 216 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 217 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 218 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 219 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 220 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 221 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 222 | private static final int CMD_SEND_ENVELOPE = 25; |
| 223 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 224 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 225 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 226 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 227 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 228 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 229 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 230 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 231 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 232 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 233 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 234 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 235 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 236 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 237 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 238 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 239 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 240 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 241 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 242 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 243 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 244 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 245 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 246 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 247 | private static final int CMD_SWITCH_SLOTS = 50; |
| 248 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 249 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 250 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 251 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 252 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 253 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 254 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 255 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 256 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 257 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 258 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 259 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 260 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 261 | private static final int CMD_MODEM_REBOOT = 64; |
| 262 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 263 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 264 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 265 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 266 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 267 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 268 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 269 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 270 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 271 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 272 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 273 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 274 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 275 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 276 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame^] | 277 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 278 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 279 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 280 | // Parameters of select command. |
| 281 | private static final int SELECT_COMMAND = 0xA4; |
| 282 | private static final int SELECT_P1 = 0x04; |
| 283 | private static final int SELECT_P2 = 0; |
| 284 | private static final int SELECT_P3 = 0x10; |
| 285 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 286 | /** The singleton instance. */ |
| 287 | private static PhoneInterfaceManager sInstance; |
| 288 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 289 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 290 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 291 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 292 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 293 | private AppOpsManager mAppOps; |
| 294 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 295 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 296 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 297 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 298 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 299 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 300 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 301 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 302 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 303 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 304 | // String to store multi SIM allowed |
| 305 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 306 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 307 | // The AID of ISD-R. |
| 308 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 309 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 310 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 311 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 312 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 313 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 314 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 315 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 316 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 317 | */ |
| 318 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 319 | "reset_network_erase_modem_config_enabled"; |
| 320 | |
| 321 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 322 | * A request object to use for transmitting data to an ICC. |
| 323 | */ |
| 324 | private static final class IccAPDUArgument { |
| 325 | public int channel, cla, command, p1, p2, p3; |
| 326 | public String data; |
| 327 | |
| 328 | public IccAPDUArgument(int channel, int cla, int command, |
| 329 | int p1, int p2, int p3, String data) { |
| 330 | this.channel = channel; |
| 331 | this.cla = cla; |
| 332 | this.command = command; |
| 333 | this.p1 = p1; |
| 334 | this.p2 = p2; |
| 335 | this.p3 = p3; |
| 336 | this.data = data; |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 341 | * A request object to use for transmitting data to an ICC. |
| 342 | */ |
| 343 | private static final class ManualNetworkSelectionArgument { |
| 344 | public OperatorInfo operatorInfo; |
| 345 | public boolean persistSelection; |
| 346 | |
| 347 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 348 | this.operatorInfo = operatorInfo; |
| 349 | this.persistSelection = persistSelection; |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 354 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 355 | * request after sending. The main thread will notify the request when it is complete. |
| 356 | */ |
| 357 | private static final class MainThreadRequest { |
| 358 | /** The argument to use for the request */ |
| 359 | public Object argument; |
| 360 | /** The result of the request that is run on the main thread */ |
| 361 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 362 | // The subscriber id that this request applies to. Defaults to |
| 363 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 364 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 365 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 366 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 367 | public Phone phone; |
| 368 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 369 | public WorkSource workSource; |
| 370 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 371 | public MainThreadRequest(Object argument) { |
| 372 | this.argument = argument; |
| 373 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 374 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 375 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 376 | this.argument = argument; |
| 377 | if (phone != null) { |
| 378 | this.phone = phone; |
| 379 | } |
| 380 | this.workSource = workSource; |
| 381 | } |
| 382 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 383 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 384 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 385 | if (subId != null) { |
| 386 | this.subId = subId; |
| 387 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 388 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 389 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 390 | } |
| 391 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 392 | private static final class IncomingThirdPartyCallArgs { |
| 393 | public final ComponentName component; |
| 394 | public final String callId; |
| 395 | public final String callerDisplayName; |
| 396 | |
| 397 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 398 | String callerDisplayName) { |
| 399 | this.component = component; |
| 400 | this.callId = callId; |
| 401 | this.callerDisplayName = callerDisplayName; |
| 402 | } |
| 403 | } |
| 404 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 405 | /** |
| 406 | * A handler that processes messages on the main thread in the phone process. Since many |
| 407 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 408 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 409 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 410 | * on, which will be notified when the operation completes and will contain the result of the |
| 411 | * request. |
| 412 | * |
| 413 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 414 | * note that request.result must be set to something non-null for the calling thread to |
| 415 | * unblock. |
| 416 | */ |
| 417 | private final class MainThreadHandler extends Handler { |
| 418 | @Override |
| 419 | public void handleMessage(Message msg) { |
| 420 | MainThreadRequest request; |
| 421 | Message onCompleted; |
| 422 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 423 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 424 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 425 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 426 | |
| 427 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 428 | case CMD_HANDLE_USSD_REQUEST: { |
| 429 | request = (MainThreadRequest) msg.obj; |
| 430 | final Phone phone = getPhoneFromRequest(request); |
| 431 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 432 | String ussdRequest = ussdObject.first; |
| 433 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 434 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 435 | if (!isUssdApiAllowed(request.subId)) { |
| 436 | // Carrier does not support use of this API, return failure. |
| 437 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 438 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 439 | Bundle returnData = new Bundle(); |
| 440 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 441 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 442 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 443 | request.result = true; |
| 444 | notifyRequester(request); |
| 445 | return; |
| 446 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 447 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 448 | try { |
| 449 | request.result = phone != null |
| 450 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 451 | } catch (CallStateException cse) { |
| 452 | request.result = false; |
| 453 | } |
| 454 | // Wake up the requesting thread |
| 455 | notifyRequester(request); |
| 456 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 457 | } |
| 458 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 459 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 460 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 461 | final Phone phone = getPhoneFromRequest(request); |
| 462 | request.result = phone != null ? |
| 463 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 464 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 465 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 466 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 467 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 468 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 469 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 470 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 471 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 472 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 473 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 474 | if (uiccCard == null) { |
| 475 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 476 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 477 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 478 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 479 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 480 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 481 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 482 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 483 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 484 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 485 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 486 | break; |
| 487 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 488 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 489 | ar = (AsyncResult) msg.obj; |
| 490 | request = (MainThreadRequest) ar.userObj; |
| 491 | if (ar.exception == null && ar.result != null) { |
| 492 | request.result = ar.result; |
| 493 | } else { |
| 494 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 495 | if (ar.result == null) { |
| 496 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 497 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 498 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 499 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 500 | } else { |
| 501 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 502 | } |
| 503 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 504 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 505 | break; |
| 506 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 507 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 508 | request = (MainThreadRequest) msg.obj; |
| 509 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 510 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 511 | if (uiccCard == null) { |
| 512 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 513 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 514 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 515 | } else { |
| 516 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 517 | request); |
| 518 | uiccCard.iccTransmitApduBasicChannel( |
| 519 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 520 | iccArgument.p3, iccArgument.data, onCompleted); |
| 521 | } |
| 522 | break; |
| 523 | |
| 524 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 525 | ar = (AsyncResult) msg.obj; |
| 526 | request = (MainThreadRequest) ar.userObj; |
| 527 | if (ar.exception == null && ar.result != null) { |
| 528 | request.result = ar.result; |
| 529 | } else { |
| 530 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 531 | if (ar.result == null) { |
| 532 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 533 | } else if (ar.exception instanceof CommandException) { |
| 534 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 535 | ar.exception); |
| 536 | } else { |
| 537 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 538 | } |
| 539 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 540 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 541 | break; |
| 542 | |
| 543 | case CMD_EXCHANGE_SIM_IO: |
| 544 | request = (MainThreadRequest) msg.obj; |
| 545 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 546 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 547 | if (uiccCard == null) { |
| 548 | loge("iccExchangeSimIO: No UICC"); |
| 549 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 550 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 551 | } else { |
| 552 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 553 | request); |
| 554 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 555 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 556 | iccArgument.data, onCompleted); |
| 557 | } |
| 558 | break; |
| 559 | |
| 560 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 561 | ar = (AsyncResult) msg.obj; |
| 562 | request = (MainThreadRequest) ar.userObj; |
| 563 | if (ar.exception == null && ar.result != null) { |
| 564 | request.result = ar.result; |
| 565 | } else { |
| 566 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 567 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 568 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 569 | break; |
| 570 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 571 | case CMD_SEND_ENVELOPE: |
| 572 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 573 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 574 | if (uiccCard == null) { |
| 575 | loge("sendEnvelopeWithStatus: No UICC"); |
| 576 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 577 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 578 | } else { |
| 579 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 580 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 581 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 582 | break; |
| 583 | |
| 584 | case EVENT_SEND_ENVELOPE_DONE: |
| 585 | ar = (AsyncResult) msg.obj; |
| 586 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 587 | if (ar.exception == null && ar.result != null) { |
| 588 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 589 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 590 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 591 | if (ar.result == null) { |
| 592 | loge("sendEnvelopeWithStatus: Empty response"); |
| 593 | } else if (ar.exception instanceof CommandException) { |
| 594 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 595 | ar.exception); |
| 596 | } else { |
| 597 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 598 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 599 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 600 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 601 | break; |
| 602 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 603 | case CMD_OPEN_CHANNEL: |
| 604 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 605 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 606 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 607 | if (uiccCard == null) { |
| 608 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 609 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 610 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 611 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 612 | } else { |
| 613 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 614 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 615 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 616 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 617 | break; |
| 618 | |
| 619 | case EVENT_OPEN_CHANNEL_DONE: |
| 620 | ar = (AsyncResult) msg.obj; |
| 621 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 622 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 623 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 624 | int[] result = (int[]) ar.result; |
| 625 | int channelId = result[0]; |
| 626 | byte[] selectResponse = null; |
| 627 | if (result.length > 1) { |
| 628 | selectResponse = new byte[result.length - 1]; |
| 629 | for (int i = 1; i < result.length; ++i) { |
| 630 | selectResponse[i - 1] = (byte) result[i]; |
| 631 | } |
| 632 | } |
| 633 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 634 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 635 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 636 | if (ar.result == null) { |
| 637 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 638 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 639 | if (ar.exception != null) { |
| 640 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 641 | } |
| 642 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 643 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 644 | if (ar.exception instanceof CommandException) { |
| 645 | CommandException.Error error = |
| 646 | ((CommandException) (ar.exception)).getCommandError(); |
| 647 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 648 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 649 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 650 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 651 | } |
| 652 | } |
| 653 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 654 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 655 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 656 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 657 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 658 | break; |
| 659 | |
| 660 | case CMD_CLOSE_CHANNEL: |
| 661 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 662 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 663 | if (uiccCard == null) { |
| 664 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 665 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 666 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 667 | } else { |
| 668 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 669 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 670 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 671 | break; |
| 672 | |
| 673 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 674 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 675 | break; |
| 676 | |
| 677 | case CMD_NV_READ_ITEM: |
| 678 | request = (MainThreadRequest) msg.obj; |
| 679 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 680 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 681 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 682 | break; |
| 683 | |
| 684 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 685 | ar = (AsyncResult) msg.obj; |
| 686 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 687 | if (ar.exception == null && ar.result != null) { |
| 688 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 689 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 690 | request.result = ""; |
| 691 | if (ar.result == null) { |
| 692 | loge("nvReadItem: Empty response"); |
| 693 | } else if (ar.exception instanceof CommandException) { |
| 694 | loge("nvReadItem: CommandException: " + |
| 695 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 696 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 697 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 698 | } |
| 699 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 700 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 701 | break; |
| 702 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 703 | case CMD_NV_WRITE_ITEM: |
| 704 | request = (MainThreadRequest) msg.obj; |
| 705 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 706 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 707 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 708 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 709 | break; |
| 710 | |
| 711 | case EVENT_NV_WRITE_ITEM_DONE: |
| 712 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 713 | break; |
| 714 | |
| 715 | case CMD_NV_WRITE_CDMA_PRL: |
| 716 | request = (MainThreadRequest) msg.obj; |
| 717 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 718 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 719 | break; |
| 720 | |
| 721 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 722 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 723 | break; |
| 724 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 725 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 726 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 727 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 728 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 729 | break; |
| 730 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 731 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 732 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 733 | break; |
| 734 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 735 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 736 | request = (MainThreadRequest) msg.obj; |
| 737 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 738 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 739 | break; |
| 740 | |
| 741 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 742 | ar = (AsyncResult) msg.obj; |
| 743 | request = (MainThreadRequest) ar.userObj; |
| 744 | if (ar.exception == null && ar.result != null) { |
| 745 | request.result = ar.result; // Integer |
| 746 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 747 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 748 | if (ar.result == null) { |
| 749 | loge("getPreferredNetworkType: Empty response"); |
| 750 | } else if (ar.exception instanceof CommandException) { |
| 751 | loge("getPreferredNetworkType: CommandException: " + |
| 752 | ar.exception); |
| 753 | } else { |
| 754 | loge("getPreferredNetworkType: Unknown exception"); |
| 755 | } |
| 756 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 757 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 758 | break; |
| 759 | |
| 760 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 761 | request = (MainThreadRequest) msg.obj; |
| 762 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 763 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 764 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 765 | break; |
| 766 | |
| 767 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 768 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 769 | break; |
| 770 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 771 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 772 | request = (MainThreadRequest)msg.obj; |
| 773 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 774 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 775 | break; |
| 776 | |
| 777 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 778 | ar = (AsyncResult)msg.obj; |
| 779 | request = (MainThreadRequest)ar.userObj; |
| 780 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 781 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 782 | break; |
| 783 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 784 | case CMD_SET_VOICEMAIL_NUMBER: |
| 785 | request = (MainThreadRequest) msg.obj; |
| 786 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 787 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 788 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 789 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 790 | break; |
| 791 | |
| 792 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 793 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 794 | break; |
| 795 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 796 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 797 | request = (MainThreadRequest) msg.obj; |
| 798 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 799 | request); |
| 800 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 801 | break; |
| 802 | |
| 803 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 804 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 805 | break; |
| 806 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 807 | case CMD_PERFORM_NETWORK_SCAN: |
| 808 | request = (MainThreadRequest) msg.obj; |
| 809 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 810 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 811 | break; |
| 812 | |
| 813 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 814 | ar = (AsyncResult) msg.obj; |
| 815 | request = (MainThreadRequest) ar.userObj; |
| 816 | CellNetworkScanResult cellScanResult; |
| 817 | if (ar.exception == null && ar.result != null) { |
| 818 | cellScanResult = new CellNetworkScanResult( |
| 819 | CellNetworkScanResult.STATUS_SUCCESS, |
| 820 | (List<OperatorInfo>) ar.result); |
| 821 | } else { |
| 822 | if (ar.result == null) { |
| 823 | loge("getCellNetworkScanResults: Empty response"); |
| 824 | } |
| 825 | if (ar.exception != null) { |
| 826 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 827 | } |
| 828 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 829 | if (ar.exception instanceof CommandException) { |
| 830 | CommandException.Error error = |
| 831 | ((CommandException) (ar.exception)).getCommandError(); |
| 832 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 833 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 834 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 835 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 836 | } |
| 837 | } |
| 838 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 839 | } |
| 840 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 841 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 842 | break; |
| 843 | |
| 844 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 845 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 846 | ManualNetworkSelectionArgument selArg = |
| 847 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 848 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 849 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 850 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 851 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 852 | break; |
| 853 | |
| 854 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 855 | ar = (AsyncResult) msg.obj; |
| 856 | request = (MainThreadRequest) ar.userObj; |
| 857 | if (ar.exception == null) { |
| 858 | request.result = true; |
| 859 | } else { |
| 860 | request.result = false; |
| 861 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 862 | } |
| 863 | notifyRequester(request); |
| 864 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 865 | break; |
| 866 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 867 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 868 | request = (MainThreadRequest) msg.obj; |
| 869 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 870 | if (defaultPhone != null) { |
| 871 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
| 872 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 873 | break; |
| 874 | |
| 875 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 876 | ar = (AsyncResult) msg.obj; |
| 877 | request = (MainThreadRequest) ar.userObj; |
| 878 | if (ar.exception == null && ar.result != null) { |
| 879 | request.result = ar.result; |
| 880 | } else { |
| 881 | if (ar.result == null) { |
| 882 | loge("queryModemActivityInfo: Empty response"); |
| 883 | } else if (ar.exception instanceof CommandException) { |
| 884 | loge("queryModemActivityInfo: CommandException: " + |
| 885 | ar.exception); |
| 886 | } else { |
| 887 | loge("queryModemActivityInfo: Unknown exception"); |
| 888 | } |
| 889 | } |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 890 | // Result cannot be null. Return ModemActivityInfo with all fields set to 0. |
| 891 | if (request.result == null) { |
Peter Collingbourne | c00e902 | 2019-11-26 09:56:26 -0800 | [diff] [blame] | 892 | request.result = new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Amit Mahajan | d476622 | 2016-01-28 15:28:28 -0800 | [diff] [blame] | 893 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 894 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 895 | break; |
| 896 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 897 | case CMD_SET_ALLOWED_CARRIERS: |
| 898 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 899 | CarrierRestrictionRules argument = |
| 900 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 901 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 902 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 903 | break; |
| 904 | |
| 905 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 906 | ar = (AsyncResult) msg.obj; |
| 907 | request = (MainThreadRequest) ar.userObj; |
| 908 | if (ar.exception == null && ar.result != null) { |
| 909 | request.result = ar.result; |
| 910 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 911 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 912 | if (ar.exception instanceof CommandException) { |
| 913 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 914 | CommandException.Error error = |
| 915 | ((CommandException) (ar.exception)).getCommandError(); |
| 916 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 917 | request.result = |
| 918 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 919 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 920 | } else { |
| 921 | loge("setAllowedCarriers: Unknown exception"); |
| 922 | } |
| 923 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 924 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 925 | break; |
| 926 | |
| 927 | case CMD_GET_ALLOWED_CARRIERS: |
| 928 | request = (MainThreadRequest) msg.obj; |
| 929 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 930 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 931 | break; |
| 932 | |
| 933 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 934 | ar = (AsyncResult) msg.obj; |
| 935 | request = (MainThreadRequest) ar.userObj; |
| 936 | if (ar.exception == null && ar.result != null) { |
| 937 | request.result = ar.result; |
| 938 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 939 | request.result = new IllegalStateException( |
| 940 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 941 | if (ar.result == null) { |
| 942 | loge("getAllowedCarriers: Empty response"); |
| 943 | } else if (ar.exception instanceof CommandException) { |
| 944 | loge("getAllowedCarriers: CommandException: " + |
| 945 | ar.exception); |
| 946 | } else { |
| 947 | loge("getAllowedCarriers: Unknown exception"); |
| 948 | } |
| 949 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 950 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 951 | break; |
| 952 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 953 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 954 | ar = (AsyncResult) msg.obj; |
| 955 | request = (MainThreadRequest) ar.userObj; |
| 956 | if (ar.exception == null && ar.result != null) { |
| 957 | request.result = ar.result; |
| 958 | } else { |
| 959 | request.result = new IllegalArgumentException( |
| 960 | "Failed to retrieve Forbidden Plmns"); |
| 961 | if (ar.result == null) { |
| 962 | loge("getForbiddenPlmns: Empty response"); |
| 963 | } else { |
| 964 | loge("getForbiddenPlmns: Unknown exception"); |
| 965 | } |
| 966 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 967 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 968 | break; |
| 969 | |
| 970 | case CMD_GET_FORBIDDEN_PLMNS: |
| 971 | request = (MainThreadRequest) msg.obj; |
| 972 | uiccCard = getUiccCardFromRequest(request); |
| 973 | if (uiccCard == null) { |
| 974 | loge("getForbiddenPlmns() UiccCard is null"); |
| 975 | request.result = new IllegalArgumentException( |
| 976 | "getForbiddenPlmns() UiccCard is null"); |
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 | } |
| 980 | Integer appType = (Integer) request.argument; |
| 981 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 982 | if (uiccApp == null) { |
| 983 | loge("getForbiddenPlmns() no app with specified type -- " |
| 984 | + appType); |
| 985 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 986 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 987 | break; |
| 988 | } else { |
| 989 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 990 | + " specified type -- " + appType); |
| 991 | } |
| 992 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 993 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 994 | onCompleted); |
| 995 | break; |
| 996 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 997 | case CMD_SWITCH_SLOTS: |
| 998 | request = (MainThreadRequest) msg.obj; |
| 999 | int[] physicalSlots = (int[]) request.argument; |
| 1000 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1001 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1002 | break; |
| 1003 | |
| 1004 | case EVENT_SWITCH_SLOTS_DONE: |
| 1005 | ar = (AsyncResult) msg.obj; |
| 1006 | request = (MainThreadRequest) ar.userObj; |
| 1007 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1008 | notifyRequester(request); |
| 1009 | break; |
| 1010 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1011 | request = (MainThreadRequest) msg.obj; |
| 1012 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1013 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1014 | break; |
| 1015 | |
| 1016 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1017 | ar = (AsyncResult) msg.obj; |
| 1018 | request = (MainThreadRequest) ar.userObj; |
| 1019 | if (ar.exception != null) { |
| 1020 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1021 | } else { |
| 1022 | int mode = ((int[]) ar.result)[0]; |
| 1023 | if (mode == 0) { |
| 1024 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1025 | } else { |
| 1026 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1027 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1028 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1029 | notifyRequester(request); |
| 1030 | break; |
| 1031 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1032 | request = (MainThreadRequest) msg.obj; |
| 1033 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1034 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1035 | break; |
| 1036 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1037 | ar = (AsyncResult) msg.obj; |
| 1038 | request = (MainThreadRequest) ar.userObj; |
| 1039 | if (ar.exception != null) { |
| 1040 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1041 | } else { |
| 1042 | request.result = ((int[]) ar.result)[0]; |
| 1043 | } |
| 1044 | notifyRequester(request); |
| 1045 | break; |
| 1046 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1047 | request = (MainThreadRequest) msg.obj; |
| 1048 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1049 | int mode = (int) request.argument; |
| 1050 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1051 | break; |
| 1052 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1053 | ar = (AsyncResult) msg.obj; |
| 1054 | request = (MainThreadRequest) ar.userObj; |
| 1055 | request.result = ar.exception == null; |
| 1056 | notifyRequester(request); |
| 1057 | break; |
| 1058 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1059 | request = (MainThreadRequest) msg.obj; |
| 1060 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1061 | int subscriptionMode = (int) request.argument; |
| 1062 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1063 | break; |
| 1064 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1065 | ar = (AsyncResult) msg.obj; |
| 1066 | request = (MainThreadRequest) ar.userObj; |
| 1067 | request.result = ar.exception == null; |
| 1068 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1069 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1070 | case CMD_GET_ALL_CELL_INFO: |
| 1071 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1072 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1073 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1074 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1075 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1076 | ar = (AsyncResult) msg.obj; |
| 1077 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1078 | // If a timeout occurs, the response will be null |
| 1079 | request.result = (ar.exception == null && ar.result != null) |
| 1080 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1081 | synchronized (request) { |
| 1082 | request.notifyAll(); |
| 1083 | } |
| 1084 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1085 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1086 | request = (MainThreadRequest) msg.obj; |
| 1087 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1088 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1089 | break; |
| 1090 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1091 | ar = (AsyncResult) msg.obj; |
| 1092 | request = (MainThreadRequest) ar.userObj; |
| 1093 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1094 | try { |
| 1095 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1096 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1097 | cb.onError( |
| 1098 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1099 | ar.exception.getClass().getName(), |
| 1100 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1101 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1102 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1103 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1104 | } else { |
| 1105 | // use the result as returned |
| 1106 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1107 | } |
| 1108 | } catch (RemoteException re) { |
| 1109 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1110 | } |
| 1111 | break; |
| 1112 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1113 | request = (MainThreadRequest) msg.obj; |
| 1114 | WorkSource ws = (WorkSource) request.argument; |
| 1115 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1116 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1117 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1118 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1119 | ar = (AsyncResult) msg.obj; |
| 1120 | request = (MainThreadRequest) ar.userObj; |
| 1121 | if (ar.exception == null) { |
| 1122 | request.result = ar.result; |
| 1123 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1124 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1125 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1126 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | synchronized (request) { |
| 1130 | request.notifyAll(); |
| 1131 | } |
| 1132 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1133 | case CMD_MODEM_REBOOT: |
| 1134 | request = (MainThreadRequest) msg.obj; |
| 1135 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1136 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1137 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1138 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1139 | handleNullReturnEvent(msg, "rebootModem"); |
| 1140 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1141 | case CMD_REQUEST_ENABLE_MODEM: |
| 1142 | request = (MainThreadRequest) msg.obj; |
| 1143 | boolean enable = (boolean) request.argument; |
| 1144 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1145 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1146 | PhoneConfigurationManager.getInstance() |
| 1147 | .enablePhone(request.phone, enable, onCompleted); |
| 1148 | break; |
| 1149 | case EVENT_ENABLE_MODEM_DONE: |
| 1150 | ar = (AsyncResult) msg.obj; |
| 1151 | request = (MainThreadRequest) ar.userObj; |
| 1152 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1153 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1154 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1155 | if ((boolean) request.result) { |
| 1156 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1157 | updateModemStateMetrics(); |
| 1158 | } else { |
| 1159 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1160 | + ar.exception); |
| 1161 | } |
| 1162 | notifyRequester(request); |
| 1163 | break; |
| 1164 | case CMD_GET_MODEM_STATUS: |
| 1165 | request = (MainThreadRequest) msg.obj; |
| 1166 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1167 | PhoneConfigurationManager.getInstance() |
| 1168 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1169 | break; |
| 1170 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1171 | ar = (AsyncResult) msg.obj; |
| 1172 | request = (MainThreadRequest) ar.userObj; |
| 1173 | int id = request.phone.getPhoneId(); |
| 1174 | if (ar.exception == null && ar.result != null) { |
| 1175 | request.result = ar.result; |
| 1176 | //update the cache as modem status has changed |
| 1177 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1178 | (boolean) request.result); |
| 1179 | } else { |
| 1180 | // Return true if modem status cannot be retrieved. For most cases, |
| 1181 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1182 | // and disable modem are not supported. Modem is always on. |
| 1183 | // TODO: this should be fixed in R to support a third |
| 1184 | // status UNKNOWN b/131631629 |
| 1185 | request.result = true; |
| 1186 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1187 | + ar.exception); |
| 1188 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1189 | notifyRequester(request); |
| 1190 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame^] | 1191 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1192 | request = (MainThreadRequest) msg.obj; |
| 1193 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1194 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1195 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1196 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1197 | break; |
| 1198 | } |
| 1199 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1200 | ar = (AsyncResult) msg.obj; |
| 1201 | request = (MainThreadRequest) ar.userObj; |
| 1202 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1203 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1204 | args.second.accept(ar.exception == null); |
| 1205 | notifyRequester(request); |
| 1206 | break; |
| 1207 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1208 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1209 | ar = (AsyncResult) msg.obj; |
| 1210 | request = (MainThreadRequest) ar.userObj; |
| 1211 | if (ar.exception == null && ar.result != null) { |
| 1212 | request.result = ar.result; |
| 1213 | } else { |
| 1214 | request.result = -1; |
| 1215 | loge("Failed to set Forbidden Plmns"); |
| 1216 | if (ar.result == null) { |
| 1217 | loge("setForbidenPlmns: Empty response"); |
| 1218 | } else if (ar.exception != null) { |
| 1219 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1220 | request.result = -1; |
| 1221 | } else { |
| 1222 | loge("setForbiddenPlmns: Unknown exception"); |
| 1223 | } |
| 1224 | } |
| 1225 | notifyRequester(request); |
| 1226 | break; |
| 1227 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1228 | request = (MainThreadRequest) msg.obj; |
| 1229 | uiccCard = getUiccCardFromRequest(request); |
| 1230 | if (uiccCard == null) { |
| 1231 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1232 | request.result = -1; |
| 1233 | notifyRequester(request); |
| 1234 | break; |
| 1235 | } |
| 1236 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1237 | (Pair<Integer, List<String>>) request.argument; |
| 1238 | appType = setFplmnsArgs.first; |
| 1239 | List<String> fplmns = setFplmnsArgs.second; |
| 1240 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1241 | if (uiccApp == null) { |
| 1242 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1243 | request.result = -1; |
| 1244 | loge("Failed to get UICC App"); |
| 1245 | notifyRequester(request); |
| 1246 | } else { |
| 1247 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1248 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1249 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1250 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1251 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1252 | case CMD_ERASE_MODEM_CONFIG: |
| 1253 | request = (MainThreadRequest) msg.obj; |
| 1254 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1255 | defaultPhone.eraseModemConfig(onCompleted); |
| 1256 | break; |
| 1257 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1258 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1259 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1260 | |
| 1261 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1262 | request = (MainThreadRequest) msg.obj; |
| 1263 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1264 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1265 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1266 | changed.first, changed.second, onCompleted); |
| 1267 | break; |
| 1268 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1269 | ar = (AsyncResult) msg.obj; |
| 1270 | request = (MainThreadRequest) ar.userObj; |
| 1271 | if (ar.exception == null) { |
| 1272 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1273 | } else { |
| 1274 | request.result = msg.arg1; |
| 1275 | } |
| 1276 | notifyRequester(request); |
| 1277 | break; |
| 1278 | |
| 1279 | case CMD_SET_ICC_LOCK_ENABLED: |
| 1280 | request = (MainThreadRequest) msg.obj; |
| 1281 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1282 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1283 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1284 | enabled.first, enabled.second, onCompleted); |
| 1285 | break; |
| 1286 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1287 | ar = (AsyncResult) msg.obj; |
| 1288 | request = (MainThreadRequest) ar.userObj; |
| 1289 | if (ar.exception == null) { |
| 1290 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1291 | } else { |
| 1292 | request.result = msg.arg1; |
| 1293 | } |
| 1294 | notifyRequester(request); |
| 1295 | break; |
| 1296 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1297 | default: |
| 1298 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1299 | break; |
| 1300 | } |
| 1301 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1302 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1303 | private void notifyRequester(MainThreadRequest request) { |
| 1304 | synchronized (request) { |
| 1305 | request.notifyAll(); |
| 1306 | } |
| 1307 | } |
| 1308 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1309 | private void handleNullReturnEvent(Message msg, String command) { |
| 1310 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1311 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1312 | if (ar.exception == null) { |
| 1313 | request.result = true; |
| 1314 | } else { |
| 1315 | request.result = false; |
| 1316 | if (ar.exception instanceof CommandException) { |
| 1317 | loge(command + ": CommandException: " + ar.exception); |
| 1318 | } else { |
| 1319 | loge(command + ": Unknown exception"); |
| 1320 | } |
| 1321 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1322 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1323 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1324 | } |
| 1325 | |
| 1326 | /** |
| 1327 | * Posts the specified command to be executed on the main thread, |
| 1328 | * waits for the request to complete, and returns the result. |
| 1329 | * @see #sendRequestAsync |
| 1330 | */ |
| 1331 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1332 | return sendRequest( |
| 1333 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1334 | } |
| 1335 | |
| 1336 | /** |
| 1337 | * Posts the specified command to be executed on the main thread, |
| 1338 | * waits for the request to complete, and returns the result. |
| 1339 | * @see #sendRequestAsync |
| 1340 | */ |
| 1341 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1342 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1343 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1344 | } |
| 1345 | |
| 1346 | /** |
| 1347 | * Posts the specified command to be executed on the main thread, |
| 1348 | * waits for the request to complete, and returns the result. |
| 1349 | * @see #sendRequestAsync |
| 1350 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1351 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1352 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1353 | } |
| 1354 | |
| 1355 | /** |
| 1356 | * Posts the specified command to be executed on the main thread, |
| 1357 | * waits for the request to complete, and returns the result. |
| 1358 | * @see #sendRequestAsync |
| 1359 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1360 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1361 | return sendRequest(command, argument, subId, null, workSource); |
| 1362 | } |
| 1363 | |
| 1364 | /** |
| 1365 | * Posts the specified command to be executed on the main thread, |
| 1366 | * waits for the request to complete, and returns the result. |
| 1367 | * @see #sendRequestAsync |
| 1368 | */ |
| 1369 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1370 | return sendRequest( |
| 1371 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1372 | } |
| 1373 | |
| 1374 | /** |
| 1375 | * Posts the specified command to be executed on the main thread, |
| 1376 | * waits for the request to complete, and returns the result. |
| 1377 | * @see #sendRequestAsync |
| 1378 | */ |
| 1379 | private Object sendRequest( |
| 1380 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1381 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1382 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1383 | } |
| 1384 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1385 | MainThreadRequest request = null; |
| 1386 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1387 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1388 | } else if (phone != null) { |
| 1389 | request = new MainThreadRequest(argument, phone, workSource); |
| 1390 | } else { |
| 1391 | request = new MainThreadRequest(argument, subId, workSource); |
| 1392 | } |
| 1393 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1394 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1395 | msg.sendToTarget(); |
| 1396 | |
| 1397 | // Wait for the request to complete |
| 1398 | synchronized (request) { |
| 1399 | while (request.result == null) { |
| 1400 | try { |
| 1401 | request.wait(); |
| 1402 | } catch (InterruptedException e) { |
| 1403 | // Do nothing, go back and wait until the request is complete |
| 1404 | } |
| 1405 | } |
| 1406 | } |
| 1407 | return request.result; |
| 1408 | } |
| 1409 | |
| 1410 | /** |
| 1411 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1412 | * Posts the specified command to be executed on the main thread, and |
| 1413 | * returns immediately. |
| 1414 | * @see #sendRequest |
| 1415 | */ |
| 1416 | private void sendRequestAsync(int command) { |
| 1417 | mMainThreadHandler.sendEmptyMessage(command); |
| 1418 | } |
| 1419 | |
| 1420 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1421 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1422 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1423 | */ |
| 1424 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1425 | sendRequestAsync(command, argument, null, null); |
| 1426 | } |
| 1427 | |
| 1428 | /** |
| 1429 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1430 | * @see {@link #sendRequest(int,Object)} |
| 1431 | */ |
| 1432 | private void sendRequestAsync( |
| 1433 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1434 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1435 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1436 | msg.sendToTarget(); |
| 1437 | } |
| 1438 | |
| 1439 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1440 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1441 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1442 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1443 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1444 | synchronized (PhoneInterfaceManager.class) { |
| 1445 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1446 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1447 | } else { |
| 1448 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1449 | } |
| 1450 | return sInstance; |
| 1451 | } |
| 1452 | } |
| 1453 | |
| 1454 | /** Private constructor; @see init() */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1455 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1456 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1457 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1458 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1459 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1460 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1461 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1462 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1463 | mTelephonySharedPreferences = |
| 1464 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1465 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1466 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1467 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1468 | publish(); |
| 1469 | } |
| 1470 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1471 | private Phone getDefaultPhone() { |
| 1472 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1473 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1474 | } |
| 1475 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1476 | private void publish() { |
| 1477 | if (DBG) log("publish: " + this); |
| 1478 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 1479 | TelephonyFrameworkInitializer |
| 1480 | .getTelephonyServiceManager() |
| 1481 | .getTelephonyServiceRegisterer() |
| 1482 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1483 | } |
| 1484 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1485 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1486 | if (request.phone != null) { |
| 1487 | return request.phone; |
| 1488 | } else { |
| 1489 | return getPhoneFromSubId(request.subId); |
| 1490 | } |
| 1491 | } |
| 1492 | |
| 1493 | private Phone getPhoneFromSubId(int subId) { |
| 1494 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1495 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1496 | } |
| 1497 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1498 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1499 | Phone phone = getPhoneFromRequest(request); |
| 1500 | return phone == null ? null : |
| 1501 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1502 | } |
| 1503 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1504 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1505 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1506 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1507 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1508 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1509 | private void sendEraseModemConfig(Phone phone) { |
| 1510 | if (phone != null) { |
| 1511 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 1512 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 1513 | final long identity = Binder.clearCallingIdentity(); |
| 1514 | try { |
| 1515 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 1516 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 1517 | } finally { |
| 1518 | Binder.restoreCallingIdentity(identity); |
| 1519 | } |
| 1520 | } |
| 1521 | } |
| 1522 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 1523 | private boolean isImsAvailableOnDevice() { |
| 1524 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 1525 | if (pm == null) { |
| 1526 | // For some reason package manger is not available.. This will fail internally anyway, |
| 1527 | // so do not throw error and allow. |
| 1528 | return true; |
| 1529 | } |
| 1530 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 1531 | } |
| 1532 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1533 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1534 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1535 | } |
| 1536 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1537 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1538 | if (DBG) log("dial: " + number); |
| 1539 | // No permission check needed here: This is just a wrapper around the |
| 1540 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1541 | // the UI before it does anything. |
| 1542 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1543 | final long identity = Binder.clearCallingIdentity(); |
| 1544 | try { |
| 1545 | String url = createTelUrl(number); |
| 1546 | if (url == null) { |
| 1547 | return; |
| 1548 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1549 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1550 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1551 | PhoneConstants.State state = mCM.getState(subId); |
| 1552 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1553 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1554 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1555 | mApp.startActivity(intent); |
| 1556 | } |
| 1557 | } finally { |
| 1558 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1559 | } |
| 1560 | } |
| 1561 | |
| 1562 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1563 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1564 | } |
| 1565 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1566 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1567 | if (DBG) log("call: " + number); |
| 1568 | |
| 1569 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1570 | // need to do a permission check since we're calling startActivity() |
| 1571 | // from the context of the phone app. |
| 1572 | enforceCallPermission(); |
| 1573 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 1574 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1575 | != AppOpsManager.MODE_ALLOWED) { |
| 1576 | return; |
| 1577 | } |
| 1578 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1579 | final long identity = Binder.clearCallingIdentity(); |
| 1580 | try { |
| 1581 | String url = createTelUrl(number); |
| 1582 | if (url == null) { |
| 1583 | return; |
| 1584 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1585 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1586 | boolean isValid = false; |
| 1587 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1588 | if (slist != null) { |
| 1589 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1590 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1591 | isValid = true; |
| 1592 | break; |
| 1593 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1594 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1595 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1596 | if (!isValid) { |
| 1597 | return; |
| 1598 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1599 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1600 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1601 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1602 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1603 | mApp.startActivity(intent); |
| 1604 | } finally { |
| 1605 | Binder.restoreCallingIdentity(identity); |
| 1606 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1607 | } |
| 1608 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1609 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1610 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1611 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1612 | } |
| 1613 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1614 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1615 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1616 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1617 | } |
| 1618 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1619 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1620 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1621 | |
| 1622 | final long identity = Binder.clearCallingIdentity(); |
| 1623 | try { |
| 1624 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1625 | checkSimPin.start(); |
| 1626 | return checkSimPin.unlockSim(null, pin); |
| 1627 | } finally { |
| 1628 | Binder.restoreCallingIdentity(identity); |
| 1629 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1630 | } |
| 1631 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1632 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1633 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1634 | |
| 1635 | final long identity = Binder.clearCallingIdentity(); |
| 1636 | try { |
| 1637 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1638 | checkSimPuk.start(); |
| 1639 | return checkSimPuk.unlockSim(puk, pin); |
| 1640 | } finally { |
| 1641 | Binder.restoreCallingIdentity(identity); |
| 1642 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1643 | } |
| 1644 | |
| 1645 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1646 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1647 | * a synchronous one. |
| 1648 | */ |
| 1649 | private static class UnlockSim extends Thread { |
| 1650 | |
| 1651 | private final IccCard mSimCard; |
| 1652 | |
| 1653 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1654 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1655 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1656 | |
| 1657 | // For replies from SimCard interface |
| 1658 | private Handler mHandler; |
| 1659 | |
| 1660 | // For async handler to identify request type |
| 1661 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1662 | |
| 1663 | public UnlockSim(IccCard simCard) { |
| 1664 | mSimCard = simCard; |
| 1665 | } |
| 1666 | |
| 1667 | @Override |
| 1668 | public void run() { |
| 1669 | Looper.prepare(); |
| 1670 | synchronized (UnlockSim.this) { |
| 1671 | mHandler = new Handler() { |
| 1672 | @Override |
| 1673 | public void handleMessage(Message msg) { |
| 1674 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1675 | switch (msg.what) { |
| 1676 | case SUPPLY_PIN_COMPLETE: |
| 1677 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1678 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1679 | mRetryCount = msg.arg1; |
| 1680 | if (ar.exception != null) { |
| 1681 | if (ar.exception instanceof CommandException && |
| 1682 | ((CommandException)(ar.exception)).getCommandError() |
| 1683 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1684 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
| 1685 | } else { |
| 1686 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1687 | } |
| 1688 | } else { |
| 1689 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1690 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1691 | mDone = true; |
| 1692 | UnlockSim.this.notifyAll(); |
| 1693 | } |
| 1694 | break; |
| 1695 | } |
| 1696 | } |
| 1697 | }; |
| 1698 | UnlockSim.this.notifyAll(); |
| 1699 | } |
| 1700 | Looper.loop(); |
| 1701 | } |
| 1702 | |
| 1703 | /* |
| 1704 | * Use PIN or PUK to unlock SIM card |
| 1705 | * |
| 1706 | * If PUK is null, unlock SIM card with PIN |
| 1707 | * |
| 1708 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1709 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1710 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1711 | |
| 1712 | while (mHandler == null) { |
| 1713 | try { |
| 1714 | wait(); |
| 1715 | } catch (InterruptedException e) { |
| 1716 | Thread.currentThread().interrupt(); |
| 1717 | } |
| 1718 | } |
| 1719 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1720 | |
| 1721 | if (puk == null) { |
| 1722 | mSimCard.supplyPin(pin, callback); |
| 1723 | } else { |
| 1724 | mSimCard.supplyPuk(puk, pin, callback); |
| 1725 | } |
| 1726 | |
| 1727 | while (!mDone) { |
| 1728 | try { |
| 1729 | Log.d(LOG_TAG, "wait for done"); |
| 1730 | wait(); |
| 1731 | } catch (InterruptedException e) { |
| 1732 | // Restore the interrupted status |
| 1733 | Thread.currentThread().interrupt(); |
| 1734 | } |
| 1735 | } |
| 1736 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1737 | int[] resultArray = new int[2]; |
| 1738 | resultArray[0] = mResult; |
| 1739 | resultArray[1] = mRetryCount; |
| 1740 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1741 | } |
| 1742 | } |
| 1743 | |
| 1744 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1745 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1746 | |
| 1747 | } |
| 1748 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1749 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1750 | // No permission check needed here: this call is harmless, and it's |
| 1751 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1752 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1753 | final long identity = Binder.clearCallingIdentity(); |
| 1754 | try { |
| 1755 | final Phone phone = getPhone(subId); |
| 1756 | if (phone != null) { |
| 1757 | phone.updateServiceLocation(); |
| 1758 | } |
| 1759 | } finally { |
| 1760 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1761 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1762 | } |
| 1763 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1764 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1765 | @Override |
| 1766 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1767 | return isRadioOnWithFeature(callingPackage, null); |
| 1768 | } |
| 1769 | |
| 1770 | |
| 1771 | @Override |
| 1772 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 1773 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 1774 | callingFeatureId); |
| 1775 | } |
| 1776 | |
| 1777 | @Deprecated |
| 1778 | @Override |
| 1779 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 1780 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1781 | } |
| 1782 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1783 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1784 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 1785 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1786 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 1787 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1788 | return false; |
| 1789 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1790 | |
| 1791 | final long identity = Binder.clearCallingIdentity(); |
| 1792 | try { |
| 1793 | return isRadioOnForSubscriber(subId); |
| 1794 | } finally { |
| 1795 | Binder.restoreCallingIdentity(identity); |
| 1796 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1797 | } |
| 1798 | |
| 1799 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1800 | final long identity = Binder.clearCallingIdentity(); |
| 1801 | try { |
| 1802 | final Phone phone = getPhone(subId); |
| 1803 | if (phone != null) { |
| 1804 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1805 | } else { |
| 1806 | return false; |
| 1807 | } |
| 1808 | } finally { |
| 1809 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1810 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1811 | } |
| 1812 | |
| 1813 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1814 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1815 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1816 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1817 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1818 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1819 | |
| 1820 | final long identity = Binder.clearCallingIdentity(); |
| 1821 | try { |
| 1822 | final Phone phone = getPhone(subId); |
| 1823 | if (phone != null) { |
| 1824 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 1825 | } |
| 1826 | } finally { |
| 1827 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1828 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1829 | } |
| 1830 | |
| 1831 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1832 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1833 | } |
| 1834 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1835 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1836 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1837 | |
| 1838 | final long identity = Binder.clearCallingIdentity(); |
| 1839 | try { |
| 1840 | final Phone phone = getPhone(subId); |
| 1841 | if (phone == null) { |
| 1842 | return false; |
| 1843 | } |
| 1844 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 1845 | toggleRadioOnOffForSubscriber(subId); |
| 1846 | } |
| 1847 | return true; |
| 1848 | } finally { |
| 1849 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1850 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1851 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1852 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1853 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 1854 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1855 | /* |
| 1856 | * If any of the Radios are available, it will need to be |
| 1857 | * shutdown. So return true if any Radio is available. |
| 1858 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1859 | final long identity = Binder.clearCallingIdentity(); |
| 1860 | try { |
| 1861 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1862 | Phone phone = PhoneFactory.getPhone(i); |
| 1863 | if (phone != null && phone.isRadioAvailable()) return true; |
| 1864 | } |
| 1865 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 1866 | return false; |
| 1867 | } finally { |
| 1868 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1869 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1870 | } |
| 1871 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1872 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1873 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1874 | enforceModifyPermission(); |
| 1875 | |
| 1876 | final long identity = Binder.clearCallingIdentity(); |
| 1877 | try { |
| 1878 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 1879 | logv("Shutting down Phone " + i); |
| 1880 | shutdownRadioUsingPhoneId(i); |
| 1881 | } |
| 1882 | } finally { |
| 1883 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1884 | } |
| 1885 | } |
| 1886 | |
| 1887 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 1888 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 1889 | if (phone != null && phone.isRadioAvailable()) { |
| 1890 | phone.shutdownRadio(); |
| 1891 | } |
| 1892 | } |
| 1893 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1894 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 1895 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1896 | |
| 1897 | final long identity = Binder.clearCallingIdentity(); |
| 1898 | try { |
| 1899 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 1900 | if (defaultPhone != null) { |
| 1901 | defaultPhone.setRadioPower(turnOn); |
| 1902 | return true; |
| 1903 | } else { |
| 1904 | loge("There's no default phone."); |
| 1905 | return false; |
| 1906 | } |
| 1907 | } finally { |
| 1908 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 1909 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1910 | } |
| 1911 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1912 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1913 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1914 | |
| 1915 | final long identity = Binder.clearCallingIdentity(); |
| 1916 | try { |
| 1917 | final Phone phone = getPhone(subId); |
| 1918 | if (phone != null) { |
| 1919 | phone.setRadioPower(turnOn); |
| 1920 | return true; |
| 1921 | } else { |
| 1922 | return false; |
| 1923 | } |
| 1924 | } finally { |
| 1925 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1926 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1927 | } |
| 1928 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1929 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1930 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1931 | public boolean enableDataConnectivity() { |
| 1932 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1933 | |
| 1934 | final long identity = Binder.clearCallingIdentity(); |
| 1935 | try { |
| 1936 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1937 | final Phone phone = getPhone(subId); |
| 1938 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1939 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1940 | return true; |
| 1941 | } else { |
| 1942 | return false; |
| 1943 | } |
| 1944 | } finally { |
| 1945 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1946 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1947 | } |
| 1948 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1949 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1950 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1951 | public boolean disableDataConnectivity() { |
| 1952 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1953 | |
| 1954 | final long identity = Binder.clearCallingIdentity(); |
| 1955 | try { |
| 1956 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 1957 | final Phone phone = getPhone(subId); |
| 1958 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 1959 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1960 | return true; |
| 1961 | } else { |
| 1962 | return false; |
| 1963 | } |
| 1964 | } finally { |
| 1965 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1966 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1967 | } |
| 1968 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1969 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 1970 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1971 | final long identity = Binder.clearCallingIdentity(); |
| 1972 | try { |
| 1973 | final Phone phone = getPhone(subId); |
| 1974 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 1975 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1976 | } else { |
| 1977 | return false; |
| 1978 | } |
| 1979 | } finally { |
| 1980 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1981 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1982 | } |
| 1983 | |
| 1984 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1985 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1986 | } |
| 1987 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 1988 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1989 | enforceCallPermission(); |
| 1990 | |
| 1991 | final long identity = Binder.clearCallingIdentity(); |
| 1992 | try { |
| 1993 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 1994 | return; |
| 1995 | } |
| 1996 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 1997 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 1998 | } finally { |
| 1999 | Binder.restoreCallingIdentity(identity); |
| 2000 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2001 | }; |
| 2002 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2003 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2004 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2005 | |
| 2006 | final long identity = Binder.clearCallingIdentity(); |
| 2007 | try { |
| 2008 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2009 | return false; |
| 2010 | } |
| 2011 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2012 | } finally { |
| 2013 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2014 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2015 | } |
| 2016 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2017 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2018 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2019 | } |
| 2020 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2021 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2022 | final long identity = Binder.clearCallingIdentity(); |
| 2023 | try { |
| 2024 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2025 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2026 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2027 | } finally { |
| 2028 | Binder.restoreCallingIdentity(identity); |
| 2029 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2030 | } |
| 2031 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2032 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2033 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2034 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2035 | } |
| 2036 | |
| 2037 | @Override |
| 2038 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2039 | final long identity = Binder.clearCallingIdentity(); |
| 2040 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2041 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2042 | if (phone != null) { |
| 2043 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2044 | } else { |
| 2045 | return PhoneConstantConversions.convertDataState( |
| 2046 | PhoneConstants.DataState.DISCONNECTED); |
| 2047 | } |
| 2048 | } finally { |
| 2049 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2050 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2051 | } |
| 2052 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2053 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2054 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2055 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2056 | } |
| 2057 | |
| 2058 | @Override |
| 2059 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2060 | final long identity = Binder.clearCallingIdentity(); |
| 2061 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2062 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2063 | if (phone != null) { |
| 2064 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2065 | } else { |
| 2066 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2067 | } |
| 2068 | } finally { |
| 2069 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2070 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2071 | } |
| 2072 | |
| 2073 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2074 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2075 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2076 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2077 | |
| 2078 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2079 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2080 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2081 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2082 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2083 | .setCallingPid(Binder.getCallingPid()) |
| 2084 | .setCallingUid(Binder.getCallingUid()) |
| 2085 | .setMethod("getCellLocation") |
| 2086 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2087 | .build()); |
| 2088 | switch (locationResult) { |
| 2089 | case DENIED_HARD: |
| 2090 | throw new SecurityException("Not allowed to access cell location"); |
| 2091 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2092 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2093 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2094 | } |
| 2095 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2096 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2097 | final long identity = Binder.clearCallingIdentity(); |
| 2098 | try { |
| 2099 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2100 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2101 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2102 | } finally { |
| 2103 | Binder.restoreCallingIdentity(identity); |
| 2104 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2105 | } |
| 2106 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2107 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2108 | public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage, |
| 2109 | String callingFeatureId) { |
Jack Yu | 1e81ccd | 2019-09-26 11:48:33 -0700 | [diff] [blame] | 2110 | if (!TextUtils.isEmpty(callingPackage)) { |
| 2111 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2112 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 2113 | callingFeatureId, "getNetworkCountryIsoForPhone")) { |
Jack Yu | 1e81ccd | 2019-09-26 11:48:33 -0700 | [diff] [blame] | 2114 | return ""; |
| 2115 | } |
| 2116 | } |
| 2117 | |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2118 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2119 | // registered cell info, so return a NULL country instead. |
| 2120 | final long identity = Binder.clearCallingIdentity(); |
| 2121 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2122 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2123 | // Get default phone in this case. |
| 2124 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2125 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2126 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 2127 | // Todo: fix this when we can get the actual cellular network info when the device |
| 2128 | // is on IWLAN. |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2129 | if (TelephonyManager.NETWORK_TYPE_IWLAN |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2130 | == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(), |
| 2131 | mApp.getFeatureId())) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2132 | return ""; |
| 2133 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2134 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2135 | if (phone != null) { |
| 2136 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2137 | EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2138 | if (sst != null) { |
| 2139 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2140 | if (lt != null) { |
sqian | b9d961a | 2019-07-31 20:23:45 -0700 | [diff] [blame] | 2141 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) { |
| 2142 | return lt.getCurrentCountry(); |
| 2143 | } else if (emergencyNumberTracker != null) { |
| 2144 | return emergencyNumberTracker.getEmergencyCountryIso(); |
| 2145 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2146 | } |
| 2147 | } |
| 2148 | } |
| 2149 | return ""; |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2150 | } finally { |
| 2151 | Binder.restoreCallingIdentity(identity); |
| 2152 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2153 | } |
| 2154 | |
| 2155 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2156 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2157 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2158 | } |
| 2159 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2160 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2161 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2162 | mApp.enforceCallingOrSelfPermission( |
| 2163 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2164 | |
| 2165 | final long identity = Binder.clearCallingIdentity(); |
| 2166 | try { |
| 2167 | final Phone phone = getPhone(subId); |
| 2168 | if (phone != null) { |
| 2169 | phone.enableLocationUpdates(); |
| 2170 | } |
| 2171 | } finally { |
| 2172 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2173 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2174 | } |
| 2175 | |
| 2176 | @Override |
| 2177 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2178 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2179 | } |
| 2180 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2181 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2182 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2183 | mApp.enforceCallingOrSelfPermission( |
| 2184 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2185 | |
| 2186 | final long identity = Binder.clearCallingIdentity(); |
| 2187 | try { |
| 2188 | final Phone phone = getPhone(subId); |
| 2189 | if (phone != null) { |
| 2190 | phone.disableLocationUpdates(); |
| 2191 | } |
| 2192 | } finally { |
| 2193 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2194 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2195 | } |
| 2196 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2197 | /** |
| 2198 | * Returns the target SDK version number for a given package name. |
| 2199 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2200 | * This call MUST be invoked before clearing the calling UID. |
| 2201 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2202 | * @return target SDK if the package is found or INT_MAX. |
| 2203 | */ |
| 2204 | private int getTargetSdk(String packageName) { |
| 2205 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2206 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 0150f0e | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2207 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2208 | if (ai != null) return ai.targetSdkVersion; |
| 2209 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2210 | loge("Failed to get package info for pkg=" |
| 2211 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2212 | } |
| 2213 | return Integer.MAX_VALUE; |
| 2214 | } |
| 2215 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2216 | @Override |
| 2217 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2218 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2219 | String callingFeatureId) { |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2220 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2221 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2222 | throw new SecurityException( |
| 2223 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2224 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2225 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2226 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2227 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2228 | return null; |
| 2229 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2230 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2231 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2232 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2233 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2234 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2235 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2236 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2237 | for (CellInfo ci : info) { |
| 2238 | if (ci instanceof CellInfoGsm) { |
| 2239 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2240 | } else if (ci instanceof CellInfoWcdma) { |
| 2241 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2242 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2243 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2244 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2245 | } |
| 2246 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2247 | private List<CellInfo> getCachedCellInfo() { |
| 2248 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2249 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2250 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2251 | if (info != null) cellInfos.addAll(info); |
| 2252 | } |
| 2253 | return cellInfos; |
| 2254 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2255 | |
| 2256 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2257 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2258 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2259 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2260 | |
| 2261 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2262 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2263 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2264 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2265 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2266 | .setCallingPid(Binder.getCallingPid()) |
| 2267 | .setCallingUid(Binder.getCallingUid()) |
| 2268 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2269 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2270 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2271 | .build()); |
| 2272 | switch (locationResult) { |
| 2273 | case DENIED_HARD: |
| 2274 | throw new SecurityException("Not allowed to access cell info"); |
| 2275 | case DENIED_SOFT: |
| 2276 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2277 | } |
| 2278 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2279 | final int targetSdk = getTargetSdk(callingPackage); |
| 2280 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2281 | return getCachedCellInfo(); |
| 2282 | } |
| 2283 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2284 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2285 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2286 | final long identity = Binder.clearCallingIdentity(); |
| 2287 | try { |
| 2288 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2289 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2290 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2291 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2292 | if (info != null) cellInfos.addAll(info); |
| 2293 | } |
| 2294 | return cellInfos; |
| 2295 | } finally { |
| 2296 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2297 | } |
| 2298 | } |
| 2299 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2300 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2301 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2302 | String callingFeatureId) { |
| 2303 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2304 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2305 | } |
| 2306 | |
| 2307 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2308 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2309 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2310 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2311 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2312 | } |
| 2313 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2314 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2315 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2316 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2317 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2318 | |
| 2319 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2320 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2321 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2322 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2323 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2324 | .setCallingPid(Binder.getCallingPid()) |
| 2325 | .setCallingUid(Binder.getCallingUid()) |
| 2326 | .setMethod("requestCellInfoUpdate") |
| 2327 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2328 | .build()); |
| 2329 | switch (locationResult) { |
| 2330 | case DENIED_HARD: |
| 2331 | throw new SecurityException("Not allowed to access cell info"); |
| 2332 | case DENIED_SOFT: |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2333 | try { |
| 2334 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2335 | } catch (RemoteException re) { |
| 2336 | // Drop without consequences |
| 2337 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2338 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2339 | } |
| 2340 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2341 | |
| 2342 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2343 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2344 | |
| 2345 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2346 | } |
| 2347 | |
| 2348 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2349 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2350 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2351 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2352 | |
| 2353 | final long identity = Binder.clearCallingIdentity(); |
| 2354 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2355 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2356 | } finally { |
| 2357 | Binder.restoreCallingIdentity(identity); |
| 2358 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2359 | } |
| 2360 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2361 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2362 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2363 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2364 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2365 | return null; |
| 2366 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2367 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2368 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2369 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2370 | return null; |
| 2371 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2372 | |
| 2373 | final long identity = Binder.clearCallingIdentity(); |
| 2374 | try { |
| 2375 | return phone.getImei(); |
| 2376 | } finally { |
| 2377 | Binder.restoreCallingIdentity(identity); |
| 2378 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2379 | } |
| 2380 | |
| 2381 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2382 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2383 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2384 | String tac = null; |
| 2385 | if (phone != null) { |
| 2386 | String imei = phone.getImei(); |
| 2387 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2388 | } |
| 2389 | return tac; |
| 2390 | } |
| 2391 | |
| 2392 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2393 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2394 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2395 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2396 | return null; |
| 2397 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2398 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2399 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2400 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2401 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2402 | return null; |
| 2403 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2404 | |
| 2405 | final long identity = Binder.clearCallingIdentity(); |
| 2406 | try { |
| 2407 | return phone.getMeid(); |
| 2408 | } finally { |
| 2409 | Binder.restoreCallingIdentity(identity); |
| 2410 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2411 | } |
| 2412 | |
| 2413 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2414 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2415 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2416 | String manufacturerCode = null; |
| 2417 | if (phone != null) { |
| 2418 | String meid = phone.getMeid(); |
| 2419 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2420 | } |
| 2421 | return manufacturerCode; |
| 2422 | } |
| 2423 | |
| 2424 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2425 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2426 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2427 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2428 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2429 | return null; |
| 2430 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2431 | int subId = phone.getSubId(); |
| 2432 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2433 | mApp, subId, callingPackage, callingFeatureId, |
| 2434 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2435 | return null; |
| 2436 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2437 | |
| 2438 | final long identity = Binder.clearCallingIdentity(); |
| 2439 | try { |
| 2440 | return phone.getDeviceSvn(); |
| 2441 | } finally { |
| 2442 | Binder.restoreCallingIdentity(identity); |
| 2443 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2444 | } |
| 2445 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2446 | @Override |
| 2447 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2448 | final long identity = Binder.clearCallingIdentity(); |
| 2449 | try { |
| 2450 | final Phone phone = getPhone(subId); |
| 2451 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2452 | } finally { |
| 2453 | Binder.restoreCallingIdentity(identity); |
| 2454 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2455 | } |
| 2456 | |
| 2457 | @Override |
| 2458 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2459 | final long identity = Binder.clearCallingIdentity(); |
| 2460 | try { |
| 2461 | final Phone phone = getPhone(subId); |
| 2462 | return phone == null ? null : phone.getCarrierName(); |
| 2463 | } finally { |
| 2464 | Binder.restoreCallingIdentity(identity); |
| 2465 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2466 | } |
| 2467 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2468 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2469 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2470 | final long identity = Binder.clearCallingIdentity(); |
| 2471 | try { |
| 2472 | final Phone phone = getPhone(subId); |
| 2473 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2474 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2475 | } finally { |
| 2476 | Binder.restoreCallingIdentity(identity); |
| 2477 | } |
| 2478 | } |
| 2479 | |
| 2480 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2481 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2482 | final long identity = Binder.clearCallingIdentity(); |
| 2483 | try { |
| 2484 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2485 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2486 | } finally { |
| 2487 | Binder.restoreCallingIdentity(identity); |
| 2488 | } |
| 2489 | } |
| 2490 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2491 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2492 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2493 | if (!isSubscriptionMccMnc) { |
| 2494 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2495 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2496 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2497 | if (phone == null) { |
| 2498 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2499 | } |
| 2500 | final long identity = Binder.clearCallingIdentity(); |
| 2501 | try { |
| 2502 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2503 | } finally { |
| 2504 | Binder.restoreCallingIdentity(identity); |
| 2505 | } |
| 2506 | } |
| 2507 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2508 | // |
| 2509 | // Internal helper methods. |
| 2510 | // |
| 2511 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2512 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2513 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2514 | * |
| 2515 | * @throws SecurityException if the caller does not have the required permission |
| 2516 | */ |
| 2517 | private void enforceModifyPermission() { |
| 2518 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2519 | } |
| 2520 | |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 2521 | /** |
| 2522 | * Make sure the caller is system. |
| 2523 | * |
| 2524 | * @throws SecurityException if the caller is not system. |
| 2525 | */ |
| 2526 | private void enforceSystemCaller() { |
| 2527 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 2528 | throw new SecurityException("Caller must be system"); |
| 2529 | } |
| 2530 | } |
| 2531 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 2532 | private void enforceActiveEmergencySessionPermission() { |
| 2533 | mApp.enforceCallingOrSelfPermission( |
| 2534 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 2535 | } |
| 2536 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2537 | /** |
| 2538 | * Make sure the caller has the CALL_PHONE permission. |
| 2539 | * |
| 2540 | * @throws SecurityException if the caller does not have the required permission |
| 2541 | */ |
| 2542 | private void enforceCallPermission() { |
| 2543 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2544 | } |
| 2545 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 2546 | private void enforceSettingsPermission() { |
| 2547 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2548 | } |
| 2549 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2550 | private String createTelUrl(String number) { |
| 2551 | if (TextUtils.isEmpty(number)) { |
| 2552 | return null; |
| 2553 | } |
| 2554 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2555 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2556 | } |
| 2557 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2558 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2559 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2560 | } |
| 2561 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2562 | private static void logv(String msg) { |
| 2563 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2564 | } |
| 2565 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2566 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2567 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2568 | } |
| 2569 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2570 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2571 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2572 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2573 | } |
| 2574 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2575 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2576 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2577 | final long identity = Binder.clearCallingIdentity(); |
| 2578 | try { |
| 2579 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2580 | if (phone == null) { |
| 2581 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2582 | } else { |
| 2583 | return phone.getPhoneType(); |
| 2584 | } |
| 2585 | } finally { |
| 2586 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2587 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2588 | } |
| 2589 | |
| 2590 | /** |
| 2591 | * Returns the CDMA ERI icon index to display |
| 2592 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2593 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2594 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 2595 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 2596 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2597 | } |
| 2598 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2599 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2600 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 2601 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2602 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2603 | mApp, subId, callingPackage, callingFeatureId, |
| 2604 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2605 | return -1; |
| 2606 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2607 | |
| 2608 | final long identity = Binder.clearCallingIdentity(); |
| 2609 | try { |
| 2610 | final Phone phone = getPhone(subId); |
| 2611 | if (phone != null) { |
| 2612 | return phone.getCdmaEriIconIndex(); |
| 2613 | } else { |
| 2614 | return -1; |
| 2615 | } |
| 2616 | } finally { |
| 2617 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2618 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2619 | } |
| 2620 | |
| 2621 | /** |
| 2622 | * Returns the CDMA ERI icon mode, |
| 2623 | * 0 - ON |
| 2624 | * 1 - FLASHING |
| 2625 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2626 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2627 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 2628 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 2629 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2630 | } |
| 2631 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2632 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2633 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 2634 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2635 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2636 | mApp, subId, callingPackage, callingFeatureId, |
| 2637 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2638 | return -1; |
| 2639 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2640 | |
| 2641 | final long identity = Binder.clearCallingIdentity(); |
| 2642 | try { |
| 2643 | final Phone phone = getPhone(subId); |
| 2644 | if (phone != null) { |
| 2645 | return phone.getCdmaEriIconMode(); |
| 2646 | } else { |
| 2647 | return -1; |
| 2648 | } |
| 2649 | } finally { |
| 2650 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2651 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2652 | } |
| 2653 | |
| 2654 | /** |
| 2655 | * Returns the CDMA ERI text, |
| 2656 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2657 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2658 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 2659 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 2660 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2661 | } |
| 2662 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2663 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2664 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 2665 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2666 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2667 | mApp, subId, callingPackage, callingFeatureId, |
| 2668 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2669 | return null; |
| 2670 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2671 | |
| 2672 | final long identity = Binder.clearCallingIdentity(); |
| 2673 | try { |
| 2674 | final Phone phone = getPhone(subId); |
| 2675 | if (phone != null) { |
| 2676 | return phone.getCdmaEriText(); |
| 2677 | } else { |
| 2678 | return null; |
| 2679 | } |
| 2680 | } finally { |
| 2681 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2682 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2683 | } |
| 2684 | |
| 2685 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2686 | * Returns the CDMA MDN. |
| 2687 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2688 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2689 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2690 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2691 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2692 | |
| 2693 | final long identity = Binder.clearCallingIdentity(); |
| 2694 | try { |
| 2695 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2696 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2697 | return phone.getLine1Number(); |
| 2698 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2699 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2700 | return null; |
| 2701 | } |
| 2702 | } finally { |
| 2703 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2704 | } |
| 2705 | } |
| 2706 | |
| 2707 | /** |
| 2708 | * Returns the CDMA MIN. |
| 2709 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2710 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2711 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2712 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2713 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2714 | |
| 2715 | final long identity = Binder.clearCallingIdentity(); |
| 2716 | try { |
| 2717 | final Phone phone = getPhone(subId); |
| 2718 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2719 | return phone.getCdmaMin(); |
| 2720 | } else { |
| 2721 | return null; |
| 2722 | } |
| 2723 | } finally { |
| 2724 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2725 | } |
| 2726 | } |
| 2727 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2728 | @Override |
| 2729 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2730 | INumberVerificationCallback callback, String callingPackage) { |
| 2731 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2732 | != PERMISSION_GRANTED) { |
| 2733 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2734 | } |
| 2735 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2736 | |
| 2737 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2738 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2739 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2740 | } |
| 2741 | |
| 2742 | if (range == null) { |
| 2743 | throw new NullPointerException("Range must be non-null"); |
| 2744 | } |
| 2745 | |
| 2746 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2747 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2748 | |
| 2749 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2750 | } |
| 2751 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2752 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2753 | * Returns true if CDMA provisioning needs to run. |
| 2754 | */ |
| 2755 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2756 | final long identity = Binder.clearCallingIdentity(); |
| 2757 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2758 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2759 | } finally { |
| 2760 | Binder.restoreCallingIdentity(identity); |
| 2761 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2762 | } |
| 2763 | |
| 2764 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2765 | * Sets the voice mail number of a given subId. |
| 2766 | */ |
| 2767 | @Override |
| 2768 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 2769 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2770 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2771 | |
| 2772 | final long identity = Binder.clearCallingIdentity(); |
| 2773 | try { |
| 2774 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2775 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2776 | return success; |
| 2777 | } finally { |
| 2778 | Binder.restoreCallingIdentity(identity); |
| 2779 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2780 | } |
| 2781 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2782 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2783 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2784 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 2785 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 2786 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2787 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2788 | throw new SecurityException("caller must be system dialer"); |
| 2789 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2790 | |
| 2791 | final long identity = Binder.clearCallingIdentity(); |
| 2792 | try { |
| 2793 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2794 | if (phoneAccountHandle == null) { |
| 2795 | return null; |
| 2796 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2797 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2798 | } finally { |
| 2799 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2800 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2801 | } |
| 2802 | |
| 2803 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2804 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 2805 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2806 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2807 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2808 | mApp, subId, callingPackage, callingFeatureId, |
| 2809 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2810 | return null; |
| 2811 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2812 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2813 | final long identity = Binder.clearCallingIdentity(); |
| 2814 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2815 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2816 | } finally { |
| 2817 | Binder.restoreCallingIdentity(identity); |
| 2818 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2819 | } |
| 2820 | |
| 2821 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2822 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2823 | VisualVoicemailSmsFilterSettings settings) { |
| 2824 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2825 | |
| 2826 | final long identity = Binder.clearCallingIdentity(); |
| 2827 | try { |
| 2828 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2829 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2830 | } finally { |
| 2831 | Binder.restoreCallingIdentity(identity); |
| 2832 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2833 | } |
| 2834 | |
| 2835 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2836 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 2837 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2838 | |
| 2839 | final long identity = Binder.clearCallingIdentity(); |
| 2840 | try { |
| 2841 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2842 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2843 | } finally { |
| 2844 | Binder.restoreCallingIdentity(identity); |
| 2845 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2846 | } |
| 2847 | |
| 2848 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2849 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 2850 | String callingPackage, int subId) { |
| 2851 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2852 | |
| 2853 | final long identity = Binder.clearCallingIdentity(); |
| 2854 | try { |
| 2855 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2856 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2857 | } finally { |
| 2858 | Binder.restoreCallingIdentity(identity); |
| 2859 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2860 | } |
| 2861 | |
| 2862 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2863 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2864 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2865 | |
| 2866 | final long identity = Binder.clearCallingIdentity(); |
| 2867 | try { |
| 2868 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2869 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2870 | } finally { |
| 2871 | Binder.restoreCallingIdentity(identity); |
| 2872 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2873 | } |
| 2874 | |
| 2875 | @Override |
| 2876 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId, |
| 2877 | String number, int port, String text, PendingIntent sentIntent) { |
| 2878 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 2879 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 2880 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2881 | SmsController smsController = PhoneFactory.getSmsController(); |
| 2882 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text, |
| 2883 | sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2884 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 2885 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2886 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2887 | * Sets the voice activation state of a given subId. |
| 2888 | */ |
| 2889 | @Override |
| 2890 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2891 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2892 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2893 | |
| 2894 | final long identity = Binder.clearCallingIdentity(); |
| 2895 | try { |
| 2896 | final Phone phone = getPhone(subId); |
| 2897 | if (phone != null) { |
| 2898 | phone.setVoiceActivationState(activationState); |
| 2899 | } else { |
| 2900 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 2901 | } |
| 2902 | } finally { |
| 2903 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2904 | } |
| 2905 | } |
| 2906 | |
| 2907 | /** |
| 2908 | * Sets the data activation state of a given subId. |
| 2909 | */ |
| 2910 | @Override |
| 2911 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2912 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2913 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2914 | |
| 2915 | final long identity = Binder.clearCallingIdentity(); |
| 2916 | try { |
| 2917 | final Phone phone = getPhone(subId); |
| 2918 | if (phone != null) { |
| 2919 | phone.setDataActivationState(activationState); |
| 2920 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 2921 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2922 | } |
| 2923 | } finally { |
| 2924 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2925 | } |
| 2926 | } |
| 2927 | |
| 2928 | /** |
| 2929 | * Returns the voice activation state of a given subId. |
| 2930 | */ |
| 2931 | @Override |
| 2932 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2933 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2934 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2935 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2936 | final long identity = Binder.clearCallingIdentity(); |
| 2937 | try { |
| 2938 | if (phone != null) { |
| 2939 | return phone.getVoiceActivationState(); |
| 2940 | } else { |
| 2941 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2942 | } |
| 2943 | } finally { |
| 2944 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2945 | } |
| 2946 | } |
| 2947 | |
| 2948 | /** |
| 2949 | * Returns the data activation state of a given subId. |
| 2950 | */ |
| 2951 | @Override |
| 2952 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 2953 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2954 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2955 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2956 | final long identity = Binder.clearCallingIdentity(); |
| 2957 | try { |
| 2958 | if (phone != null) { |
| 2959 | return phone.getDataActivationState(); |
| 2960 | } else { |
| 2961 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 2962 | } |
| 2963 | } finally { |
| 2964 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 2965 | } |
| 2966 | } |
| 2967 | |
| 2968 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2969 | * Returns the unread count of voicemails for a subId |
| 2970 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2971 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2972 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 2973 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2974 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2975 | mApp, subId, callingPackage, callingFeatureId, |
| 2976 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 2977 | return 0; |
| 2978 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2979 | final long identity = Binder.clearCallingIdentity(); |
| 2980 | try { |
| 2981 | final Phone phone = getPhone(subId); |
| 2982 | if (phone != null) { |
| 2983 | return phone.getVoiceMessageCount(); |
| 2984 | } else { |
| 2985 | return 0; |
| 2986 | } |
| 2987 | } finally { |
| 2988 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2989 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2990 | } |
| 2991 | |
| 2992 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 2993 | * returns true, if the device is in a state where both voice and data |
| 2994 | * are supported simultaneously. This can change based on location or network condition. |
| 2995 | */ |
| 2996 | @Override |
| 2997 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2998 | final long identity = Binder.clearCallingIdentity(); |
| 2999 | try { |
| 3000 | final Phone phone = getPhone(subId); |
| 3001 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3002 | } finally { |
| 3003 | Binder.restoreCallingIdentity(identity); |
| 3004 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3005 | } |
| 3006 | |
| 3007 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3008 | * Send the dialer code if called from the current default dialer or the caller has |
| 3009 | * carrier privilege. |
| 3010 | * @param inputCode The dialer code to send |
| 3011 | */ |
| 3012 | @Override |
| 3013 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3014 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3015 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3016 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3017 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3018 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3019 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3020 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3021 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3022 | |
| 3023 | final long identity = Binder.clearCallingIdentity(); |
| 3024 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3025 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3026 | } finally { |
| 3027 | Binder.restoreCallingIdentity(identity); |
| 3028 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3029 | } |
| 3030 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3031 | @Override |
| 3032 | public int getNetworkSelectionMode(int subId) { |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3033 | if (!isActiveSubscription(subId)) { |
| 3034 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3035 | } |
| 3036 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3037 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3038 | } |
| 3039 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3040 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3041 | public boolean isInEmergencySmsMode() { |
| 3042 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3043 | final long identity = Binder.clearCallingIdentity(); |
| 3044 | try { |
| 3045 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3046 | if (phone.isInEmergencySmsMode()) { |
| 3047 | return true; |
| 3048 | } |
| 3049 | } |
| 3050 | } finally { |
| 3051 | Binder.restoreCallingIdentity(identity); |
| 3052 | } |
| 3053 | return false; |
| 3054 | } |
| 3055 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3056 | /** |
| 3057 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3058 | * @param subId The subscription to use to check the configuration. |
| 3059 | * @param c The callback that will be used to send the result. |
| 3060 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3061 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3062 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3063 | throws RemoteException { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3064 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3065 | enforceReadPrivilegedPermission("registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3066 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3067 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3068 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3069 | "IMS not available on device."); |
| 3070 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3071 | final long token = Binder.clearCallingIdentity(); |
| 3072 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3073 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3074 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3075 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3076 | } catch (ImsException e) { |
| 3077 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3078 | } finally { |
| 3079 | Binder.restoreCallingIdentity(token); |
| 3080 | } |
| 3081 | } |
| 3082 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3083 | /** |
| 3084 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3085 | * @param subId The subscription to use to check the configuration. |
| 3086 | * @param c The callback that will be used to send the result. |
| 3087 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3088 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3089 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3090 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3091 | enforceReadPrivilegedPermission("unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3092 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3093 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3094 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3095 | final long token = Binder.clearCallingIdentity(); |
| 3096 | try { |
| 3097 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3098 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3099 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3100 | } catch (ImsException e) { |
| 3101 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3102 | + "is inactive, ignoring unregister."); |
| 3103 | // If the subscription is no longer active, just return, since the callback |
| 3104 | // will already have been removed internally. |
| 3105 | } finally { |
| 3106 | Binder.restoreCallingIdentity(token); |
| 3107 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3108 | } |
| 3109 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3110 | /** |
| 3111 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3112 | */ |
| 3113 | @Override |
| 3114 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3115 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3116 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3117 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3118 | "IMS not available on device."); |
| 3119 | } |
| 3120 | final long token = Binder.clearCallingIdentity(); |
| 3121 | try { |
| 3122 | Phone phone = getPhone(subId); |
| 3123 | if (phone == null) { |
| 3124 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3125 | + subId + "'"); |
| 3126 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3127 | } |
| 3128 | phone.getImsRegistrationState(regState -> { |
| 3129 | try { |
| 3130 | consumer.accept((regState == null) |
| 3131 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3132 | } catch (RemoteException e) { |
| 3133 | // Ignore if the remote process is no longer available to call back. |
| 3134 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3135 | } |
| 3136 | }); |
| 3137 | } finally { |
| 3138 | Binder.restoreCallingIdentity(token); |
| 3139 | } |
| 3140 | } |
| 3141 | |
| 3142 | /** |
| 3143 | * Get the transport type for the IMS service registration state. |
| 3144 | */ |
| 3145 | @Override |
| 3146 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3147 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3148 | enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType"); |
| 3149 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3150 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3151 | "IMS not available on device."); |
| 3152 | } |
| 3153 | final long token = Binder.clearCallingIdentity(); |
| 3154 | try { |
| 3155 | Phone phone = getPhone(subId); |
| 3156 | if (phone == null) { |
| 3157 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3158 | + subId + "'"); |
| 3159 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3160 | } |
| 3161 | phone.getImsRegistrationTech(regTech -> { |
| 3162 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3163 | int regTechConverted = (regTech == null) |
| 3164 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3165 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3166 | regTechConverted); |
| 3167 | try { |
| 3168 | consumer.accept(regTechConverted); |
| 3169 | } catch (RemoteException e) { |
| 3170 | // Ignore if the remote process is no longer available to call back. |
| 3171 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3172 | } |
| 3173 | }); |
| 3174 | } finally { |
| 3175 | Binder.restoreCallingIdentity(token); |
| 3176 | } |
| 3177 | } |
| 3178 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3179 | /** |
| 3180 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3181 | * @param subId The subscription to use to check the configuration. |
| 3182 | * @param c The callback that will be used to send the result. |
| 3183 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3184 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3185 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3186 | throws RemoteException { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3187 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3188 | enforceReadPrivilegedPermission("registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3189 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3190 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3191 | "IMS not available on device."); |
| 3192 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3193 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3194 | final long token = Binder.clearCallingIdentity(); |
| 3195 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3196 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3197 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3198 | } catch (ImsException e) { |
| 3199 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3200 | } finally { |
| 3201 | Binder.restoreCallingIdentity(token); |
| 3202 | } |
| 3203 | } |
| 3204 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3205 | /** |
| 3206 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3207 | * @param subId The subscription to use to check the configuration. |
| 3208 | * @param c The callback that will be used to send the result. |
| 3209 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3210 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3211 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3212 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3213 | enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3214 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3215 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3216 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3217 | |
| 3218 | final long token = Binder.clearCallingIdentity(); |
| 3219 | try { |
| 3220 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3221 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3222 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3223 | } catch (ImsException e) { |
| 3224 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3225 | + "is inactive, ignoring unregister."); |
| 3226 | // If the subscription is no longer active, just return, since the callback |
| 3227 | // will already have been removed internally. |
| 3228 | } finally { |
| 3229 | Binder.restoreCallingIdentity(token); |
| 3230 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3231 | } |
| 3232 | |
| 3233 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3234 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3235 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3236 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3237 | final long token = Binder.clearCallingIdentity(); |
| 3238 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3239 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3240 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3241 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3242 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3243 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3244 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3245 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3246 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3247 | } finally { |
| 3248 | Binder.restoreCallingIdentity(token); |
| 3249 | } |
| 3250 | } |
| 3251 | |
| 3252 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3253 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3254 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3255 | final long token = Binder.clearCallingIdentity(); |
| 3256 | try { |
| 3257 | Phone phone = getPhone(subId); |
| 3258 | if (phone == null) return false; |
| 3259 | return phone.isImsCapabilityAvailable(capability, regTech); |
| 3260 | } finally { |
| 3261 | Binder.restoreCallingIdentity(token); |
| 3262 | } |
| 3263 | } |
| 3264 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3265 | /** |
| 3266 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3267 | * subscription. |
| 3268 | * @param subId The subscription to use to check the configuration. |
| 3269 | * @param callback The callback that will be used to send the result. |
| 3270 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3271 | * @param transportType The transport type of the MmTelFeature capability. |
| 3272 | */ |
| 3273 | @Override |
| 3274 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3275 | int transportType) { |
| 3276 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3277 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3278 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3279 | "IMS not available on device."); |
| 3280 | } |
| 3281 | final long token = Binder.clearCallingIdentity(); |
| 3282 | try { |
| 3283 | int slotId = getSlotIndex(subId); |
| 3284 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3285 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3286 | + subId + "'"); |
| 3287 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3288 | } |
| 3289 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3290 | transportType, aBoolean -> { |
| 3291 | try { |
| 3292 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3293 | } catch (RemoteException e) { |
| 3294 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3295 | + "running. Ignore"); |
| 3296 | } |
| 3297 | }); |
| 3298 | } finally { |
| 3299 | Binder.restoreCallingIdentity(token); |
| 3300 | } |
| 3301 | } |
| 3302 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3303 | /** |
| 3304 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3305 | * @param subId The subscription to use to check the configuration. |
| 3306 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3307 | @Override |
| 3308 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3309 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
| 3310 | enforceReadPrivilegedPermission("isAdvancedCallingSettingEnabled"); |
| 3311 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3312 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3313 | final long token = Binder.clearCallingIdentity(); |
| 3314 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3315 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3316 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3317 | } catch (ImsException e) { |
| 3318 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3319 | } finally { |
| 3320 | Binder.restoreCallingIdentity(token); |
| 3321 | } |
| 3322 | } |
| 3323 | |
| 3324 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3325 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3326 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3327 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3328 | final long identity = Binder.clearCallingIdentity(); |
| 3329 | try { |
| 3330 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3331 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3332 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3333 | } catch (ImsException e) { |
| 3334 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3335 | } finally { |
| 3336 | Binder.restoreCallingIdentity(identity); |
| 3337 | } |
| 3338 | } |
| 3339 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3340 | /** |
| 3341 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3342 | * @param subId The subscription to use to check the configuration. |
| 3343 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3344 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3345 | public boolean isVtSettingEnabled(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3346 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3347 | enforceReadPrivilegedPermission("isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3348 | final long identity = Binder.clearCallingIdentity(); |
| 3349 | try { |
| 3350 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3351 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3352 | } catch (ImsException e) { |
| 3353 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3354 | } finally { |
| 3355 | Binder.restoreCallingIdentity(identity); |
| 3356 | } |
| 3357 | } |
| 3358 | |
| 3359 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3360 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3361 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3362 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3363 | final long identity = Binder.clearCallingIdentity(); |
| 3364 | try { |
| 3365 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3366 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3367 | } catch (ImsException e) { |
| 3368 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3369 | } finally { |
| 3370 | Binder.restoreCallingIdentity(identity); |
| 3371 | } |
| 3372 | } |
| 3373 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3374 | /** |
| 3375 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3376 | * @param subId The subscription to use to check the configuration. |
| 3377 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3378 | @Override |
| 3379 | public boolean isVoWiFiSettingEnabled(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3380 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3381 | enforceReadPrivilegedPermission("isVoWiFiSettingEnabled"); |
| 3382 | final long identity = Binder.clearCallingIdentity(); |
| 3383 | try { |
| 3384 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3385 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3386 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3387 | } catch (ImsException e) { |
| 3388 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3389 | } finally { |
| 3390 | Binder.restoreCallingIdentity(identity); |
| 3391 | } |
| 3392 | } |
| 3393 | |
| 3394 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3395 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3396 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3397 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3398 | final long identity = Binder.clearCallingIdentity(); |
| 3399 | try { |
| 3400 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3401 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3402 | } catch (ImsException e) { |
| 3403 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3404 | } finally { |
| 3405 | Binder.restoreCallingIdentity(identity); |
| 3406 | } |
| 3407 | } |
| 3408 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3409 | /** |
| 3410 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3411 | * @param subId The subscription to use to check the configuration. |
| 3412 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3413 | @Override |
| 3414 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3415 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3416 | enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled"); |
| 3417 | final long identity = Binder.clearCallingIdentity(); |
| 3418 | try { |
| 3419 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3420 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3421 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3422 | } catch (ImsException e) { |
| 3423 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3424 | } finally { |
| 3425 | Binder.restoreCallingIdentity(identity); |
| 3426 | } |
| 3427 | } |
| 3428 | |
| 3429 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3430 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3431 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3432 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3433 | final long identity = Binder.clearCallingIdentity(); |
| 3434 | try { |
| 3435 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3436 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3437 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3438 | } catch (ImsException e) { |
| 3439 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3440 | } finally { |
| 3441 | Binder.restoreCallingIdentity(identity); |
| 3442 | } |
| 3443 | } |
| 3444 | |
| 3445 | @Override |
| 3446 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3447 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3448 | "setVoWiFiNonPersistent"); |
| 3449 | final long identity = Binder.clearCallingIdentity(); |
| 3450 | try { |
| 3451 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3452 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3453 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3454 | } catch (ImsException e) { |
| 3455 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3456 | } finally { |
| 3457 | Binder.restoreCallingIdentity(identity); |
| 3458 | } |
| 3459 | } |
| 3460 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3461 | /** |
| 3462 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3463 | * @param subId The subscription to use to check the configuration. |
| 3464 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3465 | @Override |
| 3466 | public int getVoWiFiModeSetting(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3467 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3468 | enforceReadPrivilegedPermission("getVoWiFiModeSetting"); |
| 3469 | final long identity = Binder.clearCallingIdentity(); |
| 3470 | try { |
| 3471 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3472 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3473 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3474 | } catch (ImsException e) { |
| 3475 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3476 | } finally { |
| 3477 | Binder.restoreCallingIdentity(identity); |
| 3478 | } |
| 3479 | } |
| 3480 | |
| 3481 | @Override |
| 3482 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3483 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3484 | "setVoWiFiModeSetting"); |
| 3485 | final long identity = Binder.clearCallingIdentity(); |
| 3486 | try { |
| 3487 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3488 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3489 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3490 | } catch (ImsException e) { |
| 3491 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3492 | } finally { |
| 3493 | Binder.restoreCallingIdentity(identity); |
| 3494 | } |
| 3495 | } |
| 3496 | |
| 3497 | @Override |
| 3498 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3499 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3500 | final long identity = Binder.clearCallingIdentity(); |
| 3501 | try { |
| 3502 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3503 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3504 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3505 | } catch (ImsException e) { |
| 3506 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3507 | } finally { |
| 3508 | Binder.restoreCallingIdentity(identity); |
| 3509 | } |
| 3510 | } |
| 3511 | |
| 3512 | @Override |
| 3513 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3514 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3515 | "setVoWiFiRoamingModeSetting"); |
| 3516 | final long identity = Binder.clearCallingIdentity(); |
| 3517 | try { |
| 3518 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3519 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3520 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3521 | } catch (ImsException e) { |
| 3522 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3523 | } finally { |
| 3524 | Binder.restoreCallingIdentity(identity); |
| 3525 | } |
| 3526 | } |
| 3527 | |
| 3528 | @Override |
| 3529 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3530 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3531 | "setRttCapabilityEnabled"); |
| 3532 | final long identity = Binder.clearCallingIdentity(); |
| 3533 | try { |
| 3534 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3535 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3536 | } catch (ImsException e) { |
| 3537 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3538 | } finally { |
| 3539 | Binder.restoreCallingIdentity(identity); |
| 3540 | } |
| 3541 | } |
| 3542 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3543 | /** |
| 3544 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3545 | * @param subId The subscription to use to check the configuration. |
| 3546 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3547 | @Override |
| 3548 | public boolean isTtyOverVolteEnabled(int subId) { |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3549 | //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3550 | enforceReadPrivilegedPermission("isTtyOverVolteEnabled"); |
| 3551 | final long identity = Binder.clearCallingIdentity(); |
| 3552 | try { |
| 3553 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3554 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3555 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3556 | } catch (ImsException e) { |
| 3557 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3558 | } finally { |
| 3559 | Binder.restoreCallingIdentity(identity); |
| 3560 | } |
| 3561 | } |
| 3562 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3563 | @Override |
| 3564 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3565 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3566 | final long identity = Binder.clearCallingIdentity(); |
| 3567 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 3568 | if (!isImsAvailableOnDevice()) { |
| 3569 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3570 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 3571 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3572 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3573 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3574 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3575 | } catch (ImsException e) { |
| 3576 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3577 | } finally { |
| 3578 | Binder.restoreCallingIdentity(identity); |
| 3579 | } |
| 3580 | } |
| 3581 | |
| 3582 | @Override |
| 3583 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3584 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3585 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3586 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3587 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3588 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3589 | try { |
| 3590 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3591 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3592 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3593 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3594 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3595 | + "is inactive, ignoring unregister."); |
| 3596 | // If the subscription is no longer active, just return, since the callback will already |
| 3597 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3598 | } finally { |
| 3599 | Binder.restoreCallingIdentity(identity); |
| 3600 | } |
| 3601 | } |
| 3602 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3603 | |
| 3604 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 3605 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3606 | message); |
| 3607 | } |
| 3608 | |
| 3609 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 3610 | boolean isMmtelCapability) { |
| 3611 | Phone phone = getPhone(subId); |
| 3612 | if (phone == null) { |
| 3613 | loge("phone instance null for subid " + subId); |
| 3614 | return false; |
| 3615 | } |
| 3616 | if (isMmtelCapability) { |
| 3617 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3618 | return false; |
| 3619 | } |
| 3620 | } else { |
| 3621 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3622 | return false; |
| 3623 | } |
| 3624 | } |
| 3625 | return true; |
| 3626 | } |
| 3627 | |
| 3628 | @Override |
| 3629 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 3630 | boolean isProvisioned) { |
| 3631 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 3632 | |
| 3633 | final long identity = Binder.clearCallingIdentity(); |
| 3634 | try { |
| 3635 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3636 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3637 | return; |
| 3638 | } |
| 3639 | |
| 3640 | // this capability requires provisioning, route to the correct API. |
| 3641 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3642 | switch (capability) { |
| 3643 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3644 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3645 | ims.setEabProvisioned(isProvisioned); |
| 3646 | break; |
| 3647 | default: { |
| 3648 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3649 | + "rcs capability '" + capability + "', which does not require " |
| 3650 | + "provisioning."); |
| 3651 | } |
| 3652 | } |
| 3653 | } finally { |
| 3654 | Binder.restoreCallingIdentity(identity); |
| 3655 | } |
| 3656 | |
| 3657 | } |
| 3658 | |
| 3659 | |
| 3660 | @Override |
| 3661 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 3662 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 3663 | final long identity = Binder.clearCallingIdentity(); |
| 3664 | try { |
| 3665 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3666 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3667 | return true; |
| 3668 | } |
| 3669 | |
| 3670 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3671 | switch (capability) { |
| 3672 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3673 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3674 | return ims.isEabProvisionedOnDevice(); |
| 3675 | |
| 3676 | default: { |
| 3677 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 3678 | + "capability '" + capability + "', which does not require " |
| 3679 | + "provisioning."); |
| 3680 | } |
| 3681 | } |
| 3682 | |
| 3683 | } finally { |
| 3684 | Binder.restoreCallingIdentity(identity); |
| 3685 | } |
| 3686 | } |
| 3687 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3688 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3689 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3690 | boolean isProvisioned) { |
| 3691 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3692 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3693 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3694 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3695 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3696 | final long identity = Binder.clearCallingIdentity(); |
| 3697 | try { |
| 3698 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3699 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3700 | return; |
| 3701 | } |
| 3702 | |
| 3703 | // this capability requires provisioning, route to the correct API. |
| 3704 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3705 | switch (capability) { |
| 3706 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3707 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3708 | ims.setVolteProvisioned(isProvisioned); |
| 3709 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3710 | ims.setWfcProvisioned(isProvisioned); |
| 3711 | } |
| 3712 | break; |
| 3713 | } |
| 3714 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3715 | // There is currently no difference in VT provisioning type. |
| 3716 | ims.setVtProvisioned(isProvisioned); |
| 3717 | break; |
| 3718 | } |
| 3719 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3720 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3721 | // change the capability of the feature instead if needed. |
| 3722 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3723 | == isProvisioned) { |
| 3724 | // No change in provisioning. |
| 3725 | return; |
| 3726 | } |
| 3727 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3728 | try { |
| 3729 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3730 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3731 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3732 | + ", Exception" + e.getMessage()); |
| 3733 | } |
| 3734 | break; |
| 3735 | } |
| 3736 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3737 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3738 | + "MmTel capability '" + capability + "', which does not require " |
| 3739 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3740 | } |
| 3741 | } |
| 3742 | |
| 3743 | } finally { |
| 3744 | Binder.restoreCallingIdentity(identity); |
| 3745 | } |
| 3746 | } |
| 3747 | |
| 3748 | @Override |
| 3749 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3750 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3751 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3752 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3753 | } |
| 3754 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3755 | final long identity = Binder.clearCallingIdentity(); |
| 3756 | try { |
| 3757 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3758 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3759 | return true; |
| 3760 | } |
| 3761 | |
| 3762 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3763 | switch (capability) { |
| 3764 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3765 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3766 | return ims.isVolteProvisionedOnDevice(); |
| 3767 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3768 | return ims.isWfcProvisionedOnDevice(); |
| 3769 | } |
| 3770 | // This should never happen, since we are checking tech above to make sure it |
| 3771 | // is either LTE or IWLAN. |
| 3772 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3773 | + "capability."); |
| 3774 | } |
| 3775 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3776 | // There is currently no difference in VT provisioning type. |
| 3777 | return ims.isVtProvisionedOnDevice(); |
| 3778 | } |
| 3779 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3780 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3781 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3782 | } |
| 3783 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3784 | throw new IllegalArgumentException( |
| 3785 | "Tried to get provisioning for MmTel capability '" + capability |
| 3786 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3787 | } |
| 3788 | } |
| 3789 | |
| 3790 | } finally { |
| 3791 | Binder.restoreCallingIdentity(identity); |
| 3792 | } |
| 3793 | } |
| 3794 | |
| 3795 | @Override |
| 3796 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3797 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3798 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3799 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3800 | } |
| 3801 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3802 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3803 | return (provisionedBits & capability) > 0; |
| 3804 | } |
| 3805 | |
| 3806 | @Override |
| 3807 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3808 | boolean isProvisioned) { |
| 3809 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3810 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3811 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3812 | } |
| 3813 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3814 | "setProvisioningStatusForCapability"); |
| 3815 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3816 | // If the current provisioning status for capability already matches isProvisioned, |
| 3817 | // do nothing. |
| 3818 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3819 | return; |
| 3820 | } |
| 3821 | if (isProvisioned) { |
| 3822 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3823 | } else { |
| 3824 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 3825 | } |
| 3826 | } |
| 3827 | |
| 3828 | /** |
| 3829 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 3830 | * technology. The bitfield should mirror the bitfield defined by |
| 3831 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 3832 | */ |
| 3833 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 3834 | String key = getMmTelProvisioningKey(subId, tech); |
| 3835 | // Default is no capabilities are provisioned. |
| 3836 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 3837 | } |
| 3838 | |
| 3839 | /** |
| 3840 | * Sets the MmTel capability provisioning bitfield (defined by |
| 3841 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 3842 | * technology specified. |
| 3843 | * |
| 3844 | * Note: This is a synchronous command and should not be called on UI thread. |
| 3845 | */ |
| 3846 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 3847 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 3848 | String key = getMmTelProvisioningKey(subId, tech); |
| 3849 | editor.putInt(key, newField); |
| 3850 | editor.commit(); |
| 3851 | } |
| 3852 | |
| 3853 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 3854 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 3855 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 3856 | } |
| 3857 | |
| 3858 | /** |
| 3859 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 3860 | * carrier associated with the subscription id. |
| 3861 | */ |
| 3862 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 3863 | int capability) { |
| 3864 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 3865 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 3866 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 3867 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3868 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 3869 | false); |
| 3870 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 3871 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 3872 | |
| 3873 | // First check to make sure that the capability requires provisioning. |
| 3874 | switch (capability) { |
| 3875 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 3876 | // intentional fallthrough |
| 3877 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3878 | if (requireVoiceVtProvisioning) { |
| 3879 | // Voice and Video requires provisioning |
| 3880 | return true; |
| 3881 | } |
| 3882 | break; |
| 3883 | } |
| 3884 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3885 | if (requireUtProvisioning) { |
| 3886 | // UT requires provisioning |
| 3887 | return true; |
| 3888 | } |
| 3889 | break; |
| 3890 | } |
| 3891 | } |
| 3892 | return false; |
| 3893 | } |
| 3894 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3895 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 3896 | int capability) { |
| 3897 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 3898 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 3899 | |
| 3900 | boolean requireRcsProvisioning = c.getBoolean( |
| 3901 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 3902 | |
| 3903 | // First check to make sure that the capability requires provisioning. |
| 3904 | switch (capability) { |
| 3905 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3906 | // intentional fallthrough |
| 3907 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 3908 | if (requireRcsProvisioning) { |
| 3909 | // OPTION or PRESENCE requires provisioning |
| 3910 | return true; |
| 3911 | } |
| 3912 | break; |
| 3913 | } |
| 3914 | } |
| 3915 | return false; |
| 3916 | } |
| 3917 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3918 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3919 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3920 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3921 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3922 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3923 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 3924 | final long identity = Binder.clearCallingIdentity(); |
| 3925 | try { |
| 3926 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3927 | int slotId = getSlotIndex(subId); |
| 3928 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3929 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 3930 | + subId + "' for key:" + key); |
| 3931 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 3932 | } |
| 3933 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3934 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3935 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 3936 | + subId + "' for key:" + key); |
| 3937 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3938 | } finally { |
| 3939 | Binder.restoreCallingIdentity(identity); |
| 3940 | } |
| 3941 | } |
| 3942 | |
| 3943 | @Override |
| 3944 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3945 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3946 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3947 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3948 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 3949 | final long identity = Binder.clearCallingIdentity(); |
| 3950 | try { |
| 3951 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3952 | int slotId = getSlotIndex(subId); |
| 3953 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3954 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 3955 | + subId + "' for key:" + key); |
| 3956 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 3957 | } |
| 3958 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3959 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3960 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 3961 | + subId + "' for key:" + key); |
| 3962 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3963 | } finally { |
| 3964 | Binder.restoreCallingIdentity(identity); |
| 3965 | } |
| 3966 | } |
| 3967 | |
| 3968 | @Override |
| 3969 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3970 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3971 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3972 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3973 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3974 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3975 | final long identity = Binder.clearCallingIdentity(); |
| 3976 | try { |
| 3977 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3978 | int slotId = getSlotIndex(subId); |
| 3979 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3980 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 3981 | + subId + "' for key:" + key); |
| 3982 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 3983 | } |
| 3984 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3985 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3986 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 3987 | + "' for key:" + key); |
| 3988 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3989 | } finally { |
| 3990 | Binder.restoreCallingIdentity(identity); |
| 3991 | } |
| 3992 | } |
| 3993 | |
| 3994 | @Override |
| 3995 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3996 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3997 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 3998 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 3999 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4000 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4001 | final long identity = Binder.clearCallingIdentity(); |
| 4002 | try { |
| 4003 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4004 | int slotId = getSlotIndex(subId); |
| 4005 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4006 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4007 | + subId + "' for key:" + key); |
| 4008 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4009 | } |
| 4010 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4011 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4012 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4013 | + "' for key:" + key); |
| 4014 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4015 | } finally { |
| 4016 | Binder.restoreCallingIdentity(identity); |
| 4017 | } |
| 4018 | } |
| 4019 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4020 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4021 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4022 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4023 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4024 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4025 | } |
| 4026 | return slotId; |
| 4027 | } |
| 4028 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4029 | private int getSlotIndex(int subId) { |
| 4030 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4031 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4032 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4033 | } |
| 4034 | return slotId; |
| 4035 | } |
| 4036 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4037 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4038 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4039 | */ |
| 4040 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4041 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4042 | String callingFeatureId) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4043 | final int targetSdk = getTargetSdk(callingPackage); |
| 4044 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4045 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4046 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4047 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4048 | mApp, subId, callingPackage, callingFeatureId, |
| 4049 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4050 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4051 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4052 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4053 | final long identity = Binder.clearCallingIdentity(); |
| 4054 | try { |
| 4055 | final Phone phone = getPhone(subId); |
| 4056 | if (phone != null) { |
| 4057 | return phone.getServiceState().getDataNetworkType(); |
| 4058 | } else { |
| 4059 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4060 | } |
| 4061 | } finally { |
| 4062 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4063 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4064 | } |
| 4065 | |
| 4066 | /** |
| 4067 | * Returns the data network type |
| 4068 | */ |
| 4069 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4070 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4071 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4072 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4073 | } |
| 4074 | |
| 4075 | /** |
| 4076 | * Returns the data network type for a subId |
| 4077 | */ |
| 4078 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4079 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4080 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4081 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4082 | mApp, subId, callingPackage, callingFeatureId, |
| 4083 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4084 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4085 | } |
| 4086 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4087 | final long identity = Binder.clearCallingIdentity(); |
| 4088 | try { |
| 4089 | final Phone phone = getPhone(subId); |
| 4090 | if (phone != null) { |
| 4091 | return phone.getServiceState().getDataNetworkType(); |
| 4092 | } else { |
| 4093 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4094 | } |
| 4095 | } finally { |
| 4096 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4097 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4098 | } |
| 4099 | |
| 4100 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4101 | * Returns the Voice network type for a subId |
| 4102 | */ |
| 4103 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4104 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4105 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4106 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4107 | mApp, subId, callingPackage, callingFeatureId, |
| 4108 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4109 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4110 | } |
| 4111 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4112 | final long identity = Binder.clearCallingIdentity(); |
| 4113 | try { |
| 4114 | final Phone phone = getPhone(subId); |
| 4115 | if (phone != null) { |
| 4116 | return phone.getServiceState().getVoiceNetworkType(); |
| 4117 | } else { |
| 4118 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4119 | } |
| 4120 | } finally { |
| 4121 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4122 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4123 | } |
| 4124 | |
| 4125 | /** |
| 4126 | * @return true if a ICC card is present |
| 4127 | */ |
| 4128 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4129 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4130 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4131 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4132 | } |
| 4133 | |
| 4134 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4135 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4136 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4137 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4138 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4139 | final long identity = Binder.clearCallingIdentity(); |
| 4140 | try { |
| 4141 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4142 | if (phone != null) { |
| 4143 | return phone.getIccCard().hasIccCard(); |
| 4144 | } else { |
| 4145 | return false; |
| 4146 | } |
| 4147 | } finally { |
| 4148 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4149 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4150 | } |
| 4151 | |
| 4152 | /** |
| 4153 | * Return if the current radio is LTE on CDMA. This |
| 4154 | * is a tri-state return value as for a period of time |
| 4155 | * the mode may be unknown. |
| 4156 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4157 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4158 | * @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] | 4159 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4160 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4161 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4162 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4163 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4164 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4165 | } |
| 4166 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4167 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4168 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4169 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4170 | try { |
| 4171 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4172 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4173 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4174 | } |
| 4175 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4176 | final long identity = Binder.clearCallingIdentity(); |
| 4177 | try { |
| 4178 | final Phone phone = getPhone(subId); |
| 4179 | if (phone == null) { |
| 4180 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4181 | } else { |
| 4182 | return phone.getLteOnCdmaMode(); |
| 4183 | } |
| 4184 | } finally { |
| 4185 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4186 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4187 | } |
| 4188 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4189 | /** |
| 4190 | * {@hide} |
| 4191 | * Returns Default subId, 0 in the case of single standby. |
| 4192 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4193 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4194 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4195 | } |
| 4196 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4197 | private int getSlotForDefaultSubscription() { |
| 4198 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4199 | } |
| 4200 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4201 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4202 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4203 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4204 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4205 | private boolean isActiveSubscription(int subId) { |
| 4206 | return mSubscriptionController.isActiveSubId(subId); |
| 4207 | } |
| 4208 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4209 | /** |
| 4210 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4211 | */ |
| 4212 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4213 | final long identity = Binder.clearCallingIdentity(); |
| 4214 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4215 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4216 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4217 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4218 | } finally { |
| 4219 | Binder.restoreCallingIdentity(identity); |
| 4220 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4221 | } |
| 4222 | |
| 4223 | /** |
| 4224 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4225 | */ |
| 4226 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4227 | final long identity = Binder.clearCallingIdentity(); |
| 4228 | try { |
| 4229 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4230 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4231 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4232 | } finally { |
| 4233 | Binder.restoreCallingIdentity(identity); |
| 4234 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4235 | } |
| 4236 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4237 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4238 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4239 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4240 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4241 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4242 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4243 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4244 | if (phoneId == -1) { |
| 4245 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4246 | + " does not correspond to an active phone"); |
| 4247 | } |
| 4248 | return PhoneFactory.getPhone(phoneId); |
| 4249 | } |
| 4250 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4251 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4252 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4253 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4254 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4255 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4256 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4257 | if (DBG) { |
| 4258 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4259 | } |
| 4260 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4261 | p2); |
| 4262 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4263 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4264 | |
| 4265 | @Override |
| 4266 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4267 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4268 | enforceModifyPermission(); |
| 4269 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4270 | if (DBG) { |
| 4271 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4272 | } |
| 4273 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4274 | callingPackage, aid, p2); |
| 4275 | } |
| 4276 | |
| 4277 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4278 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4279 | final long identity = Binder.clearCallingIdentity(); |
| 4280 | try { |
| 4281 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4282 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4283 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4284 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4285 | if (bestComponent == null |
| 4286 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4287 | loge("The calling package is not allowed to access ISD-R."); |
| 4288 | throw new SecurityException( |
| 4289 | "The calling package is not allowed to access ISD-R."); |
| 4290 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4291 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4292 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4293 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4294 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4295 | null /* workSource */); |
| 4296 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4297 | return response; |
| 4298 | } finally { |
| 4299 | Binder.restoreCallingIdentity(identity); |
| 4300 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4301 | } |
| 4302 | |
| 4303 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4304 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4305 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4306 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4307 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4308 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4309 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4310 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4311 | @Override |
| 4312 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4313 | enforceModifyPermission(); |
| 4314 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4315 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4316 | channel); |
| 4317 | } |
| 4318 | |
| 4319 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4320 | final long identity = Binder.clearCallingIdentity(); |
| 4321 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4322 | if (channel < 0) { |
| 4323 | return false; |
| 4324 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4325 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4326 | null /* workSource */); |
| 4327 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4328 | return success; |
| 4329 | } finally { |
| 4330 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4331 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4332 | } |
| 4333 | |
| 4334 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4335 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4336 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4337 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4338 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4339 | if (DBG) { |
| 4340 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4341 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4342 | + p3 + " data=" + data); |
| 4343 | } |
| 4344 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4345 | command, p1, p2, p3, data); |
| 4346 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4347 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4348 | @Override |
| 4349 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4350 | int command, int p1, int p2, int p3, String data) { |
| 4351 | enforceModifyPermission(); |
| 4352 | if (DBG) { |
| 4353 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4354 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4355 | + p3 + " data=" + data); |
| 4356 | } |
| 4357 | return iccTransmitApduLogicalChannelWithPermission( |
| 4358 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4359 | data); |
| 4360 | } |
| 4361 | |
| 4362 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4363 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4364 | final long identity = Binder.clearCallingIdentity(); |
| 4365 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4366 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4367 | return ""; |
| 4368 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4369 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4370 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4371 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4372 | null /* workSource */); |
| 4373 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4374 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4375 | // Append the returned status code to the end of the response payload. |
| 4376 | String s = Integer.toHexString( |
| 4377 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4378 | if (response.payload != null) { |
| 4379 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4380 | } |
| 4381 | return s; |
| 4382 | } finally { |
| 4383 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4384 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4385 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4386 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4387 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4388 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4389 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4390 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4391 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4392 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4393 | if (DBG) { |
| 4394 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4395 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4396 | } |
| 4397 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4398 | cla, command, p1, p2, p3, data); |
| 4399 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4400 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4401 | @Override |
| 4402 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4403 | int command, int p1, int p2, int p3, String data) { |
| 4404 | enforceModifyPermission(); |
| 4405 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4406 | if (DBG) { |
| 4407 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4408 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4409 | + " data=" + data); |
| 4410 | } |
| 4411 | |
| 4412 | return iccTransmitApduBasicChannelWithPermission( |
| 4413 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4414 | p2, p3, data); |
| 4415 | } |
| 4416 | |
| 4417 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4418 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4419 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4420 | final long identity = Binder.clearCallingIdentity(); |
| 4421 | try { |
| 4422 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4423 | && TextUtils.equals(ISDR_AID, data)) { |
| 4424 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4425 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4426 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4427 | if (bestComponent == null |
| 4428 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4429 | loge("The calling package is not allowed to select ISD-R."); |
| 4430 | throw new SecurityException( |
| 4431 | "The calling package is not allowed to select ISD-R."); |
| 4432 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4433 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4434 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4435 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4436 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4437 | null /* workSource */); |
| 4438 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4439 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4440 | // Append the returned status code to the end of the response payload. |
| 4441 | String s = Integer.toHexString( |
| 4442 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4443 | if (response.payload != null) { |
| 4444 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4445 | } |
| 4446 | return s; |
| 4447 | } finally { |
| 4448 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4449 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4450 | } |
| 4451 | |
| 4452 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4453 | 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] | 4454 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4455 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4456 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4457 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4458 | final long identity = Binder.clearCallingIdentity(); |
| 4459 | try { |
| 4460 | if (DBG) { |
| 4461 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4462 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4463 | } |
| 4464 | |
| 4465 | IccIoResult response = |
| 4466 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4467 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4468 | subId); |
| 4469 | |
| 4470 | if (DBG) { |
| 4471 | log("Exchange SIM_IO [R]" + response); |
| 4472 | } |
| 4473 | |
| 4474 | byte[] result = null; |
| 4475 | int length = 2; |
| 4476 | if (response.payload != null) { |
| 4477 | length = 2 + response.payload.length; |
| 4478 | result = new byte[length]; |
| 4479 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4480 | } else { |
| 4481 | result = new byte[length]; |
| 4482 | } |
| 4483 | |
| 4484 | result[length - 1] = (byte) response.sw2; |
| 4485 | result[length - 2] = (byte) response.sw1; |
| 4486 | return result; |
| 4487 | } finally { |
| 4488 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4489 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4490 | } |
| 4491 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4492 | /** |
| 4493 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4494 | * on a particular subscription |
| 4495 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4496 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 4497 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4498 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4499 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4500 | return null; |
| 4501 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4502 | |
| 4503 | final long identity = Binder.clearCallingIdentity(); |
| 4504 | try { |
| 4505 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4506 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4507 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4508 | return null; |
| 4509 | } |
| 4510 | Object response = sendRequest( |
| 4511 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4512 | if (response instanceof String[]) { |
| 4513 | return (String[]) response; |
| 4514 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4515 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4516 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4517 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4518 | } finally { |
| 4519 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4520 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4521 | } |
| 4522 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4523 | /** |
| 4524 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 4525 | * subscription. |
| 4526 | * |
| 4527 | * @param subId the id of the subscription. |
| 4528 | * @param appType the uicc app type, must be USIM or SIM. |
| 4529 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 4530 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4531 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4532 | * @return number of fplmns that is successfully written to the SIM. |
| 4533 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4534 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 4535 | String callingFeatureId) { |
| 4536 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 4537 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4538 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 4539 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 4540 | } |
| 4541 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 4542 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4543 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 4544 | } |
| 4545 | if (fplmns == null) { |
| 4546 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 4547 | } |
| 4548 | for (String fplmn : fplmns) { |
| 4549 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 4550 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 4551 | } |
| 4552 | } |
| 4553 | final long identity = Binder.clearCallingIdentity(); |
| 4554 | try { |
| 4555 | Object response = sendRequest( |
| 4556 | CMD_SET_FORBIDDEN_PLMNS, |
| 4557 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 4558 | subId); |
| 4559 | return (int) response; |
| 4560 | } finally { |
| 4561 | Binder.restoreCallingIdentity(identity); |
| 4562 | } |
| 4563 | } |
| 4564 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4565 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4566 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4567 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4568 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4569 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4570 | final long identity = Binder.clearCallingIdentity(); |
| 4571 | try { |
| 4572 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4573 | if (response.payload == null) { |
| 4574 | return ""; |
| 4575 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4576 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4577 | // Append the returned status code to the end of the response payload. |
| 4578 | String s = Integer.toHexString( |
| 4579 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4580 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4581 | return s; |
| 4582 | } finally { |
| 4583 | Binder.restoreCallingIdentity(identity); |
| 4584 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4585 | } |
| 4586 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4587 | /** |
| 4588 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4589 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4590 | * |
| 4591 | * @param itemID the ID of the item to read |
| 4592 | * @return the NV item as a String, or null on error. |
| 4593 | */ |
| 4594 | @Override |
| 4595 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4596 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4597 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4598 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4599 | |
| 4600 | final long identity = Binder.clearCallingIdentity(); |
| 4601 | try { |
| 4602 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4603 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4604 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4605 | return value; |
| 4606 | } finally { |
| 4607 | Binder.restoreCallingIdentity(identity); |
| 4608 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4609 | } |
| 4610 | |
| 4611 | /** |
| 4612 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4613 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4614 | * |
| 4615 | * @param itemID the ID of the item to read |
| 4616 | * @param itemValue the value to write, as a String |
| 4617 | * @return true on success; false on any failure |
| 4618 | */ |
| 4619 | @Override |
| 4620 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4621 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4622 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4623 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4624 | |
| 4625 | final long identity = Binder.clearCallingIdentity(); |
| 4626 | try { |
| 4627 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4628 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4629 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4630 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4631 | return success; |
| 4632 | } finally { |
| 4633 | Binder.restoreCallingIdentity(identity); |
| 4634 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4635 | } |
| 4636 | |
| 4637 | /** |
| 4638 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4639 | * Used for device configuration by some CDMA operators. |
| 4640 | * |
| 4641 | * @param preferredRoamingList byte array containing the new PRL |
| 4642 | * @return true on success; false on any failure |
| 4643 | */ |
| 4644 | @Override |
| 4645 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4646 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4647 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4648 | |
| 4649 | final long identity = Binder.clearCallingIdentity(); |
| 4650 | try { |
| 4651 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4652 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4653 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4654 | return success; |
| 4655 | } finally { |
| 4656 | Binder.restoreCallingIdentity(identity); |
| 4657 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4658 | } |
| 4659 | |
| 4660 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4661 | * 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] | 4662 | * Used for device configuration by some CDMA operators. |
| 4663 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4664 | * @param slotIndex - device slot. |
| 4665 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4666 | * @return true on success; false on any failure |
| 4667 | */ |
| 4668 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4669 | public boolean resetModemConfig(int slotIndex) { |
| 4670 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4671 | if (phone != null) { |
| 4672 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4673 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4674 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4675 | final long identity = Binder.clearCallingIdentity(); |
| 4676 | try { |
| 4677 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4678 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4679 | return success; |
| 4680 | } finally { |
| 4681 | Binder.restoreCallingIdentity(identity); |
| 4682 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4683 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4684 | return false; |
| 4685 | } |
| 4686 | |
| 4687 | /** |
| 4688 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4689 | * |
| 4690 | * @param slotIndex - device slot. |
| 4691 | * |
| 4692 | * @return true on success; false on any failure |
| 4693 | */ |
| 4694 | @Override |
| 4695 | public boolean rebootModem(int slotIndex) { |
| 4696 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4697 | if (phone != null) { |
| 4698 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4699 | mApp, phone.getSubId(), "rebootModem"); |
| 4700 | |
| 4701 | final long identity = Binder.clearCallingIdentity(); |
| 4702 | try { |
| 4703 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4704 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4705 | return success; |
| 4706 | } finally { |
| 4707 | Binder.restoreCallingIdentity(identity); |
| 4708 | } |
| 4709 | } |
| 4710 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4711 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4712 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4713 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 4714 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4715 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4716 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4717 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4718 | return new String[0]; |
| 4719 | } |
| 4720 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4721 | final long identity = Binder.clearCallingIdentity(); |
| 4722 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4723 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4724 | } finally { |
| 4725 | Binder.restoreCallingIdentity(identity); |
| 4726 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4727 | } |
| 4728 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4729 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4730 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4731 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4732 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4733 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4734 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4735 | |
| 4736 | final long identity = Binder.clearCallingIdentity(); |
| 4737 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4738 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4739 | // may happen if the device does not support IMS. |
| 4740 | return; |
| 4741 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4742 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4743 | } finally { |
| 4744 | Binder.restoreCallingIdentity(identity); |
| 4745 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4746 | } |
| 4747 | |
| 4748 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4749 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4750 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4751 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4752 | public void disableIms(int slotId) { |
| 4753 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4754 | |
| 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 | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4761 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4762 | } finally { |
| 4763 | Binder.restoreCallingIdentity(identity); |
| 4764 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4765 | } |
| 4766 | |
| 4767 | /** |
| 4768 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4769 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4770 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4771 | */ |
| 4772 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4773 | IImsServiceFeatureCallback callback) { |
| 4774 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4775 | |
| 4776 | final long identity = Binder.clearCallingIdentity(); |
| 4777 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4778 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4779 | // may happen if the device does not support IMS. |
| 4780 | return null; |
| 4781 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4782 | return mImsResolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4783 | } finally { |
| 4784 | Binder.restoreCallingIdentity(identity); |
| 4785 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4786 | } |
| 4787 | |
| 4788 | /** |
| 4789 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4790 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4791 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4792 | * listener for feature updates. |
| 4793 | */ |
| 4794 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4795 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4796 | |
| 4797 | final long identity = Binder.clearCallingIdentity(); |
| 4798 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4799 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4800 | // may happen if the device does not support IMS. |
| 4801 | return null; |
| 4802 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4803 | return mImsResolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4804 | } finally { |
| 4805 | Binder.restoreCallingIdentity(identity); |
| 4806 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4807 | } |
| 4808 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4809 | /** |
| 4810 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4811 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4812 | */ |
| 4813 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 4814 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4815 | |
| 4816 | final long identity = Binder.clearCallingIdentity(); |
| 4817 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4818 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4819 | // may happen if the device does not support IMS. |
| 4820 | return null; |
| 4821 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4822 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4823 | } finally { |
| 4824 | Binder.restoreCallingIdentity(identity); |
| 4825 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 4826 | } |
| 4827 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4828 | /** |
| 4829 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4830 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4831 | */ |
| 4832 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 4833 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4834 | |
| 4835 | final long identity = Binder.clearCallingIdentity(); |
| 4836 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4837 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4838 | // may happen if the device does not support IMS. |
| 4839 | return null; |
| 4840 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4841 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4842 | } finally { |
| 4843 | Binder.restoreCallingIdentity(identity); |
| 4844 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4845 | } |
| 4846 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 4847 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4848 | * Sets the ImsService Package Name that Telephony will bind to. |
| 4849 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4850 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 4851 | * @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] | 4852 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4853 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 4854 | * @param packageName The name of the package that the current configuration will be replaced |
| 4855 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4856 | * @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] | 4857 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4858 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 4859 | int[] featureTypes, String packageName) { |
| 4860 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 4861 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4862 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 4863 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4864 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4865 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4866 | final long identity = Binder.clearCallingIdentity(); |
| 4867 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4868 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4869 | // may happen if the device does not support IMS. |
| 4870 | return false; |
| 4871 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4872 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 4873 | for (int featureType : featureTypes) { |
| 4874 | featureConfig.put(featureType, packageName); |
| 4875 | } |
| 4876 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 4877 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4878 | } finally { |
| 4879 | Binder.restoreCallingIdentity(identity); |
| 4880 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4881 | } |
| 4882 | |
| 4883 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4884 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4885 | * |
| 4886 | * @param slotId The slot that the ImsService is associated with. |
| 4887 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 4888 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4889 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4890 | * @return the package name of the ImsService configuration. |
| 4891 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4892 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 4893 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4894 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4895 | TelephonyPermissions |
| 4896 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 4897 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 4898 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 4899 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4900 | final long identity = Binder.clearCallingIdentity(); |
| 4901 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4902 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4903 | // may happen if the device does not support IMS. |
| 4904 | return ""; |
| 4905 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 4906 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4907 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 4908 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4909 | } finally { |
| 4910 | Binder.restoreCallingIdentity(identity); |
| 4911 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 4912 | } |
| 4913 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 4914 | /** |
| 4915 | * Get the MmTelFeature state associated with the requested subscription id. |
| 4916 | * @param subId The subscription that the MmTelFeature is associated with. |
| 4917 | * @param callback A callback with an integer containing the |
| 4918 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 4919 | */ |
| 4920 | @Override |
| 4921 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 4922 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 4923 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 4924 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4925 | "IMS not available on device."); |
| 4926 | } |
| 4927 | final long token = Binder.clearCallingIdentity(); |
| 4928 | try { |
| 4929 | int slotId = getSlotIndex(subId); |
| 4930 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4931 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 4932 | + subId + "'"); |
| 4933 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 4934 | } |
| 4935 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 4936 | try { |
| 4937 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 4938 | } catch (RemoteException e) { |
| 4939 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 4940 | + "Ignore"); |
| 4941 | } |
| 4942 | }); |
| 4943 | } finally { |
| 4944 | Binder.restoreCallingIdentity(token); |
| 4945 | } |
| 4946 | } |
| 4947 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4948 | public void setImsRegistrationState(boolean registered) { |
| 4949 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4950 | |
| 4951 | final long identity = Binder.clearCallingIdentity(); |
| 4952 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4953 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4954 | } finally { |
| 4955 | Binder.restoreCallingIdentity(identity); |
| 4956 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4957 | } |
| 4958 | |
| 4959 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4960 | * Set the network selection mode to automatic. |
| 4961 | * |
| 4962 | */ |
| 4963 | @Override |
| 4964 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4965 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4966 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4967 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4968 | if (!isActiveSubscription(subId)) { |
| 4969 | return; |
| 4970 | } |
| 4971 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4972 | final long identity = Binder.clearCallingIdentity(); |
| 4973 | try { |
| 4974 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 4975 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 4976 | } finally { |
| 4977 | Binder.restoreCallingIdentity(identity); |
| 4978 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 4979 | } |
| 4980 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4981 | /** |
| 4982 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 4983 | * |
| 4984 | * @param subId the id of the subscription. |
| 4985 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 4986 | * the operator to attach to. |
| 4987 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 4988 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 4989 | * normal network selection next time. |
| 4990 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 4991 | */ |
| 4992 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 4993 | public boolean setNetworkSelectionModeManual( |
| 4994 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4995 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4996 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4997 | |
| 4998 | if (!isActiveSubscription(subId)) { |
| 4999 | return false; |
| 5000 | } |
| 5001 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5002 | final long identity = Binder.clearCallingIdentity(); |
| 5003 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5004 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5005 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5006 | if (DBG) { |
| 5007 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5008 | + " operator: " + operatorInfo); |
| 5009 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5010 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5011 | } finally { |
| 5012 | Binder.restoreCallingIdentity(identity); |
| 5013 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5014 | } |
| 5015 | |
| 5016 | /** |
| 5017 | * Scans for available networks. |
| 5018 | */ |
| 5019 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5020 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5021 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5022 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5023 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5024 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5025 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5026 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5027 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5028 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5029 | .setCallingPid(Binder.getCallingPid()) |
| 5030 | .setCallingUid(Binder.getCallingUid()) |
| 5031 | .setMethod("getCellNetworkScanResults") |
| 5032 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5033 | .build()); |
| 5034 | switch (locationResult) { |
| 5035 | case DENIED_HARD: |
| 5036 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5037 | case DENIED_SOFT: |
| 5038 | return null; |
| 5039 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5040 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5041 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5042 | try { |
| 5043 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5044 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5045 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5046 | } finally { |
| 5047 | Binder.restoreCallingIdentity(identity); |
| 5048 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5049 | } |
| 5050 | |
| 5051 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5052 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5053 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5054 | * @param subId id of the subscription |
| 5055 | * @param request contains the radio access networks with bands/channels to scan |
| 5056 | * @param messenger callback messenger for scan results or errors |
| 5057 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5058 | * @return the id of the requested scan which can be used to stop the scan. |
| 5059 | */ |
| 5060 | @Override |
| 5061 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5062 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5063 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5064 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5065 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5066 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5067 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5068 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5069 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5070 | .setCallingPid(Binder.getCallingPid()) |
| 5071 | .setCallingUid(Binder.getCallingUid()) |
| 5072 | .setMethod("requestNetworkScan") |
| 5073 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5074 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5075 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5076 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5077 | if (e != null) { |
| 5078 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5079 | throw e; |
| 5080 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5081 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5082 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5083 | } |
| 5084 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5085 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5086 | int callingUid = Binder.getCallingUid(); |
| 5087 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5088 | final long identity = Binder.clearCallingIdentity(); |
| 5089 | try { |
| 5090 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5091 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5092 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5093 | } finally { |
| 5094 | Binder.restoreCallingIdentity(identity); |
| 5095 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5096 | } |
| 5097 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5098 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5099 | NetworkScanRequest request, int subId) { |
| 5100 | boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid()) |
| 5101 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5102 | boolean hasNetworkScanPermission = |
| 5103 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5104 | == PERMISSION_GRANTED; |
| 5105 | |
| 5106 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5107 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5108 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5109 | } |
| 5110 | |
| 5111 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5112 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5113 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5114 | return new SecurityException("Specific channels must not be" |
| 5115 | + " scanned without location access."); |
| 5116 | } |
| 5117 | } |
| 5118 | } |
| 5119 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5120 | return null; |
| 5121 | } |
| 5122 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5123 | /** |
| 5124 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5125 | * |
| 5126 | * @param subId id of the subscription |
| 5127 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5128 | */ |
| 5129 | @Override |
| 5130 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5131 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5132 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5133 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5134 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5135 | final long identity = Binder.clearCallingIdentity(); |
| 5136 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5137 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5138 | } finally { |
| 5139 | Binder.restoreCallingIdentity(identity); |
| 5140 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5141 | } |
| 5142 | |
| 5143 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5144 | * Get the calculated preferred network type. |
| 5145 | * Used for debugging incorrect network type. |
| 5146 | * |
| 5147 | * @return the preferred network type, defined in RILConstants.java. |
| 5148 | */ |
| 5149 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5150 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5151 | final Phone defaultPhone = getDefaultPhone(); |
| 5152 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5153 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5154 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5155 | } |
| 5156 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5157 | final long identity = Binder.clearCallingIdentity(); |
| 5158 | try { |
| 5159 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5160 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5161 | } finally { |
| 5162 | Binder.restoreCallingIdentity(identity); |
| 5163 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5164 | } |
| 5165 | |
| 5166 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5167 | * Get the preferred network type. |
| 5168 | * Used for device configuration by some CDMA operators. |
| 5169 | * |
| 5170 | * @return the preferred network type, defined in RILConstants.java. |
| 5171 | */ |
| 5172 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5173 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5174 | TelephonyPermissions |
| 5175 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5176 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5177 | |
| 5178 | final long identity = Binder.clearCallingIdentity(); |
| 5179 | try { |
| 5180 | if (DBG) log("getPreferredNetworkType"); |
| 5181 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5182 | int networkType = (result != null ? result[0] : -1); |
| 5183 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5184 | return networkType; |
| 5185 | } finally { |
| 5186 | Binder.restoreCallingIdentity(identity); |
| 5187 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5188 | } |
| 5189 | |
| 5190 | /** |
| 5191 | * Set the preferred network type. |
| 5192 | * Used for device configuration by some CDMA operators. |
| 5193 | * |
| 5194 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5195 | * @return true on success; false on any failure. |
| 5196 | */ |
| 5197 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5198 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5199 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5200 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5201 | |
| 5202 | final long identity = Binder.clearCallingIdentity(); |
| 5203 | try { |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5204 | Settings.Global.putInt(mApp.getContentResolver(), |
| 5205 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 5206 | return setPreferredNetworkTypesInternal(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5207 | } finally { |
| 5208 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5209 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5210 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5211 | |
| 5212 | /** |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5213 | * Get the allowed network types that store in the telephony provider. |
| 5214 | * |
| 5215 | * @param subId the id of the subscription. |
| 5216 | * @return allowedNetworkTypes the allowed network types. |
| 5217 | */ |
| 5218 | @Override |
| 5219 | public long getAllowedNetworkTypes(int subId) { |
| 5220 | TelephonyPermissions |
| 5221 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5222 | mApp, subId, "getAllowedNetworkTypes"); |
| 5223 | |
| 5224 | final long identity = Binder.clearCallingIdentity(); |
| 5225 | try { |
| 5226 | return SubscriptionManager.getLongSubscriptionProperty( |
| 5227 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5228 | } finally { |
| 5229 | Binder.restoreCallingIdentity(identity); |
| 5230 | } |
| 5231 | } |
| 5232 | |
| 5233 | /** |
| 5234 | * Set the allowed network types. |
| 5235 | * |
| 5236 | * @param subId the id of the subscription. |
| 5237 | * @param allowedNetworkTypes the allowed network types. |
| 5238 | * @return true on success; false on any failure. |
| 5239 | */ |
| 5240 | @Override |
| 5241 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 5242 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5243 | mApp, subId, "setAllowedNetworkTypes"); |
| 5244 | final long identity = Binder.clearCallingIdentity(); |
| 5245 | try { |
| 5246 | SubscriptionManager.setSubscriptionProperty(subId, |
| 5247 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 5248 | String.valueOf(allowedNetworkTypes)); |
| 5249 | return setPreferredNetworkTypesInternal(subId); |
| 5250 | } finally { |
| 5251 | Binder.restoreCallingIdentity(identity); |
| 5252 | } |
| 5253 | } |
| 5254 | |
| 5255 | private boolean setPreferredNetworkTypesInternal(int subId) { |
| 5256 | long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType( |
| 5257 | Settings.Global.getInt(mApp.getContentResolver(), |
| 5258 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5259 | RILConstants.PREFERRED_NETWORK_MODE)); |
| 5260 | long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty( |
| 5261 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5262 | int networkMode = RadioAccessFamily.getNetworkTypeFromRaf( |
| 5263 | (int) (networkTypeBitMask & allowedNetworkTypes)); |
| 5264 | |
| 5265 | if (DBG) { |
| 5266 | log("setPreferredNetworkTypesInternal: subId " + subId |
| 5267 | + " networkTypes " + networkTypeBitMask |
| 5268 | + " allowedNetworkTypes " + allowedNetworkTypes |
| 5269 | + " networkMode " + networkMode); |
| 5270 | } |
| 5271 | |
| 5272 | Boolean success = (Boolean) sendRequest( |
| 5273 | CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId); |
| 5274 | if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail")); |
| 5275 | return success; |
| 5276 | } |
| 5277 | |
| 5278 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5279 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5280 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5281 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 5282 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5283 | * @hide |
| 5284 | */ |
| 5285 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 5286 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5287 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5288 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5289 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5290 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5291 | if (phone != null) { |
| 5292 | return phone.hasMatchedTetherApnSetting(); |
| 5293 | } else { |
| 5294 | return false; |
| 5295 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5296 | } finally { |
| 5297 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5298 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5299 | } |
| 5300 | |
| 5301 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5302 | * Set mobile data enabled |
| 5303 | * Used by the user through settings etc to turn on/off mobile data |
| 5304 | * |
| 5305 | * @param enable {@code true} turn turn data on, else {@code false} |
| 5306 | */ |
| 5307 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5308 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5309 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5310 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5311 | |
| 5312 | final long identity = Binder.clearCallingIdentity(); |
| 5313 | try { |
| 5314 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5315 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5316 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5317 | if (phone != null) { |
| 5318 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5319 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5320 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5321 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5322 | } |
| 5323 | } finally { |
| 5324 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5325 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5326 | } |
| 5327 | |
| 5328 | /** |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 5329 | * Enable or disable always reporting signal strength changes from radio. |
| 5330 | * |
| 5331 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 5332 | */ |
| 5333 | @Override |
| 5334 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 5335 | enforceModifyPermission(); |
| 5336 | enforceSystemCaller(); |
| 5337 | |
| 5338 | final long identity = Binder.clearCallingIdentity(); |
| 5339 | final Phone phone = getPhone(subId); |
| 5340 | try { |
| 5341 | if (phone != null) { |
| 5342 | if (DBG) { |
| 5343 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 5344 | + " isEnable=" + isEnable); |
| 5345 | } |
| 5346 | phone.setAlwaysReportSignalStrength(isEnable); |
| 5347 | } else { |
| 5348 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 5349 | + subId); |
| 5350 | } |
| 5351 | } finally { |
| 5352 | Binder.restoreCallingIdentity(identity); |
| 5353 | } |
| 5354 | } |
| 5355 | |
| 5356 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5357 | * Get the user enabled state of Mobile Data. |
| 5358 | * |
| 5359 | * TODO: remove and use isUserDataEnabled. |
| 5360 | * This can't be removed now because some vendor codes |
| 5361 | * calls through ITelephony directly while they should |
| 5362 | * use TelephonyManager. |
| 5363 | * |
| 5364 | * @return true on enabled |
| 5365 | */ |
| 5366 | @Override |
| 5367 | public boolean getDataEnabled(int subId) { |
| 5368 | return isUserDataEnabled(subId); |
| 5369 | } |
| 5370 | |
| 5371 | /** |
| 5372 | * Get whether mobile data is enabled per user setting. |
| 5373 | * |
| 5374 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 5375 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5376 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 5377 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5378 | * |
| 5379 | * @return {@code true} if data is enabled else {@code false} |
| 5380 | */ |
| 5381 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5382 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5383 | try { |
| 5384 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 5385 | null); |
| 5386 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5387 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5388 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5389 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5390 | |
| 5391 | final long identity = Binder.clearCallingIdentity(); |
| 5392 | try { |
| 5393 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5394 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5395 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5396 | if (phone != null) { |
| 5397 | boolean retVal = phone.isUserDataEnabled(); |
| 5398 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5399 | return retVal; |
| 5400 | } else { |
| 5401 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5402 | return false; |
| 5403 | } |
| 5404 | } finally { |
| 5405 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5406 | } |
| 5407 | } |
| 5408 | |
| 5409 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5410 | * Checks if the device is capable of mobile data by considering whether whether the |
| 5411 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 5412 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5413 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5414 | * @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] | 5415 | */ |
| 5416 | @Override |
| 5417 | public boolean isDataEnabled(int subId) { |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5418 | enforceReadPrivilegedPermission("isDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5419 | |
| 5420 | final long identity = Binder.clearCallingIdentity(); |
| 5421 | try { |
| 5422 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5423 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5424 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5425 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5426 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5427 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5428 | return retVal; |
| 5429 | } else { |
| 5430 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5431 | return false; |
| 5432 | } |
| 5433 | } finally { |
| 5434 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5435 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5436 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5437 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5438 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, |
| 5439 | Phone phone) { |
| 5440 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5441 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5442 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5443 | || subController == null) return privilegeFromSim; |
| 5444 | |
| 5445 | int uid = Binder.getCallingUid(); |
| 5446 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 5447 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 5448 | |
| 5449 | final long identity = Binder.clearCallingIdentity(); |
| 5450 | try { |
| 5451 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5452 | SubscriptionManager subManager = (SubscriptionManager) |
| 5453 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5454 | for (String pkg : packages) { |
| 5455 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 5456 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5457 | } |
| 5458 | } |
| 5459 | return privilegeFromSim; |
| 5460 | } finally { |
| 5461 | Binder.restoreCallingIdentity(identity); |
| 5462 | } |
| 5463 | } |
| 5464 | |
| 5465 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 5466 | String pkgName) { |
| 5467 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5468 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5469 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5470 | || subController == null) return privilegeFromSim; |
| 5471 | |
| 5472 | final long identity = Binder.clearCallingIdentity(); |
| 5473 | try { |
| 5474 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5475 | SubscriptionManager subManager = (SubscriptionManager) |
| 5476 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5477 | return subManager.canManageSubscription(subInfo, pkgName) |
| 5478 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 5479 | } finally { |
| 5480 | Binder.restoreCallingIdentity(identity); |
| 5481 | } |
| 5482 | } |
| 5483 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5484 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5485 | public int getCarrierPrivilegeStatus(int subId) { |
| 5486 | final Phone phone = getPhone(subId); |
| 5487 | if (phone == null) { |
| 5488 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 5489 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5490 | } |
| 5491 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5492 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 5493 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5494 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5495 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5496 | |
| 5497 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5498 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
| 5499 | phone.getContext().getPackageManager()), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5500 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5501 | |
| 5502 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5503 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5504 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5505 | final Phone phone = getPhone(subId); |
| 5506 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5507 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5508 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5509 | } |
| 5510 | UiccProfile profile = |
| 5511 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 5512 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5513 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5514 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5515 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5516 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5517 | profile.getCarrierPrivilegeStatusForUid( |
| 5518 | phone.getContext().getPackageManager(), uid), phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5519 | } |
| 5520 | |
| 5521 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5522 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 5523 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5524 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5525 | } |
| 5526 | |
| 5527 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 5528 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5529 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5530 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5531 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5532 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5533 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5534 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5535 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5536 | } |
| 5537 | |
| 5538 | @Override |
| 5539 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5540 | if (TextUtils.isEmpty(pkgName)) |
| 5541 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5542 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5543 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5544 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 5545 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 5546 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5547 | continue; |
| 5548 | } |
| 5549 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5550 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5551 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5552 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5553 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 5554 | break; |
| 5555 | } |
| 5556 | } |
| 5557 | |
| 5558 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5559 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 5560 | |
| 5561 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 5562 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 5563 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 5564 | loge("phoneId " + phoneId + " is not valid."); |
| 5565 | return null; |
| 5566 | } |
| 5567 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5568 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5569 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5570 | return null ; |
| 5571 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5572 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5573 | } |
| 5574 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5575 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5576 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5577 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5578 | List<String> privilegedPackages = new ArrayList<>(); |
| 5579 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5580 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 5581 | // has UICC in that slot. |
| 5582 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5583 | if (card.hasCarrierPrivilegeRules()) { |
| 5584 | if (packages == null) { |
| 5585 | // Only check packages in user 0 for now |
| 5586 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5587 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 5588 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 5589 | | PackageManager.GET_SIGNING_CERTIFICATES, |
| 5590 | UserHandle.USER_SYSTEM); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5591 | } |
| 5592 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 5593 | PackageInfo pkgInfo = packages.get(p); |
| 5594 | if (pkgInfo != null && pkgInfo.packageName != null |
| 5595 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5596 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5597 | privilegedPackages.add(pkgInfo.packageName); |
| 5598 | } |
| 5599 | } |
| 5600 | } |
| 5601 | } |
| 5602 | return privilegedPackages; |
| 5603 | } |
| 5604 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5605 | @Override |
| 5606 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5607 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 5608 | |
| 5609 | final long identity = Binder.clearCallingIdentity(); |
| 5610 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5611 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5612 | try { |
| 5613 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5614 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 5615 | } |
| 5616 | } finally { |
| 5617 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5618 | } |
| 5619 | return privilegedPackages; |
| 5620 | } |
| 5621 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5622 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5623 | final Phone phone = getPhone(subId); |
| 5624 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5625 | if (card == null) { |
| 5626 | loge("getIccId: No UICC"); |
| 5627 | return null; |
| 5628 | } |
| 5629 | String iccId = card.getIccId(); |
| 5630 | if (TextUtils.isEmpty(iccId)) { |
| 5631 | loge("getIccId: ICC ID is null or empty."); |
| 5632 | return null; |
| 5633 | } |
| 5634 | return iccId; |
| 5635 | } |
| 5636 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5637 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5638 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 5639 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5640 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5641 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5642 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5643 | final long identity = Binder.clearCallingIdentity(); |
| 5644 | try { |
| 5645 | final String iccId = getIccId(subId); |
| 5646 | final Phone phone = getPhone(subId); |
| 5647 | if (phone == null) { |
| 5648 | return false; |
| 5649 | } |
| 5650 | final String subscriberId = phone.getSubscriberId(); |
| 5651 | |
| 5652 | if (DBG_MERGE) { |
| 5653 | Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
| 5654 | + subscriberId + " to " + number); |
| 5655 | } |
| 5656 | |
| 5657 | if (TextUtils.isEmpty(iccId)) { |
| 5658 | return false; |
| 5659 | } |
| 5660 | |
| 5661 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 5662 | |
| 5663 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5664 | if (alphaTag == null) { |
| 5665 | editor.remove(alphaTagPrefKey); |
| 5666 | } else { |
| 5667 | editor.putString(alphaTagPrefKey, alphaTag); |
| 5668 | } |
| 5669 | |
| 5670 | // Record both the line number and IMSI for this ICCID, since we need to |
| 5671 | // track all merged IMSIs based on line number |
| 5672 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5673 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5674 | if (number == null) { |
| 5675 | editor.remove(numberPrefKey); |
| 5676 | editor.remove(subscriberPrefKey); |
| 5677 | } else { |
| 5678 | editor.putString(numberPrefKey, number); |
| 5679 | editor.putString(subscriberPrefKey, subscriberId); |
| 5680 | } |
| 5681 | |
| 5682 | editor.commit(); |
| 5683 | return true; |
| 5684 | } finally { |
| 5685 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5686 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5687 | } |
| 5688 | |
| 5689 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5690 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 5691 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 5692 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5693 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5694 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5695 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5696 | return null; |
| 5697 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5698 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5699 | final long identity = Binder.clearCallingIdentity(); |
| 5700 | try { |
| 5701 | String iccId = getIccId(subId); |
| 5702 | if (iccId != null) { |
| 5703 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5704 | if (DBG_MERGE) { |
| 5705 | log("getLine1NumberForDisplay returning " |
| 5706 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 5707 | } |
| 5708 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5709 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5710 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 5711 | return null; |
| 5712 | } finally { |
| 5713 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5714 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5715 | } |
| 5716 | |
| 5717 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5718 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 5719 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5720 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5721 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5722 | return null; |
| 5723 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5724 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5725 | final long identity = Binder.clearCallingIdentity(); |
| 5726 | try { |
| 5727 | String iccId = getIccId(subId); |
| 5728 | if (iccId != null) { |
| 5729 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5730 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 5731 | } |
| 5732 | return null; |
| 5733 | } finally { |
| 5734 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5735 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5736 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5737 | |
| 5738 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5739 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 5740 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5741 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 5742 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5743 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5744 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5745 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5746 | return null; |
| 5747 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5748 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5749 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 5750 | // the process, where TelephonyManager was instantiated. |
| 5751 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5752 | final long identity = Binder.clearCallingIdentity(); |
| 5753 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5754 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5755 | final TelephonyManager tele = TelephonyManager.from(context); |
| 5756 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 5757 | |
| 5758 | // Figure out what subscribers are currently active |
| 5759 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5760 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 5761 | // Only consider subs which match the current subId |
| 5762 | // This logic can be simplified. See b/131189269 for progress. |
| 5763 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5764 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 5765 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5766 | |
| 5767 | // First pass, find a number override for an active subscriber |
| 5768 | String mergeNumber = null; |
| 5769 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 5770 | for (String key : prefs.keySet()) { |
| 5771 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 5772 | final String subscriberId = (String) prefs.get(key); |
| 5773 | if (activeSubscriberIds.contains(subscriberId)) { |
| 5774 | final String iccId = key.substring( |
| 5775 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 5776 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5777 | mergeNumber = (String) prefs.get(numberKey); |
| 5778 | if (DBG_MERGE) { |
| 5779 | Slog.d(LOG_TAG, "Found line number " + mergeNumber |
| 5780 | + " for active subscriber " + subscriberId); |
| 5781 | } |
| 5782 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 5783 | break; |
| 5784 | } |
| 5785 | } |
| 5786 | } |
| 5787 | } |
| 5788 | |
| 5789 | // Shortcut when no active merged subscribers |
| 5790 | if (TextUtils.isEmpty(mergeNumber)) { |
| 5791 | return null; |
| 5792 | } |
| 5793 | |
| 5794 | // Second pass, find all subscribers under that line override |
| 5795 | final ArraySet<String> result = new ArraySet<>(); |
| 5796 | for (String key : prefs.keySet()) { |
| 5797 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 5798 | final String number = (String) prefs.get(key); |
| 5799 | if (mergeNumber.equals(number)) { |
| 5800 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 5801 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5802 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 5803 | if (!TextUtils.isEmpty(subscriberId)) { |
| 5804 | result.add(subscriberId); |
| 5805 | } |
| 5806 | } |
| 5807 | } |
| 5808 | } |
| 5809 | |
| 5810 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 5811 | Arrays.sort(resultArray); |
| 5812 | if (DBG_MERGE) { |
| 5813 | Slog.d(LOG_TAG, |
| 5814 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 5815 | } |
| 5816 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 5817 | } finally { |
| 5818 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5819 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5820 | } |
| 5821 | |
| 5822 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 5823 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 5824 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 5825 | |
| 5826 | final long identity = Binder.clearCallingIdentity(); |
| 5827 | try { |
| 5828 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 5829 | TelephonyManager.class); |
| 5830 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 5831 | if (subscriberId == null) { |
| 5832 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 5833 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 5834 | + subId); |
| 5835 | } |
| 5836 | return null; |
| 5837 | } |
| 5838 | |
| 5839 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 5840 | .getSubscriptionInfo(subId); |
| 5841 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 5842 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 5843 | if (groupUuid == null) { |
| 5844 | return new String[]{subscriberId}; |
| 5845 | } |
| 5846 | |
| 5847 | // Get all subscriberIds from the group. |
| 5848 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 5849 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5850 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 5851 | mApp.getFeatureId()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 5852 | for (SubscriptionInfo subInfo : groupInfos) { |
| 5853 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 5854 | if (subscriberId != null) { |
| 5855 | mergedSubscriberIds.add(subscriberId); |
| 5856 | } |
| 5857 | } |
| 5858 | |
| 5859 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 5860 | } finally { |
| 5861 | Binder.restoreCallingIdentity(identity); |
| 5862 | |
| 5863 | } |
| 5864 | } |
| 5865 | |
| 5866 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5867 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5868 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5869 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5870 | |
| 5871 | final long identity = Binder.clearCallingIdentity(); |
| 5872 | try { |
| 5873 | final Phone phone = getPhone(subId); |
| 5874 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 5875 | } finally { |
| 5876 | Binder.restoreCallingIdentity(identity); |
| 5877 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 5878 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 5879 | |
| 5880 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5881 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5882 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 5883 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5884 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 5885 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5886 | |
| 5887 | final long identity = Binder.clearCallingIdentity(); |
| 5888 | try { |
| 5889 | final Phone phone = getPhone(subId); |
| 5890 | if (phone == null) { |
| 5891 | return false; |
| 5892 | } |
| 5893 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 5894 | cdmaNonRoamingList); |
| 5895 | } finally { |
| 5896 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5897 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 5898 | } |
| 5899 | |
| 5900 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5901 | @Deprecated |
| 5902 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 5903 | enforceModifyPermission(); |
| 5904 | |
| 5905 | int returnValue = 0; |
| 5906 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5907 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 5908 | if(result.exception == null) { |
| 5909 | if (result.result != null) { |
| 5910 | byte[] responseData = (byte[])(result.result); |
| 5911 | if(responseData.length > oemResp.length) { |
| 5912 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 5913 | responseData.length + "bytes. Buffer Size is " + |
| 5914 | oemResp.length + "bytes."); |
| 5915 | } |
| 5916 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 5917 | returnValue = responseData.length; |
| 5918 | } |
| 5919 | } else { |
| 5920 | CommandException ex = (CommandException) result.exception; |
| 5921 | returnValue = ex.getCommandError().ordinal(); |
| 5922 | if(returnValue > 0) returnValue *= -1; |
| 5923 | } |
| 5924 | } catch (RuntimeException e) { |
| 5925 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 5926 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 5927 | if(returnValue > 0) returnValue *= -1; |
| 5928 | } |
| 5929 | |
| 5930 | return returnValue; |
| 5931 | } |
| 5932 | |
| 5933 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5934 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 5935 | try { |
| 5936 | ProxyController.getInstance().setRadioCapability(rafs); |
| 5937 | } catch (RuntimeException e) { |
| 5938 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 5939 | } |
| 5940 | } |
| 5941 | |
| 5942 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 5943 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5944 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5945 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5946 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5947 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 5948 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5949 | final long identity = Binder.clearCallingIdentity(); |
| 5950 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5951 | TelephonyPermissions |
| 5952 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5953 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 5954 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5955 | } finally { |
| 5956 | Binder.restoreCallingIdentity(identity); |
| 5957 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 5958 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 5959 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5960 | |
| 5961 | @Override |
| 5962 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5963 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5964 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5965 | |
| 5966 | final long identity = Binder.clearCallingIdentity(); |
| 5967 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5968 | ImsManager.getInstance(defaultPhone.getContext(), |
| 5969 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5970 | } finally { |
| 5971 | Binder.restoreCallingIdentity(identity); |
| 5972 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5973 | } |
| 5974 | |
| 5975 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5976 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5977 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5978 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5979 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 5980 | return false; |
| 5981 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5982 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5983 | final long identity = Binder.clearCallingIdentity(); |
| 5984 | try { |
| 5985 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 5986 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 5987 | // In the long run, we may instead need to check if there exists a connection service |
| 5988 | // which can support video calling. |
| 5989 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5990 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5991 | return imsManager.isVtEnabledByPlatform() |
| 5992 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 5993 | && imsManager.isVtEnabledByUser(); |
| 5994 | } finally { |
| 5995 | Binder.restoreCallingIdentity(identity); |
| 5996 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 5997 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 5998 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 5999 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6000 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 6001 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6002 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6003 | mApp, subId, callingPackage, callingFeatureId, |
| 6004 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6005 | return false; |
| 6006 | } |
| 6007 | |
| 6008 | final long identity = Binder.clearCallingIdentity(); |
| 6009 | try { |
| 6010 | CarrierConfigManager configManager = |
| 6011 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6012 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6013 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 6014 | } finally { |
| 6015 | Binder.restoreCallingIdentity(identity); |
| 6016 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6017 | } |
| 6018 | |
| 6019 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6020 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6021 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6022 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6023 | return false; |
| 6024 | } |
| 6025 | |
| 6026 | final long identity = Binder.clearCallingIdentity(); |
| 6027 | try { |
| 6028 | CarrierConfigManager configManager = |
| 6029 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6030 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6031 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 6032 | } finally { |
| 6033 | Binder.restoreCallingIdentity(identity); |
| 6034 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6035 | } |
| 6036 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6037 | @Override |
| 6038 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6039 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 6040 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6041 | } |
| 6042 | |
| 6043 | @Override |
| 6044 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6045 | final long identity = Binder.clearCallingIdentity(); |
| 6046 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6047 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6048 | } finally { |
| 6049 | Binder.restoreCallingIdentity(identity); |
| 6050 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6051 | } |
| 6052 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6053 | /** |
| 6054 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 6055 | * support for the feature and device firmware support. |
| 6056 | * |
| 6057 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 6058 | */ |
| 6059 | @Override |
| 6060 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6061 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6062 | final Phone phone = getPhone(subscriptionId); |
| 6063 | if (phone == null) { |
| 6064 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 6065 | return false; |
| 6066 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6067 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6068 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6069 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 6070 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6071 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6072 | return isCarrierSupported && isDeviceSupported; |
| 6073 | } finally { |
| 6074 | Binder.restoreCallingIdentity(identity); |
| 6075 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 6076 | } |
| 6077 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6078 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 6079 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 6080 | * RTT setting, will return true if the device and carrier both support RTT. |
| 6081 | * 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] | 6082 | */ |
| 6083 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6084 | final long identity = Binder.clearCallingIdentity(); |
| 6085 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 6086 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 6087 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 6088 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 6089 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 6090 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 6091 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6092 | } finally { |
| 6093 | Binder.restoreCallingIdentity(identity); |
| 6094 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 6095 | } |
| 6096 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6097 | @Deprecated |
| 6098 | @Override |
| 6099 | public String getDeviceId(String callingPackage) { |
| 6100 | return getDeviceIdWithFeature(callingPackage, null); |
| 6101 | } |
| 6102 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6103 | /** |
| 6104 | * Returns the unique device ID of phone, for example, the IMEI for |
| 6105 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 6106 | * |
| 6107 | * <p>Requires Permission: |
| 6108 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 6109 | */ |
| 6110 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6111 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6112 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6113 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6114 | return null; |
| 6115 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6116 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 6117 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6118 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6119 | return null; |
| 6120 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6121 | |
| 6122 | final long identity = Binder.clearCallingIdentity(); |
| 6123 | try { |
| 6124 | return phone.getDeviceId(); |
| 6125 | } finally { |
| 6126 | Binder.restoreCallingIdentity(identity); |
| 6127 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6128 | } |
| 6129 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6130 | /** |
| 6131 | * {@hide} |
| 6132 | * Returns the IMS Registration Status on a particular subid |
| 6133 | * |
| 6134 | * @param subId |
| 6135 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6136 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6137 | Phone phone = getPhone(subId); |
| 6138 | if (phone != null) { |
| 6139 | return phone.isImsRegistered(); |
| 6140 | } else { |
| 6141 | return false; |
| 6142 | } |
| 6143 | } |
| 6144 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6145 | @Override |
| 6146 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6147 | final long identity = Binder.clearCallingIdentity(); |
| 6148 | try { |
| 6149 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 6150 | } finally { |
| 6151 | Binder.restoreCallingIdentity(identity); |
| 6152 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6153 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 6154 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6155 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6156 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6157 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6158 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6159 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6160 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6161 | } |
| 6162 | final long identity = Binder.clearCallingIdentity(); |
| 6163 | try { |
| 6164 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 6165 | } finally { |
| 6166 | Binder.restoreCallingIdentity(identity); |
| 6167 | } |
| 6168 | } |
| 6169 | |
| 6170 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6171 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 6172 | final long identity = Binder.clearCallingIdentity(); |
| 6173 | try { |
| 6174 | Phone phone = getPhone(subscriptionId); |
| 6175 | if (phone == null) { |
| 6176 | return null; |
| 6177 | } |
| 6178 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 6179 | } finally { |
| 6180 | Binder.restoreCallingIdentity(identity); |
| 6181 | } |
| 6182 | } |
| 6183 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6184 | /** |
| 6185 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6186 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6187 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6188 | final long identity = Binder.clearCallingIdentity(); |
| 6189 | try { |
| 6190 | Phone phone = getPhone(subId); |
| 6191 | if (phone != null) { |
| 6192 | return phone.isWifiCallingEnabled(); |
| 6193 | } else { |
| 6194 | return false; |
| 6195 | } |
| 6196 | } finally { |
| 6197 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6198 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6199 | } |
| 6200 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6201 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6202 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6203 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6204 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6205 | final long identity = Binder.clearCallingIdentity(); |
| 6206 | try { |
| 6207 | Phone phone = getPhone(subId); |
| 6208 | if (phone != null) { |
| 6209 | return phone.isVideoEnabled(); |
| 6210 | } else { |
| 6211 | return false; |
| 6212 | } |
| 6213 | } finally { |
| 6214 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6215 | } |
| 6216 | } |
| 6217 | |
| 6218 | /** |
| 6219 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 6220 | * defined in {@link ImsRegistrationImplBase}. |
| 6221 | */ |
| 6222 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6223 | final long identity = Binder.clearCallingIdentity(); |
| 6224 | try { |
| 6225 | Phone phone = getPhone(subId); |
| 6226 | if (phone != null) { |
| 6227 | return phone.getImsRegistrationTech(); |
| 6228 | } else { |
| 6229 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 6230 | } |
| 6231 | } finally { |
| 6232 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6233 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6234 | } |
| 6235 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6236 | @Override |
| 6237 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 6238 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6239 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 6240 | return; |
| 6241 | } |
| 6242 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6243 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6244 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6245 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6246 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 6247 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6248 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6249 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6250 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6251 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 6252 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6253 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6254 | // There has been issues when Sms raw table somehow stores orphan |
| 6255 | // fragments. They lead to garbled message when new fragments come |
| 6256 | // in and combined with those stale ones. In case this happens again, |
| 6257 | // user can reset all network settings which will clean up this table. |
| 6258 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6259 | // Clean up IMS settings as well here. |
| 6260 | int slotId = getSlotIndex(subId); |
| 6261 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6262 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 6263 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 6264 | |
| 6265 | // Erase modem config if erase modem on network setting is enabled. |
| 6266 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 6267 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 6268 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 6269 | sendEraseModemConfig(getDefaultPhone()); |
| 6270 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6271 | } finally { |
| 6272 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6273 | } |
| 6274 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6275 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6276 | private void cleanUpSmsRawTable(Context context) { |
| 6277 | ContentResolver resolver = context.getContentResolver(); |
| 6278 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 6279 | resolver.delete(uri, null, null); |
| 6280 | } |
| 6281 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6282 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6283 | public String getSimLocaleForSubscriber(int subId) { |
| 6284 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 6285 | final Phone phone = getPhone(subId); |
| 6286 | if (phone == null) { |
| 6287 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 6288 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6289 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6290 | final long identity = Binder.clearCallingIdentity(); |
| 6291 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6292 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6293 | phone.getContext().getOpPackageName(), phone.getContext().getFeatureId()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 6294 | if (info == null) { |
| 6295 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 6296 | return null; |
| 6297 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6298 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 6299 | // preferences (EF-PL and EF-LI)... |
| 6300 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6301 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6302 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 6303 | if (localeFromDefaultSim != null) { |
| 6304 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 6305 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 6306 | + localeFromDefaultSim); |
| 6307 | return localeFromDefaultSim.toLanguageTag(); |
| 6308 | } else { |
| 6309 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6310 | } |
| 6311 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6312 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6313 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 6314 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 6315 | // the SIM and carrier preferences does not include a country we add the country |
| 6316 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 6317 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6318 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6319 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6320 | return mccLocale.toLanguageTag(); |
| 6321 | } |
| 6322 | |
| 6323 | if (DBG) log("No locale found - returning null"); |
| 6324 | return null; |
| 6325 | } finally { |
| 6326 | Binder.restoreCallingIdentity(identity); |
| 6327 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6328 | } |
| 6329 | |
| 6330 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6331 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
| 6332 | mApp.getFeatureId()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6333 | } |
| 6334 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6335 | /** |
| 6336 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 6337 | */ |
| 6338 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6339 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
| 6340 | mApp.getFeatureId()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6341 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6342 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6343 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6344 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6345 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6346 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6347 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 6348 | * representing the state of the modem. |
| 6349 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6350 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 6351 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6352 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6353 | */ |
| 6354 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6355 | public void requestModemActivityInfo(ResultReceiver result) { |
| 6356 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6357 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6358 | |
| 6359 | final long identity = Binder.clearCallingIdentity(); |
| 6360 | try { |
| 6361 | ModemActivityInfo ret = null; |
| 6362 | synchronized (mLastModemActivityInfo) { |
| 6363 | ModemActivityInfo info = (ModemActivityInfo) sendRequest( |
| 6364 | CMD_GET_MODEM_ACTIVITY_INFO, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6365 | null, workSource); |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6366 | if (isModemActivityInfoValid(info)) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6367 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6368 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6369 | int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6370 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6371 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6372 | } |
| 6373 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6374 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 6375 | + mLastModemActivityInfo.getSleepTimeMillis()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6376 | mLastModemActivityInfo.setIdleTimeMillis( |
| 6377 | info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis()); |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6378 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 6379 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 6380 | info.getReceiveTimeMillis() + mLastModemActivityInfo |
| 6381 | .getReceiveTimeMillis()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6382 | } |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6383 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6384 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 6385 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 6386 | mLastModemActivityInfo.getIdleTimeMillis(), |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6387 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 6388 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6389 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6390 | Bundle bundle = new Bundle(); |
| 6391 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 6392 | result.send(0, bundle); |
| 6393 | } finally { |
| 6394 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6395 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6396 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6397 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6398 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 6399 | // less than total activity duration. |
| 6400 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 6401 | if (info == null) { |
| 6402 | return false; |
| 6403 | } |
| 6404 | int activityDurationMs = |
| 6405 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 6406 | int totalTxTimeMs = 0; |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6407 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6408 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 6409 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6410 | } |
| 6411 | return (info.isValid() |
| 6412 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 6413 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6414 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6415 | && (totalTxTimeMs <= activityDurationMs)); |
| 6416 | } |
| 6417 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6418 | /** |
| 6419 | * {@hide} |
| 6420 | * Returns the service state information on specified subscription. |
| 6421 | */ |
| 6422 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6423 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 6424 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6425 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6426 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6427 | return null; |
| 6428 | } |
| 6429 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6430 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 6431 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6432 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6433 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6434 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6435 | .setCallingPid(Binder.getCallingPid()) |
| 6436 | .setCallingUid(Binder.getCallingUid()) |
| 6437 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6438 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6439 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6440 | .build()); |
| 6441 | |
| 6442 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 6443 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6444 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6445 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 6446 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6447 | .setCallingPid(Binder.getCallingPid()) |
| 6448 | .setCallingUid(Binder.getCallingUid()) |
| 6449 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6450 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6451 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6452 | .build()); |
| 6453 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 6454 | boolean hasFinePermission = |
| 6455 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6456 | boolean hasCoarsePermission = |
| 6457 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6458 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6459 | final long identity = Binder.clearCallingIdentity(); |
| 6460 | try { |
| 6461 | final Phone phone = getPhone(subId); |
| 6462 | if (phone == null) { |
| 6463 | return null; |
| 6464 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6465 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6466 | ServiceState ss = phone.getServiceState(); |
| 6467 | |
| 6468 | // Scrub out the location info in ServiceState depending on what level of access |
| 6469 | // the caller has. |
| 6470 | if (hasFinePermission) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 6471 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 6472 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6473 | } finally { |
| 6474 | Binder.restoreCallingIdentity(identity); |
| 6475 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6476 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6477 | |
| 6478 | /** |
| 6479 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 6480 | * |
| 6481 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6482 | * voicemail ringtone. |
| 6483 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 6484 | * PhoneAccount. |
| 6485 | */ |
| 6486 | @Override |
| 6487 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6488 | final long identity = Binder.clearCallingIdentity(); |
| 6489 | try { |
| 6490 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6491 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6492 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6493 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6494 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6495 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 6496 | } finally { |
| 6497 | Binder.restoreCallingIdentity(identity); |
| 6498 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6499 | } |
| 6500 | |
| 6501 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6502 | * Sets the per-account voicemail ringtone. |
| 6503 | * |
| 6504 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6505 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6506 | * |
| 6507 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6508 | * voicemail ringtone. |
| 6509 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 6510 | * PhoneAccount. |
| 6511 | */ |
| 6512 | @Override |
| 6513 | public void setVoicemailRingtoneUri(String callingPackage, |
| 6514 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6515 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6516 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6517 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6518 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6519 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6520 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6521 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6522 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6523 | |
| 6524 | final long identity = Binder.clearCallingIdentity(); |
| 6525 | try { |
| 6526 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6527 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6528 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6529 | } |
| 6530 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 6531 | } finally { |
| 6532 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6533 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6534 | } |
| 6535 | |
| 6536 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6537 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 6538 | * |
| 6539 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6540 | * voicemail vibration setting. |
| 6541 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 6542 | */ |
| 6543 | @Override |
| 6544 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6545 | final long identity = Binder.clearCallingIdentity(); |
| 6546 | try { |
| 6547 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6548 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6549 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6550 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6551 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6552 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 6553 | } finally { |
| 6554 | Binder.restoreCallingIdentity(identity); |
| 6555 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6556 | } |
| 6557 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6558 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6559 | * Sets the per-account voicemail vibration. |
| 6560 | * |
| 6561 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6562 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6563 | * |
| 6564 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6565 | * voicemail vibration setting. |
| 6566 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 6567 | * specific PhoneAccount. |
| 6568 | */ |
| 6569 | @Override |
| 6570 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 6571 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6572 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6573 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6574 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6575 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6576 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6577 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6578 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6579 | } |
| 6580 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6581 | final long identity = Binder.clearCallingIdentity(); |
| 6582 | try { |
| 6583 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6584 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6585 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6586 | } |
| 6587 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 6588 | } finally { |
| 6589 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6590 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6591 | } |
| 6592 | |
| 6593 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6594 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 6595 | * |
| 6596 | * @throws SecurityException if the caller does not have the required permission |
| 6597 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6598 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6599 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6600 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6601 | } |
| 6602 | |
| 6603 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6604 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 6605 | * permission. |
| 6606 | * |
| 6607 | * @throws SecurityException if the caller does not have the required permission |
| 6608 | */ |
| 6609 | private void enforceSendSmsPermission() { |
| 6610 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 6611 | } |
| 6612 | |
| 6613 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6614 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6615 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6616 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6617 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6618 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6619 | final long identity = Binder.clearCallingIdentity(); |
| 6620 | try { |
| 6621 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6622 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6623 | if (componentName == null) { |
| 6624 | throw new SecurityException( |
| 6625 | "Caller not current active visual voicemail package[null]"); |
| 6626 | } |
| 6627 | String vvmPackage = componentName.getPackageName(); |
| 6628 | if (!callingPackage.equals(vvmPackage)) { |
| 6629 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 6630 | + vvmPackage + "]"); |
| 6631 | } |
| 6632 | } finally { |
| 6633 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6634 | } |
| 6635 | } |
| 6636 | |
| 6637 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6638 | * Return the application ID for the app type. |
| 6639 | * |
| 6640 | * @param subId the subscription ID that this request applies to. |
| 6641 | * @param appType the uicc app type. |
| 6642 | * @return Application ID for specificied app type, or null if no uicc. |
| 6643 | */ |
| 6644 | @Override |
| 6645 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6646 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6647 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6648 | |
| 6649 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6650 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6651 | if (phone == null) { |
| 6652 | return null; |
| 6653 | } |
| 6654 | String aid = null; |
| 6655 | try { |
| 6656 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 6657 | .getApplicationByType(appType).getAid(); |
| 6658 | } catch (Exception e) { |
| 6659 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 6660 | } |
| 6661 | return aid; |
| 6662 | } finally { |
| 6663 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6664 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6665 | } |
| 6666 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6667 | /** |
| 6668 | * Return the Electronic Serial Number. |
| 6669 | * |
| 6670 | * @param subId the subscription ID that this request applies to. |
| 6671 | * @return ESN or null if error. |
| 6672 | */ |
| 6673 | @Override |
| 6674 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6675 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6676 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6677 | |
| 6678 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6679 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6680 | if (phone == null) { |
| 6681 | return null; |
| 6682 | } |
| 6683 | String esn = null; |
| 6684 | try { |
| 6685 | esn = phone.getEsn(); |
| 6686 | } catch (Exception e) { |
| 6687 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 6688 | } |
| 6689 | return esn; |
| 6690 | } finally { |
| 6691 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6692 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6693 | } |
| 6694 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6695 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6696 | * Return the Preferred Roaming List Version. |
| 6697 | * |
| 6698 | * @param subId the subscription ID that this request applies to. |
| 6699 | * @return PRLVersion or null if error. |
| 6700 | */ |
| 6701 | @Override |
| 6702 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6703 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6704 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6705 | |
| 6706 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6707 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6708 | if (phone == null) { |
| 6709 | return null; |
| 6710 | } |
| 6711 | String cdmaPrlVersion = null; |
| 6712 | try { |
| 6713 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 6714 | } catch (Exception e) { |
| 6715 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 6716 | } |
| 6717 | return cdmaPrlVersion; |
| 6718 | } finally { |
| 6719 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6720 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6721 | } |
| 6722 | |
| 6723 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6724 | * Get snapshot of Telephony histograms |
| 6725 | * @return List of Telephony histograms |
| 6726 | * @hide |
| 6727 | */ |
| 6728 | @Override |
| 6729 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6730 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6731 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6732 | |
| 6733 | final long identity = Binder.clearCallingIdentity(); |
| 6734 | try { |
| 6735 | return RIL.getTelephonyRILTimingHistograms(); |
| 6736 | } finally { |
| 6737 | Binder.restoreCallingIdentity(identity); |
| 6738 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6739 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6740 | |
| 6741 | /** |
| 6742 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6743 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 6744 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6745 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6746 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6747 | * @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] | 6748 | */ |
| 6749 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6750 | @TelephonyManager.SetCarrierRestrictionResult |
| 6751 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6752 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6753 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6754 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6755 | if (carrierRestrictionRules == null) { |
| 6756 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 6757 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6758 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6759 | final long identity = Binder.clearCallingIdentity(); |
| 6760 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6761 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6762 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6763 | } finally { |
| 6764 | Binder.restoreCallingIdentity(identity); |
| 6765 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6766 | } |
| 6767 | |
| 6768 | /** |
| 6769 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6770 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 6771 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6772 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6773 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6774 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6775 | */ |
| 6776 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6777 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6778 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6779 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6780 | |
| 6781 | final long identity = Binder.clearCallingIdentity(); |
| 6782 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6783 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 6784 | if (response instanceof CarrierRestrictionRules) { |
| 6785 | return (CarrierRestrictionRules) response; |
| 6786 | } |
| 6787 | // Response is an Exception of some kind, |
| 6788 | // which is signalled to the user as a NULL retval |
| 6789 | return null; |
| 6790 | } catch (Exception e) { |
| 6791 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 6792 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6793 | } finally { |
| 6794 | Binder.restoreCallingIdentity(identity); |
| 6795 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6796 | } |
| 6797 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6798 | /** |
| 6799 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 6800 | * @param subId the subscription ID that this action applies to. |
| 6801 | * @param enabled control enable or disable metered apns. |
| 6802 | * {@hide} |
| 6803 | */ |
| 6804 | @Override |
| 6805 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 6806 | enforceModifyPermission(); |
| 6807 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6808 | |
| 6809 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6810 | if (phone == null) { |
| 6811 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 6812 | return; |
| 6813 | } |
| 6814 | try { |
| 6815 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 6816 | } catch (Exception e) { |
| 6817 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6818 | } finally { |
| 6819 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6820 | } |
| 6821 | } |
| 6822 | |
| 6823 | /** |
| 6824 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 6825 | * @param subId the subscription ID that this action applies to. |
| 6826 | * @param enabled control enable or disable radio. |
| 6827 | * {@hide} |
| 6828 | */ |
| 6829 | @Override |
| 6830 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 6831 | enforceModifyPermission(); |
| 6832 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6833 | |
| 6834 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6835 | if (phone == null) { |
| 6836 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 6837 | return; |
| 6838 | } |
| 6839 | try { |
| 6840 | phone.carrierActionSetRadioEnabled(enabled); |
| 6841 | } catch (Exception e) { |
| 6842 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6843 | } finally { |
| 6844 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 6845 | } |
| 6846 | } |
| 6847 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6848 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6849 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 6850 | * network status based on which carrier apps could apply actions accordingly, |
| 6851 | * enable/disable default url handler for example. |
| 6852 | * |
| 6853 | * @param subId the subscription ID that this action applies to. |
| 6854 | * @param report control start/stop reporting the default network status. |
| 6855 | * {@hide} |
| 6856 | */ |
| 6857 | @Override |
| 6858 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 6859 | enforceModifyPermission(); |
| 6860 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6861 | |
| 6862 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6863 | if (phone == null) { |
| 6864 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 6865 | return; |
| 6866 | } |
| 6867 | try { |
| 6868 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 6869 | } catch (Exception e) { |
| 6870 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6871 | } finally { |
| 6872 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 6873 | } |
| 6874 | } |
| 6875 | |
| 6876 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 6877 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 6878 | * @param subId the subscription ID that this action applies to. |
| 6879 | * {@hide} |
| 6880 | */ |
| 6881 | @Override |
| 6882 | public void carrierActionResetAll(int subId) { |
| 6883 | enforceModifyPermission(); |
| 6884 | final Phone phone = getPhone(subId); |
| 6885 | if (phone == null) { |
| 6886 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 6887 | return; |
| 6888 | } |
| 6889 | try { |
| 6890 | phone.carrierActionResetAll(); |
| 6891 | } catch (Exception e) { |
| 6892 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 6893 | } |
| 6894 | } |
| 6895 | |
| 6896 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6897 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 6898 | * bug report is being generated. |
| 6899 | */ |
| 6900 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 6901 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6902 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 6903 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 6904 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 6905 | + Binder.getCallingPid() |
| 6906 | + ", uid=" + Binder.getCallingUid() |
| 6907 | + "without permission " |
| 6908 | + android.Manifest.permission.DUMP); |
| 6909 | return; |
| 6910 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6911 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 6912 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6913 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6914 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 6915 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 6916 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 6917 | @NonNull String[] args) { |
| 6918 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 6919 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 6920 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 6921 | } |
| 6922 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6923 | /** |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6924 | * Get aggregated video call data usage since boot. |
| 6925 | * |
| 6926 | * @param perUidStats True if requesting data usage per uid, otherwise overall usage. |
| 6927 | * @return Snapshot of video call data usage |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6928 | * {@hide} |
| 6929 | */ |
| 6930 | @Override |
Jack Yu | 84291ec | 2017-05-26 16:07:50 -0700 | [diff] [blame] | 6931 | public NetworkStats getVtDataUsage(int subId, boolean perUidStats) { |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6932 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY, |
| 6933 | null); |
| 6934 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6935 | final long identity = Binder.clearCallingIdentity(); |
| 6936 | try { |
| 6937 | // NetworkStatsService keeps tracking the active network interface and identity. It |
| 6938 | // records the delta with the corresponding network identity. |
| 6939 | // We just return the total video call data usage snapshot since boot. |
| 6940 | Phone phone = getPhone(subId); |
| 6941 | if (phone != null) { |
| 6942 | return phone.getVtDataUsage(perUidStats); |
| 6943 | } |
| 6944 | return null; |
| 6945 | } finally { |
| 6946 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6947 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 6948 | } |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6949 | |
| 6950 | /** |
| 6951 | * Policy control of data connection. Usually used when data limit is passed. |
| 6952 | * @param enabled True if enabling the data, otherwise disabling. |
| 6953 | * @param subId Subscription index |
| 6954 | * {@hide} |
| 6955 | */ |
| 6956 | @Override |
| 6957 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 6958 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6959 | |
| 6960 | final long identity = Binder.clearCallingIdentity(); |
| 6961 | try { |
| 6962 | Phone phone = getPhone(subId); |
| 6963 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6964 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6965 | } |
| 6966 | } finally { |
| 6967 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 6968 | } |
| 6969 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6970 | |
| 6971 | /** |
| 6972 | * Get Client request stats |
| 6973 | * @return List of Client Request Stats |
| 6974 | * @hide |
| 6975 | */ |
| 6976 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6977 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 6978 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6979 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6980 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6981 | return null; |
| 6982 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6983 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6984 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6985 | final long identity = Binder.clearCallingIdentity(); |
| 6986 | try { |
| 6987 | if (phone != null) { |
| 6988 | return phone.getClientRequestStats(); |
| 6989 | } |
| 6990 | |
| 6991 | return null; |
| 6992 | } finally { |
| 6993 | Binder.restoreCallingIdentity(identity); |
| 6994 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 6995 | } |
| 6996 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6997 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6998 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 6999 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7000 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7001 | |
| 7002 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7003 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7004 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7005 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7006 | * @param state State of SIM (power down, power up, pass through) |
| 7007 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7008 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7009 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7010 | * |
| 7011 | **/ |
| 7012 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7013 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7014 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7015 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7016 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7017 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7018 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7019 | final long identity = Binder.clearCallingIdentity(); |
| 7020 | try { |
| 7021 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7022 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7023 | } |
| 7024 | } finally { |
| 7025 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7026 | } |
| 7027 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7028 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7029 | private boolean isUssdApiAllowed(int subId) { |
| 7030 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7031 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7032 | if (configManager == null) { |
| 7033 | return false; |
| 7034 | } |
| 7035 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 7036 | if (pb == null) { |
| 7037 | return false; |
| 7038 | } |
| 7039 | return pb.getBoolean( |
| 7040 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 7041 | } |
| 7042 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7043 | /** |
| 7044 | * Check if phone is in emergency callback mode |
| 7045 | * @return true if phone is in emergency callback mode |
| 7046 | * @param subId sub id |
| 7047 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 7048 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7049 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7050 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7051 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7052 | |
| 7053 | final long identity = Binder.clearCallingIdentity(); |
| 7054 | try { |
| 7055 | if (phone != null) { |
| 7056 | return phone.isInEcm(); |
| 7057 | } else { |
| 7058 | return false; |
| 7059 | } |
| 7060 | } finally { |
| 7061 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7062 | } |
| 7063 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7064 | |
| 7065 | /** |
| 7066 | * Get the current signal strength information for the given subscription. |
| 7067 | * Because this information is not updated when the device is in a low power state |
| 7068 | * it should not be relied-upon to be current. |
| 7069 | * @param subId Subscription index |
| 7070 | * @return the most recent cached signal strength info from the modem |
| 7071 | */ |
| 7072 | @Override |
| 7073 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7074 | final long identity = Binder.clearCallingIdentity(); |
| 7075 | try { |
| 7076 | Phone p = getPhone(subId); |
| 7077 | if (p == null) { |
| 7078 | return null; |
| 7079 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7080 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7081 | return p.getSignalStrength(); |
| 7082 | } finally { |
| 7083 | Binder.restoreCallingIdentity(identity); |
| 7084 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7085 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7086 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7087 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7088 | * Get the current modem radio state for the given slot. |
| 7089 | * @param slotIndex slot index. |
| 7090 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7091 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7092 | * @return the current radio power state from the modem |
| 7093 | */ |
| 7094 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7095 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7096 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7097 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7098 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 7099 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7100 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7101 | } |
| 7102 | |
| 7103 | final long identity = Binder.clearCallingIdentity(); |
| 7104 | try { |
| 7105 | return phone.getRadioPowerState(); |
| 7106 | } finally { |
| 7107 | Binder.restoreCallingIdentity(identity); |
| 7108 | } |
| 7109 | } |
| 7110 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7111 | } |
| 7112 | |
| 7113 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7114 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 7115 | * |
| 7116 | * <p>Requires one of the following permissions: |
| 7117 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 7118 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 7119 | * privileges. |
| 7120 | * |
| 7121 | * @param subId subscription id |
| 7122 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 7123 | * {@code false}. |
| 7124 | */ |
| 7125 | @Override |
| 7126 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7127 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7128 | null /* message */); |
| 7129 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7130 | boolean isEnabled = false; |
| 7131 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7132 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7133 | Phone phone = getPhone(subId); |
| 7134 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7135 | } catch (Exception e) { |
| 7136 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 7137 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7138 | } finally { |
| 7139 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7140 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7141 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7142 | } |
| 7143 | |
| 7144 | |
| 7145 | /** |
| 7146 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 7147 | * |
| 7148 | * <p> Requires permission: |
| 7149 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 7150 | * privileges. |
| 7151 | * |
| 7152 | * @param subId subscription id |
| 7153 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 7154 | */ |
| 7155 | @Override |
| 7156 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7157 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7158 | mApp, subId, "setDataRoamingEnabled"); |
| 7159 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7160 | final long identity = Binder.clearCallingIdentity(); |
| 7161 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7162 | Phone phone = getPhone(subId); |
| 7163 | if (phone != null) { |
| 7164 | phone.setDataRoamingEnabled(isEnabled); |
| 7165 | } |
| 7166 | } finally { |
| 7167 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7168 | } |
| 7169 | } |
| 7170 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7171 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7172 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 7173 | TelephonyPermissions |
| 7174 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7175 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 7176 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7177 | boolean isAllowed = true; |
| 7178 | final long identity = Binder.clearCallingIdentity(); |
| 7179 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7180 | Phone phone = getPhone(subId); |
| 7181 | if (phone != null) { |
| 7182 | isAllowed = phone.isCspPlmnEnabled(); |
| 7183 | } |
| 7184 | } finally { |
| 7185 | Binder.restoreCallingIdentity(identity); |
| 7186 | } |
| 7187 | return isAllowed; |
| 7188 | } |
| 7189 | |
| 7190 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7191 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7192 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7193 | try { |
| 7194 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7195 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7196 | } catch (SecurityException e) { |
| 7197 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 7198 | // has carrier privileges on an active UICC |
| 7199 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 7200 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7201 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7202 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7203 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7204 | |
| 7205 | final long identity = Binder.clearCallingIdentity(); |
| 7206 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7207 | UiccController uiccController = UiccController.getInstance(); |
| 7208 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7209 | if (hasReadPermission) { |
| 7210 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7211 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7212 | |
| 7213 | // Remove private info if the caller doesn't have access |
| 7214 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 7215 | for (UiccCardInfo cardInfo : cardInfos) { |
| 7216 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 7217 | // is available |
| 7218 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 7219 | if (card == null || card.getUiccProfile() == null) { |
| 7220 | // assume no access if the card or profile is unavailable |
| 7221 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7222 | continue; |
| 7223 | } |
| 7224 | UiccProfile profile = card.getUiccProfile(); |
| 7225 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 7226 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7227 | filteredInfos.add(cardInfo); |
| 7228 | } else { |
| 7229 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7230 | } |
| 7231 | } |
| 7232 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7233 | } finally { |
| 7234 | Binder.restoreCallingIdentity(identity); |
| 7235 | } |
| 7236 | } |
| 7237 | |
| 7238 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7239 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7240 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7241 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7242 | final long identity = Binder.clearCallingIdentity(); |
| 7243 | try { |
| 7244 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 7245 | if (slots == null) { |
| 7246 | Rlog.i(LOG_TAG, "slots is null."); |
| 7247 | return null; |
| 7248 | } |
| 7249 | |
| 7250 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 7251 | for (int i = 0; i < slots.length; i++) { |
| 7252 | UiccSlot slot = slots[i]; |
| 7253 | if (slot == null) { |
| 7254 | continue; |
| 7255 | } |
| 7256 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7257 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7258 | UiccCard card = slot.getUiccCard(); |
| 7259 | if (card != null) { |
| 7260 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7261 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 7262 | cardId = slot.getEid(); |
| 7263 | if (TextUtils.isEmpty(cardId)) { |
| 7264 | cardId = slot.getIccId(); |
| 7265 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7266 | } |
| 7267 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 7268 | if (cardId != null) { |
| 7269 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 7270 | // if cardId is an EID, it's all digits so this is fine |
| 7271 | cardId = IccUtils.stripTrailingFs(cardId); |
| 7272 | } |
| 7273 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7274 | int cardState = 0; |
| 7275 | switch (slot.getCardState()) { |
| 7276 | case CARDSTATE_ABSENT: |
| 7277 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 7278 | break; |
| 7279 | case CARDSTATE_PRESENT: |
| 7280 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 7281 | break; |
| 7282 | case CARDSTATE_ERROR: |
| 7283 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 7284 | break; |
| 7285 | case CARDSTATE_RESTRICTED: |
| 7286 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 7287 | break; |
| 7288 | default: |
| 7289 | break; |
| 7290 | |
| 7291 | } |
| 7292 | |
| 7293 | infos[i] = new UiccSlotInfo( |
| 7294 | slot.isActive(), |
| 7295 | slot.isEuicc(), |
| 7296 | cardId, |
| 7297 | cardState, |
| 7298 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 7299 | slot.isExtendedApduSupported(), |
| 7300 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7301 | } |
| 7302 | return infos; |
| 7303 | } finally { |
| 7304 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 7305 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7306 | } |
| 7307 | |
| 7308 | @Override |
| 7309 | public boolean switchSlots(int[] physicalSlots) { |
| 7310 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7311 | |
| 7312 | final long identity = Binder.clearCallingIdentity(); |
| 7313 | try { |
| 7314 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 7315 | } finally { |
| 7316 | Binder.restoreCallingIdentity(identity); |
| 7317 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7318 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7319 | |
| 7320 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7321 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7322 | final long identity = Binder.clearCallingIdentity(); |
| 7323 | try { |
| 7324 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 7325 | } finally { |
| 7326 | Binder.restoreCallingIdentity(identity); |
| 7327 | } |
| 7328 | } |
| 7329 | |
| 7330 | @Override |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7331 | public void setRadioIndicationUpdateMode(int subId, int filters, int mode) { |
| 7332 | enforceModifyPermission(); |
| 7333 | final Phone phone = getPhone(subId); |
| 7334 | if (phone == null) { |
| 7335 | loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId); |
| 7336 | return; |
| 7337 | } |
| 7338 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7339 | final long identity = Binder.clearCallingIdentity(); |
| 7340 | try { |
| 7341 | phone.setRadioIndicationUpdateMode(filters, mode); |
| 7342 | } finally { |
| 7343 | Binder.restoreCallingIdentity(identity); |
| 7344 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7345 | } |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7346 | |
| 7347 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 7348 | * A test API to reload the UICC profile. |
| 7349 | * |
| 7350 | * <p>Requires that the calling app has permission |
| 7351 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7352 | * @hide |
| 7353 | */ |
| 7354 | @Override |
| 7355 | public void refreshUiccProfile(int subId) { |
| 7356 | enforceModifyPermission(); |
| 7357 | |
| 7358 | final long identity = Binder.clearCallingIdentity(); |
| 7359 | try { |
| 7360 | Phone phone = getPhone(subId); |
| 7361 | if (phone == null) { |
| 7362 | return; |
| 7363 | } |
| 7364 | UiccCard uiccCard = phone.getUiccCard(); |
| 7365 | if (uiccCard == null) { |
| 7366 | return; |
| 7367 | } |
| 7368 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7369 | if (uiccProfile == null) { |
| 7370 | return; |
| 7371 | } |
| 7372 | uiccProfile.refresh(); |
| 7373 | } finally { |
| 7374 | Binder.restoreCallingIdentity(identity); |
| 7375 | } |
| 7376 | } |
| 7377 | |
| 7378 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7379 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 7380 | */ |
| 7381 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7382 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7383 | } |
| 7384 | |
| 7385 | /** |
| 7386 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 7387 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 7388 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 7389 | */ |
| 7390 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 7391 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7392 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7393 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7394 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 7395 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 7396 | return isDataRoamingEnabled; |
| 7397 | } |
| 7398 | |
| 7399 | /** |
| 7400 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 7401 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 7402 | */ |
| 7403 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7404 | List<Integer> list = TelephonyProperties.default_network(); |
| 7405 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 7406 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 7407 | return list.get(phoneId); |
| 7408 | } |
| 7409 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7410 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7411 | |
| 7412 | @Override |
| 7413 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7414 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7415 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7416 | |
| 7417 | final long identity = Binder.clearCallingIdentity(); |
| 7418 | try { |
| 7419 | final Phone phone = getPhone(subId); |
| 7420 | if (phone == null) { |
| 7421 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 7422 | return; |
| 7423 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7424 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 7425 | carrierPrivilegeRules, apn); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7426 | } finally { |
| 7427 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7428 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7429 | } |
| 7430 | |
| 7431 | @Override |
| 7432 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7433 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7434 | |
| 7435 | final long identity = Binder.clearCallingIdentity(); |
| 7436 | try { |
| 7437 | final Phone phone = getPhone(subId); |
| 7438 | if (phone == null) { |
| 7439 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 7440 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 7441 | } |
| 7442 | return phone.getCarrierIdListVersion(); |
| 7443 | } finally { |
| 7444 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7445 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7446 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7447 | |
| 7448 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7449 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 7450 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7451 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7452 | mApp, subId, callingPackage, callingFeatureId, |
| 7453 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7454 | return -1; |
| 7455 | } |
| 7456 | |
| 7457 | final long identity = Binder.clearCallingIdentity(); |
| 7458 | try { |
| 7459 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 7460 | } finally { |
| 7461 | Binder.restoreCallingIdentity(identity); |
| 7462 | } |
| 7463 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7464 | |
| 7465 | @Override |
| 7466 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 7467 | TelephonyPermissions |
| 7468 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7469 | mApp, subId, "getCdmaRoamingMode"); |
| 7470 | |
| 7471 | final long identity = Binder.clearCallingIdentity(); |
| 7472 | try { |
| 7473 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 7474 | } finally { |
| 7475 | Binder.restoreCallingIdentity(identity); |
| 7476 | } |
| 7477 | } |
| 7478 | |
| 7479 | @Override |
| 7480 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 7481 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7482 | mApp, subId, "setCdmaRoamingMode"); |
| 7483 | |
| 7484 | final long identity = Binder.clearCallingIdentity(); |
| 7485 | try { |
| 7486 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 7487 | } finally { |
| 7488 | Binder.restoreCallingIdentity(identity); |
| 7489 | } |
| 7490 | } |
| 7491 | |
| 7492 | @Override |
| 7493 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 7494 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7495 | mApp, subId, "setCdmaSubscriptionMode"); |
| 7496 | |
| 7497 | final long identity = Binder.clearCallingIdentity(); |
| 7498 | try { |
| 7499 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 7500 | } finally { |
| 7501 | Binder.restoreCallingIdentity(identity); |
| 7502 | } |
| 7503 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 7504 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7505 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7506 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7507 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7508 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7509 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 7510 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7511 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7512 | } |
| 7513 | final long identity = Binder.clearCallingIdentity(); |
| 7514 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7515 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 7516 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7517 | if (phone.getEmergencyNumberTracker() != null |
| 7518 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 7519 | emergencyNumberListInternal.put( |
| 7520 | phone.getSubId(), |
| 7521 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 7522 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7523 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7524 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7525 | } finally { |
| 7526 | Binder.restoreCallingIdentity(identity); |
| 7527 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7528 | } |
| 7529 | |
| 7530 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7531 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7532 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7533 | if (!exactMatch) { |
| 7534 | TelephonyPermissions |
| 7535 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7536 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7537 | } |
| 7538 | final long identity = Binder.clearCallingIdentity(); |
| 7539 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7540 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7541 | if (phone.getEmergencyNumberTracker() != null |
| 7542 | && phone.getEmergencyNumberTracker() != null) { |
| 7543 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 7544 | number, exactMatch)) { |
| 7545 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7546 | } |
| 7547 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7548 | } |
| 7549 | return false; |
| 7550 | } finally { |
| 7551 | Binder.restoreCallingIdentity(identity); |
| 7552 | } |
| 7553 | } |
| 7554 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 7555 | /** |
| 7556 | * Update emergency number list for test mode. |
| 7557 | */ |
| 7558 | @Override |
| 7559 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 7560 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7561 | "updateEmergencyNumberListTestMode"); |
| 7562 | |
| 7563 | final long identity = Binder.clearCallingIdentity(); |
| 7564 | try { |
| 7565 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7566 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7567 | if (tracker != null) { |
| 7568 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 7569 | } |
| 7570 | } |
| 7571 | } finally { |
| 7572 | Binder.restoreCallingIdentity(identity); |
| 7573 | } |
| 7574 | } |
| 7575 | |
| 7576 | /** |
| 7577 | * Get the full emergency number list for test mode. |
| 7578 | */ |
| 7579 | @Override |
| 7580 | public List<String> getEmergencyNumberListTestMode() { |
| 7581 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7582 | "getEmergencyNumberListTestMode"); |
| 7583 | |
| 7584 | final long identity = Binder.clearCallingIdentity(); |
| 7585 | try { |
| 7586 | Set<String> emergencyNumbers = new HashSet<>(); |
| 7587 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7588 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7589 | if (tracker != null) { |
| 7590 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 7591 | emergencyNumbers.add(num.getNumber()); |
| 7592 | } |
| 7593 | } |
| 7594 | } |
| 7595 | return new ArrayList<>(emergencyNumbers); |
| 7596 | } finally { |
| 7597 | Binder.restoreCallingIdentity(identity); |
| 7598 | } |
| 7599 | } |
| 7600 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7601 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7602 | public int getEmergencyNumberDbVersion(int subId) { |
| 7603 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 7604 | |
| 7605 | final long identity = Binder.clearCallingIdentity(); |
| 7606 | try { |
| 7607 | final Phone phone = getPhone(subId); |
| 7608 | if (phone == null) { |
| 7609 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 7610 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 7611 | } |
| 7612 | return phone.getEmergencyNumberDbVersion(); |
| 7613 | } finally { |
| 7614 | Binder.restoreCallingIdentity(identity); |
| 7615 | } |
| 7616 | } |
| 7617 | |
| 7618 | @Override |
| 7619 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 7620 | enforceModifyPermission(); |
| 7621 | |
| 7622 | final long identity = Binder.clearCallingIdentity(); |
| 7623 | try { |
| 7624 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7625 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7626 | if (tracker != null) { |
| 7627 | tracker.updateOtaEmergencyNumberDatabase(); |
| 7628 | } |
| 7629 | } |
| 7630 | } finally { |
| 7631 | Binder.restoreCallingIdentity(identity); |
| 7632 | } |
| 7633 | } |
| 7634 | |
| 7635 | @Override |
| 7636 | public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) { |
| 7637 | enforceActiveEmergencySessionPermission(); |
| 7638 | |
| 7639 | final long identity = Binder.clearCallingIdentity(); |
| 7640 | try { |
| 7641 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7642 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7643 | if (tracker != null) { |
| 7644 | tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath); |
| 7645 | } |
| 7646 | } |
| 7647 | } finally { |
| 7648 | Binder.restoreCallingIdentity(identity); |
| 7649 | } |
| 7650 | } |
| 7651 | |
| 7652 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7653 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 7654 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 7655 | Phone phone = getPhone(subId); |
| 7656 | if (phone == null) { |
| 7657 | return null; |
| 7658 | } |
| 7659 | final long identity = Binder.clearCallingIdentity(); |
| 7660 | try { |
| 7661 | UiccProfile profile = UiccController.getInstance() |
| 7662 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 7663 | if (profile != null) { |
| 7664 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 7665 | } |
| 7666 | } finally { |
| 7667 | Binder.restoreCallingIdentity(identity); |
| 7668 | } |
| 7669 | return null; |
| 7670 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 7671 | |
| 7672 | /** |
| 7673 | * Enable or disable a modem stack. |
| 7674 | */ |
| 7675 | @Override |
| 7676 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 7677 | enforceModifyPermission(); |
| 7678 | |
| 7679 | final long identity = Binder.clearCallingIdentity(); |
| 7680 | try { |
| 7681 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7682 | if (phone == null) { |
| 7683 | return false; |
| 7684 | } else { |
| 7685 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 7686 | } |
| 7687 | } finally { |
| 7688 | Binder.restoreCallingIdentity(identity); |
| 7689 | } |
| 7690 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7691 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7692 | /** |
| 7693 | * Whether a modem stack is enabled or not. |
| 7694 | */ |
| 7695 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7696 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 7697 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7698 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7699 | if (phone == null) return false; |
| 7700 | |
| 7701 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7702 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 7703 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7704 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7705 | } |
| 7706 | |
| 7707 | final long identity = Binder.clearCallingIdentity(); |
| 7708 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 7709 | try { |
| 7710 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 7711 | } catch (NoSuchElementException ex) { |
| 7712 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 7713 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7714 | } finally { |
| 7715 | Binder.restoreCallingIdentity(identity); |
| 7716 | } |
| 7717 | } |
| 7718 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7719 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7720 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7721 | enforceModifyPermission(); |
| 7722 | |
| 7723 | final long identity = Binder.clearCallingIdentity(); |
| 7724 | try { |
| 7725 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7726 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7727 | .commit(); |
| 7728 | } finally { |
| 7729 | Binder.restoreCallingIdentity(identity); |
| 7730 | } |
| 7731 | } |
| 7732 | |
| 7733 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7734 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7735 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7736 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7737 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 7738 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7739 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7740 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7741 | |
| 7742 | final long identity = Binder.clearCallingIdentity(); |
| 7743 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7744 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7745 | } finally { |
| 7746 | Binder.restoreCallingIdentity(identity); |
| 7747 | } |
| 7748 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7749 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7750 | @TelephonyManager.IsMultiSimSupportedResult |
| 7751 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7752 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 7753 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 7754 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7755 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 7756 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7757 | } |
| 7758 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 7759 | // supported by the modem, indicate that it is restricted. |
| 7760 | PhoneCapability staticCapability = |
| 7761 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 7762 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7763 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 7764 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7765 | } |
| 7766 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7767 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 7768 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7769 | } |
| 7770 | // Check if support of multiple SIMs is restricted by carrier |
| 7771 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7772 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7773 | } |
| 7774 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7775 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7776 | } |
| 7777 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7778 | /** |
| 7779 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7780 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 7781 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 7782 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7783 | * @param numOfSims number of active sims we want to switch to |
| 7784 | */ |
| 7785 | @Override |
| 7786 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 7787 | if (numOfSims == 1) { |
| 7788 | enforceModifyPermission(); |
| 7789 | } else { |
| 7790 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7791 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 7792 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7793 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7794 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7795 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7796 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7797 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7798 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 7799 | return; |
| 7800 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7801 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 7802 | } finally { |
| 7803 | Binder.restoreCallingIdentity(identity); |
| 7804 | } |
| 7805 | } |
| 7806 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 7807 | @Override |
| 7808 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 7809 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 7810 | Phone phone = getPhone(subId); |
| 7811 | if (phone == null) { |
| 7812 | return false; |
| 7813 | } |
| 7814 | final long identity = Binder.clearCallingIdentity(); |
| 7815 | try { |
| 7816 | UiccCard uiccCard = phone.getUiccCard(); |
| 7817 | if (uiccCard == null) { |
| 7818 | return false; |
| 7819 | } |
| 7820 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7821 | if (uiccProfile == null) { |
| 7822 | return false; |
| 7823 | } |
| 7824 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 7825 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 7826 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 7827 | } |
| 7828 | return false; |
| 7829 | } finally { |
| 7830 | Binder.restoreCallingIdentity(identity); |
| 7831 | } |
| 7832 | } |
| 7833 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7834 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7835 | * Get whether making changes to modem configurations will trigger reboot. |
| 7836 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 7837 | */ |
| 7838 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7839 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 7840 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7841 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7842 | mApp, subId, callingPackage, callingFeatureId, |
| 7843 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 7844 | return false; |
| 7845 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 7846 | final long identity = Binder.clearCallingIdentity(); |
| 7847 | try { |
| 7848 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 7849 | } finally { |
| 7850 | Binder.restoreCallingIdentity(identity); |
| 7851 | } |
| 7852 | } |
| 7853 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 7854 | private void updateModemStateMetrics() { |
| 7855 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 7856 | // TODO: check the state for each modem if the api is ready. |
| 7857 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 7858 | } |
| 7859 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 7860 | @Override |
| 7861 | public int[] getSlotsMapping() { |
| 7862 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 7863 | |
| 7864 | final long identity = Binder.clearCallingIdentity(); |
| 7865 | try { |
| 7866 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 7867 | // All logical slots should have a mapping to a physical slot. |
| 7868 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 7869 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 7870 | for (int i = 0; i < slotInfos.length; i++) { |
| 7871 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 7872 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 7873 | } |
| 7874 | } |
| 7875 | return logicalSlotsMapping; |
| 7876 | } finally { |
| 7877 | Binder.restoreCallingIdentity(identity); |
| 7878 | } |
| 7879 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 7880 | |
| 7881 | /** |
| 7882 | * Get the IRadio HAL Version |
| 7883 | */ |
| 7884 | @Override |
| 7885 | public int getRadioHalVersion() { |
| 7886 | Phone phone = getDefaultPhone(); |
| 7887 | if (phone == null) return -1; |
| 7888 | HalVersion hv = phone.getHalVersion(); |
| 7889 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 7890 | return hv.major * 100 + hv.minor; |
| 7891 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7892 | |
| 7893 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 7894 | * Get the current calling package name. |
| 7895 | * @return the current calling package name |
| 7896 | */ |
| 7897 | @Override |
| 7898 | public String getCurrentPackageName() { |
| 7899 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 7900 | } |
| 7901 | |
| 7902 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7903 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 7904 | * corresponding network requests on a subId. |
| 7905 | * |
| 7906 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7907 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7908 | * 2) APN is un-metered for this subscription, or |
| 7909 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 7910 | * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7911 | * |
| 7912 | * @return whether data is allowed for a apn type. |
| 7913 | * |
| 7914 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7915 | */ |
| 7916 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7917 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 7918 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 7919 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7920 | |
| 7921 | // Now that all security checks passes, perform the operation as ourselves. |
| 7922 | final long identity = Binder.clearCallingIdentity(); |
| 7923 | try { |
| 7924 | Phone phone = getPhone(subId); |
| 7925 | if (phone == null) return false; |
| 7926 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7927 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7928 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 7929 | } finally { |
| 7930 | Binder.restoreCallingIdentity(identity); |
| 7931 | } |
| 7932 | } |
| 7933 | |
| 7934 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7935 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 7936 | enforceReadPrivilegedPermission("isApnMetered"); |
| 7937 | |
| 7938 | // Now that all security checks passes, perform the operation as ourselves. |
| 7939 | final long identity = Binder.clearCallingIdentity(); |
| 7940 | try { |
| 7941 | Phone phone = getPhone(subId); |
| 7942 | if (phone == null) return true; // By default return true. |
| 7943 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 7944 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 7945 | } finally { |
| 7946 | Binder.restoreCallingIdentity(identity); |
| 7947 | } |
| 7948 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 7949 | |
| 7950 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame^] | 7951 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 7952 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 7953 | enforceModifyPermission(); |
| 7954 | long token = Binder.clearCallingIdentity(); |
| 7955 | try { |
| 7956 | Phone phone = getPhone(subscriptionId); |
| 7957 | if (phone == null) { |
| 7958 | try { |
| 7959 | if (resultCallback != null) { |
| 7960 | resultCallback.accept(false); |
| 7961 | } |
| 7962 | } catch (RemoteException e) { |
| 7963 | // ignore |
| 7964 | } |
| 7965 | return; |
| 7966 | } |
| 7967 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 7968 | Pair.create(specifiers, (x) -> { |
| 7969 | try { |
| 7970 | if (resultCallback != null) { |
| 7971 | resultCallback.accept(x); |
| 7972 | } |
| 7973 | } catch (RemoteException e) { |
| 7974 | // ignore |
| 7975 | } |
| 7976 | }); |
| 7977 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 7978 | } finally { |
| 7979 | Binder.restoreCallingIdentity(token); |
| 7980 | } |
| 7981 | } |
| 7982 | |
| 7983 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 7984 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
| 7985 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 7986 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 7987 | if (iccRecords == null) { |
| 7988 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 7989 | return false; |
| 7990 | } |
| 7991 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 7992 | } |
| 7993 | |
| 7994 | @Override |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 7995 | public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 7996 | if (callingPackage == null) { |
| 7997 | callingPackage = getCurrentPackageName(); |
| 7998 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 7999 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 8000 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
| 8001 | if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) { |
| 8002 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 8003 | } |
| 8004 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 8005 | Intent intent = new Intent(); |
| 8006 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 8007 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 8008 | // Bring up choose default SMS subscription dialog right now |
| 8009 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 8010 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 8011 | mApp.startActivity(intent); |
| 8012 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8013 | |
| 8014 | @Override |
| 8015 | public String getMmsUAProfUrl(int subId) { |
| 8016 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8017 | final long identity = Binder.clearCallingIdentity(); |
| 8018 | try { |
| 8019 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8020 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 8021 | } finally { |
| 8022 | Binder.restoreCallingIdentity(identity); |
| 8023 | } |
| 8024 | } |
| 8025 | |
| 8026 | @Override |
| 8027 | public String getMmsUserAgent(int subId) { |
| 8028 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8029 | final long identity = Binder.clearCallingIdentity(); |
| 8030 | try { |
| 8031 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8032 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 8033 | } finally { |
| 8034 | Binder.restoreCallingIdentity(identity); |
| 8035 | } |
| 8036 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8037 | |
| 8038 | @Override |
| 8039 | public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) { |
| 8040 | enforceModifyPermission(); |
| 8041 | |
| 8042 | // Now that all security checks passes, perform the operation as ourselves. |
| 8043 | final long identity = Binder.clearCallingIdentity(); |
| 8044 | try { |
| 8045 | Phone phone = getPhone(subId); |
| 8046 | if (phone == null) return false; |
| 8047 | |
| 8048 | return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow); |
| 8049 | } finally { |
| 8050 | Binder.restoreCallingIdentity(identity); |
| 8051 | } |
| 8052 | } |
| 8053 | |
| 8054 | @Override |
| 8055 | public boolean isDataAllowedInVoiceCall(int subId) { |
| 8056 | enforceReadPrivilegedPermission("isDataAllowedInVoiceCall"); |
| 8057 | |
| 8058 | // Now that all security checks passes, perform the operation as ourselves. |
| 8059 | final long identity = Binder.clearCallingIdentity(); |
| 8060 | try { |
| 8061 | Phone phone = getPhone(subId); |
| 8062 | if (phone == null) return false; |
| 8063 | |
| 8064 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 8065 | } finally { |
| 8066 | Binder.restoreCallingIdentity(identity); |
| 8067 | } |
| 8068 | } |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8069 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8070 | @Override |
| 8071 | public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) { |
| 8072 | enforceModifyPermission(); |
| 8073 | |
| 8074 | // Now that all security checks passes, perform the operation as ourselves. |
| 8075 | final long identity = Binder.clearCallingIdentity(); |
| 8076 | try { |
| 8077 | Phone phone = getPhone(subId); |
| 8078 | if (phone == null) return false; |
| 8079 | |
| 8080 | return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow); |
| 8081 | } finally { |
| 8082 | Binder.restoreCallingIdentity(identity); |
| 8083 | } |
| 8084 | } |
| 8085 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8086 | /** |
| 8087 | * Updates whether conference event pacakge handling is enabled. |
| 8088 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 8089 | * otherwise. |
| 8090 | */ |
| 8091 | @Override |
| 8092 | public void setCepEnabled(boolean isCepEnabled) { |
| 8093 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 8094 | |
| 8095 | final long identity = Binder.clearCallingIdentity(); |
| 8096 | try { |
| 8097 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 8098 | for (Phone phone : PhoneFactory.getPhones()) { |
| 8099 | Phone defaultPhone = phone.getImsPhone(); |
| 8100 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 8101 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 8102 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 8103 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 8104 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 8105 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 8106 | + imsPhone.getMsisdn()); |
| 8107 | } |
| 8108 | } |
| 8109 | } finally { |
| 8110 | Binder.restoreCallingIdentity(identity); |
| 8111 | } |
| 8112 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 8113 | |
| 8114 | /** |
| 8115 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 8116 | * |
| 8117 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 8118 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 8119 | * before being read. |
| 8120 | */ |
| 8121 | @Override |
| 8122 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 8123 | isCompressed) { |
| 8124 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8125 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
| 8126 | try { |
| 8127 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 8128 | if (configBinder == null) { |
| 8129 | Rlog.e(LOG_TAG, "null result for getImsConfig"); |
| 8130 | } else { |
| 8131 | configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed); |
| 8132 | } |
| 8133 | } catch (RemoteException e) { |
| 8134 | Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage()); |
| 8135 | } |
| 8136 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8137 | |
| 8138 | @Override |
| 8139 | public boolean isIccLockEnabled(int subId) { |
| 8140 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 8141 | |
| 8142 | // Now that all security checks passes, perform the operation as ourselves. |
| 8143 | final long identity = Binder.clearCallingIdentity(); |
| 8144 | try { |
| 8145 | Phone phone = getPhone(subId); |
| 8146 | if (phone != null && phone.getIccCard() != null) { |
| 8147 | return phone.getIccCard().getIccLockEnabled(); |
| 8148 | } else { |
| 8149 | return false; |
| 8150 | } |
| 8151 | } finally { |
| 8152 | Binder.restoreCallingIdentity(identity); |
| 8153 | } |
| 8154 | } |
| 8155 | |
| 8156 | /** |
| 8157 | * Set the ICC pin lock enabled or disabled. |
| 8158 | * |
| 8159 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 8160 | * three cases: |
| 8161 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 8162 | * successfully. |
| 8163 | * - Positive number and zero for remaining password attempts. |
| 8164 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 8165 | * |
| 8166 | */ |
| 8167 | @Override |
| 8168 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 8169 | enforceModifyPermission(); |
| 8170 | |
| 8171 | Phone phone = getPhone(subId); |
| 8172 | if (phone == null) { |
| 8173 | return 0; |
| 8174 | } |
| 8175 | // Now that all security checks passes, perform the operation as ourselves. |
| 8176 | final long identity = Binder.clearCallingIdentity(); |
| 8177 | try { |
| 8178 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 8179 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 8180 | return attemptsRemaining; |
| 8181 | |
| 8182 | } catch (Exception e) { |
| 8183 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 8184 | } finally { |
| 8185 | Binder.restoreCallingIdentity(identity); |
| 8186 | } |
| 8187 | return 0; |
| 8188 | } |
| 8189 | |
| 8190 | /** |
| 8191 | * Change the ICC password used in ICC pin lock. |
| 8192 | * |
| 8193 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 8194 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 8195 | * - Positive number and zero for remaining password attempts. |
| 8196 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 8197 | * |
| 8198 | */ |
| 8199 | @Override |
| 8200 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 8201 | enforceModifyPermission(); |
| 8202 | |
| 8203 | Phone phone = getPhone(subId); |
| 8204 | if (phone == null) { |
| 8205 | return 0; |
| 8206 | } |
| 8207 | // Now that all security checks passes, perform the operation as ourselves. |
| 8208 | final long identity = Binder.clearCallingIdentity(); |
| 8209 | try { |
| 8210 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 8211 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 8212 | return attemptsRemaining; |
| 8213 | |
| 8214 | } catch (Exception e) { |
| 8215 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 8216 | } finally { |
| 8217 | Binder.restoreCallingIdentity(identity); |
| 8218 | } |
| 8219 | return 0; |
| 8220 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 8221 | } |