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; |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 25 | import android.annotation.NonNull; |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 26 | import android.annotation.Nullable; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 27 | import android.app.AppOpsManager; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 28 | import android.app.PendingIntent; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 29 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 30 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 31 | import android.content.Context; |
| 32 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 33 | import android.content.SharedPreferences; |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 34 | import android.content.pm.ApplicationInfo; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 35 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 36 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 37 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 38 | import android.net.Uri; |
| 39 | import android.os.AsyncResult; |
| 40 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 41 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 42 | import android.os.Bundle; |
| 43 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 44 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.os.Looper; |
| 46 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 47 | import android.os.Messenger; |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 48 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 49 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 50 | import android.os.PersistableBundle; |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 51 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 52 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 53 | import android.os.ResultReceiver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 54 | import android.os.ServiceManager; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 55 | import android.os.ServiceSpecificException; |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 56 | import android.os.ShellCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 57 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 58 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 59 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 60 | import android.preference.PreferenceManager; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 61 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 62 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 63 | import android.provider.Telephony; |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 64 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 65 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 66 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 67 | import android.telecom.TelecomManager; |
Chen Xu | c7b18ec | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 68 | import android.telephony.Annotation.ApnType; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 69 | import android.telephony.CallForwardingInfo; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 70 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 71 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 72 | import android.telephony.CellIdentity; |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 73 | import android.telephony.CellIdentityCdma; |
| 74 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 75 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 76 | import android.telephony.CellInfoGsm; |
| 77 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 78 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 79 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 80 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 81 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 82 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 83 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 84 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 85 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 86 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 87 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 88 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 89 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 90 | import android.telephony.SignalStrength; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 91 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 92 | import android.telephony.SubscriptionManager; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 93 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 94 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 95 | import android.telephony.TelephonyScanManager; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 96 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 97 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 98 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 99 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 100 | import android.telephony.data.ApnSetting; |
| 101 | import android.telephony.emergency.EmergencyNumber; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 102 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 103 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 104 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 105 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 106 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 107 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 108 | import android.telephony.ims.aidl.IImsMmTelFeature; |
| 109 | import android.telephony.ims.aidl.IImsRcsFeature; |
| 110 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 111 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 112 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 113 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 114 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 115 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 116 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 117 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 118 | import android.util.ArraySet; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 119 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 120 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 121 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 122 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 123 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Jordan Liu | a39e6c1 | 2020-03-04 13:59:23 -0800 | [diff] [blame] | 124 | import com.android.internal.annotations.VisibleForTesting; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 125 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 127 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 129 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 130 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.CommandException; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 132 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 134 | import com.android.internal.telephony.HalVersion; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 135 | import com.android.internal.telephony.IBooleanConsumer; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 137 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 139 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 145 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.SubscriptionController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 155 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 157 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 159 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 161 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 162 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 163 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 165 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 166 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 167 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 169 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 171 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 172 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 173 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 175 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 176 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 177 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 178 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 179 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 180 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 181 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 182 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 183 | import java.io.FileDescriptor; |
| 184 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 185 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 186 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 187 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 188 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 189 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 190 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 191 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 192 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 193 | import java.util.Set; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 194 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 195 | |
| 196 | /** |
| 197 | * Implementation of the ITelephony interface. |
| 198 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 199 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 200 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 201 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 202 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 203 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 204 | |
| 205 | // Message codes used with mMainThreadHandler |
| 206 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 207 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 208 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 209 | private static final int CMD_OPEN_CHANNEL = 9; |
| 210 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 211 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 212 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 213 | private static final int CMD_NV_READ_ITEM = 13; |
| 214 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 215 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 216 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 217 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 218 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 219 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 220 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 221 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 222 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 223 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 224 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 225 | private static final int CMD_SEND_ENVELOPE = 25; |
| 226 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 227 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 228 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 229 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 230 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 231 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 232 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 233 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 234 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 235 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 236 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 237 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 238 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 239 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 240 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 241 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 242 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 243 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 244 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 245 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 246 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 247 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 248 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 249 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 250 | private static final int CMD_SWITCH_SLOTS = 50; |
| 251 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 252 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 253 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 254 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 255 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 256 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 257 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 258 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 259 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 260 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 261 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 262 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 263 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 264 | private static final int CMD_MODEM_REBOOT = 64; |
| 265 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 266 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 267 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 268 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 269 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 270 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 271 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 272 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 273 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 274 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 275 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 276 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 277 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 278 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 279 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 280 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 281 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 282 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 283 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 284 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 285 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 286 | private static final int CMD_GET_CALL_WAITING = 87; |
| 287 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 288 | private static final int CMD_SET_CALL_WAITING = 89; |
| 289 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 290 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 291 | // Parameters of select command. |
| 292 | private static final int SELECT_COMMAND = 0xA4; |
| 293 | private static final int SELECT_P1 = 0x04; |
| 294 | private static final int SELECT_P2 = 0; |
| 295 | private static final int SELECT_P3 = 0x10; |
| 296 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 297 | /** The singleton instance. */ |
| 298 | private static PhoneInterfaceManager sInstance; |
| 299 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 300 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 301 | private CallManager mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 302 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 303 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 304 | private AppOpsManager mAppOps; |
| 305 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 306 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 307 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 308 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 309 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 310 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 311 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 312 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 313 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 314 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 315 | // String to store multi SIM allowed |
| 316 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 317 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 318 | // The AID of ISD-R. |
| 319 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 320 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 321 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 322 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 323 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 324 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 325 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 326 | /** |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 327 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 328 | */ |
| 329 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 330 | "reset_network_erase_modem_config_enabled"; |
| 331 | |
| 332 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 333 | * A request object to use for transmitting data to an ICC. |
| 334 | */ |
| 335 | private static final class IccAPDUArgument { |
| 336 | public int channel, cla, command, p1, p2, p3; |
| 337 | public String data; |
| 338 | |
| 339 | public IccAPDUArgument(int channel, int cla, int command, |
| 340 | int p1, int p2, int p3, String data) { |
| 341 | this.channel = channel; |
| 342 | this.cla = cla; |
| 343 | this.command = command; |
| 344 | this.p1 = p1; |
| 345 | this.p2 = p2; |
| 346 | this.p3 = p3; |
| 347 | this.data = data; |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 352 | * A request object to use for transmitting data to an ICC. |
| 353 | */ |
| 354 | private static final class ManualNetworkSelectionArgument { |
| 355 | public OperatorInfo operatorInfo; |
| 356 | public boolean persistSelection; |
| 357 | |
| 358 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 359 | this.operatorInfo = operatorInfo; |
| 360 | this.persistSelection = persistSelection; |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 365 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 366 | * request after sending. The main thread will notify the request when it is complete. |
| 367 | */ |
| 368 | private static final class MainThreadRequest { |
| 369 | /** The argument to use for the request */ |
| 370 | public Object argument; |
| 371 | /** The result of the request that is run on the main thread */ |
| 372 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 373 | // The subscriber id that this request applies to. Defaults to |
| 374 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 375 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 376 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 377 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 378 | public Phone phone; |
| 379 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 380 | public WorkSource workSource; |
| 381 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 382 | public MainThreadRequest(Object argument) { |
| 383 | this.argument = argument; |
| 384 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 385 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 386 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 387 | this.argument = argument; |
| 388 | if (phone != null) { |
| 389 | this.phone = phone; |
| 390 | } |
| 391 | this.workSource = workSource; |
| 392 | } |
| 393 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 394 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 395 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 396 | if (subId != null) { |
| 397 | this.subId = subId; |
| 398 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 399 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 400 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 401 | } |
| 402 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 403 | private static final class IncomingThirdPartyCallArgs { |
| 404 | public final ComponentName component; |
| 405 | public final String callId; |
| 406 | public final String callerDisplayName; |
| 407 | |
| 408 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 409 | String callerDisplayName) { |
| 410 | this.component = component; |
| 411 | this.callId = callId; |
| 412 | this.callerDisplayName = callerDisplayName; |
| 413 | } |
| 414 | } |
| 415 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 416 | /** |
| 417 | * A handler that processes messages on the main thread in the phone process. Since many |
| 418 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 419 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 420 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 421 | * on, which will be notified when the operation completes and will contain the result of the |
| 422 | * request. |
| 423 | * |
| 424 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 425 | * note that request.result must be set to something non-null for the calling thread to |
| 426 | * unblock. |
| 427 | */ |
| 428 | private final class MainThreadHandler extends Handler { |
| 429 | @Override |
| 430 | public void handleMessage(Message msg) { |
| 431 | MainThreadRequest request; |
| 432 | Message onCompleted; |
| 433 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 434 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 435 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 436 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 437 | |
| 438 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 439 | case CMD_HANDLE_USSD_REQUEST: { |
| 440 | request = (MainThreadRequest) msg.obj; |
| 441 | final Phone phone = getPhoneFromRequest(request); |
| 442 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 443 | String ussdRequest = ussdObject.first; |
| 444 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 445 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 446 | if (!isUssdApiAllowed(request.subId)) { |
| 447 | // Carrier does not support use of this API, return failure. |
| 448 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 449 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 450 | Bundle returnData = new Bundle(); |
| 451 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 452 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 453 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 454 | request.result = true; |
| 455 | notifyRequester(request); |
| 456 | return; |
| 457 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 458 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 459 | try { |
| 460 | request.result = phone != null |
| 461 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 462 | } catch (CallStateException cse) { |
| 463 | request.result = false; |
| 464 | } |
| 465 | // Wake up the requesting thread |
| 466 | notifyRequester(request); |
| 467 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 468 | } |
| 469 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 470 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 471 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 472 | final Phone phone = getPhoneFromRequest(request); |
| 473 | request.result = phone != null ? |
| 474 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 475 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 476 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 477 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 478 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 479 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 480 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 481 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 482 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 483 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 484 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 485 | if (uiccCard == null) { |
| 486 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 487 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 488 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 489 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 490 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 491 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 492 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 493 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 494 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 495 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 496 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 497 | break; |
| 498 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 499 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 500 | ar = (AsyncResult) msg.obj; |
| 501 | request = (MainThreadRequest) ar.userObj; |
| 502 | if (ar.exception == null && ar.result != null) { |
| 503 | request.result = ar.result; |
| 504 | } else { |
| 505 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 506 | if (ar.result == null) { |
| 507 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 508 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 509 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 510 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 511 | } else { |
| 512 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 513 | } |
| 514 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 515 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 516 | break; |
| 517 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 518 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 519 | request = (MainThreadRequest) msg.obj; |
| 520 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 521 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 522 | if (uiccCard == null) { |
| 523 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 524 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 525 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 526 | } else { |
| 527 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 528 | request); |
| 529 | uiccCard.iccTransmitApduBasicChannel( |
| 530 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 531 | iccArgument.p3, iccArgument.data, onCompleted); |
| 532 | } |
| 533 | break; |
| 534 | |
| 535 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 536 | ar = (AsyncResult) msg.obj; |
| 537 | request = (MainThreadRequest) ar.userObj; |
| 538 | if (ar.exception == null && ar.result != null) { |
| 539 | request.result = ar.result; |
| 540 | } else { |
| 541 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 542 | if (ar.result == null) { |
| 543 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 544 | } else if (ar.exception instanceof CommandException) { |
| 545 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 546 | ar.exception); |
| 547 | } else { |
| 548 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 549 | } |
| 550 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 551 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 552 | break; |
| 553 | |
| 554 | case CMD_EXCHANGE_SIM_IO: |
| 555 | request = (MainThreadRequest) msg.obj; |
| 556 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 557 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 558 | if (uiccCard == null) { |
| 559 | loge("iccExchangeSimIO: No UICC"); |
| 560 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 561 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 562 | } else { |
| 563 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 564 | request); |
| 565 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 566 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 567 | iccArgument.data, onCompleted); |
| 568 | } |
| 569 | break; |
| 570 | |
| 571 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 572 | ar = (AsyncResult) msg.obj; |
| 573 | request = (MainThreadRequest) ar.userObj; |
| 574 | if (ar.exception == null && ar.result != null) { |
| 575 | request.result = ar.result; |
| 576 | } else { |
| 577 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 578 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 579 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 580 | break; |
| 581 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 582 | case CMD_SEND_ENVELOPE: |
| 583 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 584 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 585 | if (uiccCard == null) { |
| 586 | loge("sendEnvelopeWithStatus: No UICC"); |
| 587 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 588 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 589 | } else { |
| 590 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 591 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 592 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 593 | break; |
| 594 | |
| 595 | case EVENT_SEND_ENVELOPE_DONE: |
| 596 | ar = (AsyncResult) msg.obj; |
| 597 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 598 | if (ar.exception == null && ar.result != null) { |
| 599 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 600 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 601 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 602 | if (ar.result == null) { |
| 603 | loge("sendEnvelopeWithStatus: Empty response"); |
| 604 | } else if (ar.exception instanceof CommandException) { |
| 605 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 606 | ar.exception); |
| 607 | } else { |
| 608 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 609 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 610 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 611 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 612 | break; |
| 613 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 614 | case CMD_OPEN_CHANNEL: |
| 615 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 616 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 617 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 618 | if (uiccCard == null) { |
| 619 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 620 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 621 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 622 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 623 | } else { |
| 624 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 625 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 626 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 627 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 628 | break; |
| 629 | |
| 630 | case EVENT_OPEN_CHANNEL_DONE: |
| 631 | ar = (AsyncResult) msg.obj; |
| 632 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 633 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 634 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 635 | int[] result = (int[]) ar.result; |
| 636 | int channelId = result[0]; |
| 637 | byte[] selectResponse = null; |
| 638 | if (result.length > 1) { |
| 639 | selectResponse = new byte[result.length - 1]; |
| 640 | for (int i = 1; i < result.length; ++i) { |
| 641 | selectResponse[i - 1] = (byte) result[i]; |
| 642 | } |
| 643 | } |
| 644 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 645 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 646 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 647 | if (ar.result == null) { |
| 648 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 649 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 650 | if (ar.exception != null) { |
| 651 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 652 | } |
| 653 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 654 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 655 | if (ar.exception instanceof CommandException) { |
| 656 | CommandException.Error error = |
| 657 | ((CommandException) (ar.exception)).getCommandError(); |
| 658 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 659 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 660 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 661 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 662 | } |
| 663 | } |
| 664 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 665 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 666 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 667 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 668 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 669 | break; |
| 670 | |
| 671 | case CMD_CLOSE_CHANNEL: |
| 672 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 673 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 674 | if (uiccCard == null) { |
| 675 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 676 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 677 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 678 | } else { |
| 679 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 680 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 681 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 682 | break; |
| 683 | |
| 684 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 685 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 686 | break; |
| 687 | |
| 688 | case CMD_NV_READ_ITEM: |
| 689 | request = (MainThreadRequest) msg.obj; |
| 690 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 691 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 692 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 693 | break; |
| 694 | |
| 695 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 696 | ar = (AsyncResult) msg.obj; |
| 697 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 698 | if (ar.exception == null && ar.result != null) { |
| 699 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 700 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 701 | request.result = ""; |
| 702 | if (ar.result == null) { |
| 703 | loge("nvReadItem: Empty response"); |
| 704 | } else if (ar.exception instanceof CommandException) { |
| 705 | loge("nvReadItem: CommandException: " + |
| 706 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 707 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 708 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 709 | } |
| 710 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 711 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 712 | break; |
| 713 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 714 | case CMD_NV_WRITE_ITEM: |
| 715 | request = (MainThreadRequest) msg.obj; |
| 716 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 717 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 718 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 719 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 720 | break; |
| 721 | |
| 722 | case EVENT_NV_WRITE_ITEM_DONE: |
| 723 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 724 | break; |
| 725 | |
| 726 | case CMD_NV_WRITE_CDMA_PRL: |
| 727 | request = (MainThreadRequest) msg.obj; |
| 728 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 729 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 730 | break; |
| 731 | |
| 732 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 733 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 734 | break; |
| 735 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 736 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 737 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 738 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 739 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 740 | break; |
| 741 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 742 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 743 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 744 | break; |
| 745 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 746 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 747 | request = (MainThreadRequest) msg.obj; |
| 748 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 749 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 750 | break; |
| 751 | |
| 752 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 753 | ar = (AsyncResult) msg.obj; |
| 754 | request = (MainThreadRequest) ar.userObj; |
| 755 | if (ar.exception == null && ar.result != null) { |
| 756 | request.result = ar.result; // Integer |
| 757 | } else { |
Sanket Padawe | cfc2d35 | 2016-01-05 19:52:14 -0800 | [diff] [blame] | 758 | request.result = null; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 759 | if (ar.result == null) { |
| 760 | loge("getPreferredNetworkType: Empty response"); |
| 761 | } else if (ar.exception instanceof CommandException) { |
| 762 | loge("getPreferredNetworkType: CommandException: " + |
| 763 | ar.exception); |
| 764 | } else { |
| 765 | loge("getPreferredNetworkType: Unknown exception"); |
| 766 | } |
| 767 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 768 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 769 | break; |
| 770 | |
| 771 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 772 | request = (MainThreadRequest) msg.obj; |
| 773 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 774 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 775 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 776 | break; |
| 777 | |
| 778 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 779 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 780 | break; |
| 781 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 782 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 783 | request = (MainThreadRequest)msg.obj; |
| 784 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 785 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 786 | break; |
| 787 | |
| 788 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 789 | ar = (AsyncResult)msg.obj; |
| 790 | request = (MainThreadRequest)ar.userObj; |
| 791 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 792 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 793 | break; |
| 794 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 795 | case CMD_SET_VOICEMAIL_NUMBER: |
| 796 | request = (MainThreadRequest) msg.obj; |
| 797 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 798 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 799 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 800 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 801 | break; |
| 802 | |
| 803 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 804 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 805 | break; |
| 806 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 807 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 808 | request = (MainThreadRequest) msg.obj; |
| 809 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 810 | request); |
| 811 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 812 | break; |
| 813 | |
| 814 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 815 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 816 | break; |
| 817 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 818 | case CMD_PERFORM_NETWORK_SCAN: |
| 819 | request = (MainThreadRequest) msg.obj; |
| 820 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 821 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 822 | break; |
| 823 | |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 824 | case CMD_GET_CALL_FORWARDING: |
| 825 | request = (MainThreadRequest) msg.obj; |
| 826 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
| 827 | int callForwardingReason = (Integer) request.argument; |
| 828 | getPhoneFromRequest(request).getCallForwardingOption( |
| 829 | callForwardingReason, onCompleted); |
| 830 | break; |
| 831 | |
| 832 | case EVENT_GET_CALL_FORWARDING_DONE: |
| 833 | ar = (AsyncResult) msg.obj; |
| 834 | request = (MainThreadRequest) ar.userObj; |
| 835 | CallForwardingInfo callForwardingInfo = null; |
| 836 | if (ar.exception == null && ar.result != null) { |
| 837 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 838 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 839 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 840 | // any service for voice call. |
| 841 | if ((callForwardInfo.serviceClass |
| 842 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
| 843 | callForwardingInfo = new CallForwardingInfo( |
| 844 | callForwardInfo.serviceClass, callForwardInfo.reason, |
| 845 | callForwardInfo.number, |
| 846 | callForwardInfo.timeSeconds); |
| 847 | break; |
| 848 | } |
| 849 | } |
| 850 | // Didn't find a call forward info for voice call. |
| 851 | if (callForwardingInfo == null) { |
| 852 | callForwardingInfo = new CallForwardingInfo( |
| 853 | CallForwardingInfo.STATUS_UNKNOWN_ERROR, |
| 854 | 0 /* reason */, null /* number */, 0 /* timeout */); |
| 855 | } |
| 856 | } else { |
| 857 | if (ar.result == null) { |
| 858 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 859 | } |
| 860 | if (ar.exception != null) { |
| 861 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 862 | } |
| 863 | int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR; |
| 864 | if (ar.exception instanceof CommandException) { |
| 865 | CommandException.Error error = |
| 866 | ((CommandException) (ar.exception)).getCommandError(); |
| 867 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
| 868 | errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE; |
| 869 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 870 | errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED; |
| 871 | } |
| 872 | } |
| 873 | callForwardingInfo = new CallForwardingInfo( |
| 874 | errorCode, 0 /* reason */, null /* number */, 0 /* timeout */); |
| 875 | } |
| 876 | request.result = callForwardingInfo; |
| 877 | notifyRequester(request); |
| 878 | break; |
| 879 | |
| 880 | case CMD_SET_CALL_FORWARDING: |
| 881 | request = (MainThreadRequest) msg.obj; |
| 882 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
| 883 | CallForwardingInfo callForwardingInfoToSet = |
| 884 | (CallForwardingInfo) request.argument; |
| 885 | getPhoneFromRequest(request).setCallForwardingOption( |
| 886 | callForwardingInfoToSet.getStatus(), |
| 887 | callForwardingInfoToSet.getReason(), |
| 888 | callForwardingInfoToSet.getNumber(), |
| 889 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 890 | break; |
| 891 | |
| 892 | case EVENT_SET_CALL_FORWARDING_DONE: |
| 893 | ar = (AsyncResult) msg.obj; |
| 894 | request = (MainThreadRequest) ar.userObj; |
| 895 | if (ar.exception == null) { |
| 896 | request.result = true; |
| 897 | } else { |
| 898 | request.result = false; |
| 899 | loge("setCallForwarding exception: " + ar.exception); |
| 900 | } |
| 901 | notifyRequester(request); |
| 902 | break; |
| 903 | |
| 904 | case CMD_GET_CALL_WAITING: |
| 905 | request = (MainThreadRequest) msg.obj; |
| 906 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 907 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 908 | break; |
| 909 | |
| 910 | case EVENT_GET_CALL_WAITING_DONE: |
| 911 | ar = (AsyncResult) msg.obj; |
| 912 | request = (MainThreadRequest) ar.userObj; |
| 913 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 914 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 915 | int[] callForwardResults = (int[]) ar.result; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 916 | // Service Class is a bit mask per 3gpp 27.007. |
| 917 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 918 | if (callForwardResults.length > 1 |
| 919 | && ((callForwardResults[1] |
| 920 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
| 921 | callForwardingStatus = callForwardResults[0] == 0 |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 922 | ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE |
| 923 | : TelephonyManager.CALL_WAITING_STATUS_ACTIVE; |
| 924 | } else { |
| 925 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE; |
| 926 | } |
| 927 | } else { |
| 928 | if (ar.result == null) { |
| 929 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 930 | } |
| 931 | if (ar.exception != null) { |
| 932 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 933 | } |
| 934 | if (ar.exception instanceof CommandException) { |
| 935 | CommandException.Error error = |
| 936 | ((CommandException) (ar.exception)).getCommandError(); |
| 937 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 938 | callForwardingStatus = |
| 939 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 940 | } |
| 941 | } |
| 942 | } |
| 943 | request.result = callForwardingStatus; |
| 944 | notifyRequester(request); |
| 945 | break; |
| 946 | |
| 947 | case CMD_SET_CALL_WAITING: |
| 948 | request = (MainThreadRequest) msg.obj; |
| 949 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
| 950 | boolean isEnable = (Boolean) request.argument; |
| 951 | getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted); |
| 952 | break; |
| 953 | |
| 954 | case EVENT_SET_CALL_WAITING_DONE: |
| 955 | ar = (AsyncResult) msg.obj; |
| 956 | request = (MainThreadRequest) ar.userObj; |
| 957 | if (ar.exception == null) { |
| 958 | request.result = true; |
| 959 | } else { |
| 960 | request.result = false; |
| 961 | loge("setCallWaiting exception: " + ar.exception); |
| 962 | } |
| 963 | notifyRequester(request); |
| 964 | break; |
| 965 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 966 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 967 | ar = (AsyncResult) msg.obj; |
| 968 | request = (MainThreadRequest) ar.userObj; |
| 969 | CellNetworkScanResult cellScanResult; |
| 970 | if (ar.exception == null && ar.result != null) { |
| 971 | cellScanResult = new CellNetworkScanResult( |
| 972 | CellNetworkScanResult.STATUS_SUCCESS, |
| 973 | (List<OperatorInfo>) ar.result); |
| 974 | } else { |
| 975 | if (ar.result == null) { |
| 976 | loge("getCellNetworkScanResults: Empty response"); |
| 977 | } |
| 978 | if (ar.exception != null) { |
| 979 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 980 | } |
| 981 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 982 | if (ar.exception instanceof CommandException) { |
| 983 | CommandException.Error error = |
| 984 | ((CommandException) (ar.exception)).getCommandError(); |
| 985 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 986 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 987 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 988 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 989 | } |
| 990 | } |
| 991 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 992 | } |
| 993 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 994 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 995 | break; |
| 996 | |
| 997 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 998 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 999 | ManualNetworkSelectionArgument selArg = |
| 1000 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1001 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1002 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1003 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1004 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1005 | break; |
| 1006 | |
| 1007 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1008 | ar = (AsyncResult) msg.obj; |
| 1009 | request = (MainThreadRequest) ar.userObj; |
| 1010 | if (ar.exception == null) { |
| 1011 | request.result = true; |
| 1012 | } else { |
| 1013 | request.result = false; |
| 1014 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1015 | } |
| 1016 | notifyRequester(request); |
| 1017 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1018 | break; |
| 1019 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1020 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1021 | request = (MainThreadRequest) msg.obj; |
| 1022 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1023 | if (defaultPhone != null) { |
| 1024 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1025 | } else { |
| 1026 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1027 | Bundle bundle = new Bundle(); |
| 1028 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
| 1029 | new ModemActivityInfo(0, 0, 0, new int[0], 0)); |
| 1030 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1031 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1032 | break; |
| 1033 | |
| 1034 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 1035 | ar = (AsyncResult) msg.obj; |
| 1036 | request = (MainThreadRequest) ar.userObj; |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1037 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1038 | |
| 1039 | ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1040 | if (ar.exception == null && ar.result != null) { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1041 | // Update the last modem activity info and the result of the request. |
| 1042 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1043 | if (isModemActivityInfoValid(info)) { |
| 1044 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 1045 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1046 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1047 | .getTransmitTimeMillis(); |
| 1048 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1049 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1050 | } |
| 1051 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 1052 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1053 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1054 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1055 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1056 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1057 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1058 | info.getReceiveTimeMillis() |
| 1059 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1060 | } |
| 1061 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 1062 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1063 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1064 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1065 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1066 | } else { |
| 1067 | if (ar.result == null) { |
| 1068 | loge("queryModemActivityInfo: Empty response"); |
| 1069 | } else if (ar.exception instanceof CommandException) { |
| 1070 | loge("queryModemActivityInfo: CommandException: " + |
| 1071 | ar.exception); |
| 1072 | } else { |
| 1073 | loge("queryModemActivityInfo: Unknown exception"); |
| 1074 | } |
| 1075 | } |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1076 | Bundle bundle = new Bundle(); |
| 1077 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1078 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1079 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1080 | break; |
| 1081 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1082 | case CMD_SET_ALLOWED_CARRIERS: |
| 1083 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1084 | CarrierRestrictionRules argument = |
| 1085 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1086 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1087 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1088 | break; |
| 1089 | |
| 1090 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1091 | ar = (AsyncResult) msg.obj; |
| 1092 | request = (MainThreadRequest) ar.userObj; |
| 1093 | if (ar.exception == null && ar.result != null) { |
| 1094 | request.result = ar.result; |
| 1095 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1096 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1097 | if (ar.exception instanceof CommandException) { |
| 1098 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1099 | CommandException.Error error = |
| 1100 | ((CommandException) (ar.exception)).getCommandError(); |
| 1101 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1102 | request.result = |
| 1103 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1104 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1105 | } else { |
| 1106 | loge("setAllowedCarriers: Unknown exception"); |
| 1107 | } |
| 1108 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1109 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1110 | break; |
| 1111 | |
| 1112 | case CMD_GET_ALLOWED_CARRIERS: |
| 1113 | request = (MainThreadRequest) msg.obj; |
| 1114 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1115 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1116 | break; |
| 1117 | |
| 1118 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1119 | ar = (AsyncResult) msg.obj; |
| 1120 | request = (MainThreadRequest) ar.userObj; |
| 1121 | if (ar.exception == null && ar.result != null) { |
| 1122 | request.result = ar.result; |
| 1123 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1124 | request.result = new IllegalStateException( |
| 1125 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1126 | if (ar.result == null) { |
| 1127 | loge("getAllowedCarriers: Empty response"); |
| 1128 | } else if (ar.exception instanceof CommandException) { |
| 1129 | loge("getAllowedCarriers: CommandException: " + |
| 1130 | ar.exception); |
| 1131 | } else { |
| 1132 | loge("getAllowedCarriers: Unknown exception"); |
| 1133 | } |
| 1134 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1135 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1136 | break; |
| 1137 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1138 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1139 | ar = (AsyncResult) msg.obj; |
| 1140 | request = (MainThreadRequest) ar.userObj; |
| 1141 | if (ar.exception == null && ar.result != null) { |
| 1142 | request.result = ar.result; |
| 1143 | } else { |
| 1144 | request.result = new IllegalArgumentException( |
| 1145 | "Failed to retrieve Forbidden Plmns"); |
| 1146 | if (ar.result == null) { |
| 1147 | loge("getForbiddenPlmns: Empty response"); |
| 1148 | } else { |
| 1149 | loge("getForbiddenPlmns: Unknown exception"); |
| 1150 | } |
| 1151 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1152 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1153 | break; |
| 1154 | |
| 1155 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1156 | request = (MainThreadRequest) msg.obj; |
| 1157 | uiccCard = getUiccCardFromRequest(request); |
| 1158 | if (uiccCard == null) { |
| 1159 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1160 | request.result = new IllegalArgumentException( |
| 1161 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1162 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1163 | break; |
| 1164 | } |
| 1165 | Integer appType = (Integer) request.argument; |
| 1166 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1167 | if (uiccApp == null) { |
| 1168 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1169 | + appType); |
| 1170 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1171 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1172 | break; |
| 1173 | } else { |
| 1174 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1175 | + " specified type -- " + appType); |
| 1176 | } |
| 1177 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1178 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1179 | onCompleted); |
| 1180 | break; |
| 1181 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1182 | case CMD_SWITCH_SLOTS: |
| 1183 | request = (MainThreadRequest) msg.obj; |
| 1184 | int[] physicalSlots = (int[]) request.argument; |
| 1185 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1186 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1187 | break; |
| 1188 | |
| 1189 | case EVENT_SWITCH_SLOTS_DONE: |
| 1190 | ar = (AsyncResult) msg.obj; |
| 1191 | request = (MainThreadRequest) ar.userObj; |
| 1192 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1193 | notifyRequester(request); |
| 1194 | break; |
| 1195 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1196 | request = (MainThreadRequest) msg.obj; |
| 1197 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1198 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1199 | break; |
| 1200 | |
| 1201 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1202 | ar = (AsyncResult) msg.obj; |
| 1203 | request = (MainThreadRequest) ar.userObj; |
| 1204 | if (ar.exception != null) { |
| 1205 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1206 | } else { |
| 1207 | int mode = ((int[]) ar.result)[0]; |
| 1208 | if (mode == 0) { |
| 1209 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1210 | } else { |
| 1211 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1212 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1213 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1214 | notifyRequester(request); |
| 1215 | break; |
| 1216 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1217 | request = (MainThreadRequest) msg.obj; |
| 1218 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1219 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1220 | break; |
| 1221 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1222 | ar = (AsyncResult) msg.obj; |
| 1223 | request = (MainThreadRequest) ar.userObj; |
| 1224 | if (ar.exception != null) { |
| 1225 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1226 | } else { |
| 1227 | request.result = ((int[]) ar.result)[0]; |
| 1228 | } |
| 1229 | notifyRequester(request); |
| 1230 | break; |
| 1231 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1232 | request = (MainThreadRequest) msg.obj; |
| 1233 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1234 | int mode = (int) request.argument; |
| 1235 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1236 | break; |
| 1237 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1238 | ar = (AsyncResult) msg.obj; |
| 1239 | request = (MainThreadRequest) ar.userObj; |
| 1240 | request.result = ar.exception == null; |
| 1241 | notifyRequester(request); |
| 1242 | break; |
| 1243 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1244 | request = (MainThreadRequest) msg.obj; |
| 1245 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1246 | int subscriptionMode = (int) request.argument; |
| 1247 | getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted); |
| 1248 | break; |
| 1249 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1250 | ar = (AsyncResult) msg.obj; |
| 1251 | request = (MainThreadRequest) ar.userObj; |
| 1252 | request.result = ar.exception == null; |
| 1253 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1254 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1255 | case CMD_GET_ALL_CELL_INFO: |
| 1256 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1257 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1258 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1259 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1260 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1261 | ar = (AsyncResult) msg.obj; |
| 1262 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1263 | // If a timeout occurs, the response will be null |
| 1264 | request.result = (ar.exception == null && ar.result != null) |
| 1265 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1266 | synchronized (request) { |
| 1267 | request.notifyAll(); |
| 1268 | } |
| 1269 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1270 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1271 | request = (MainThreadRequest) msg.obj; |
| 1272 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1273 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1274 | break; |
| 1275 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1276 | ar = (AsyncResult) msg.obj; |
| 1277 | request = (MainThreadRequest) ar.userObj; |
| 1278 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1279 | try { |
| 1280 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1281 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1282 | cb.onError( |
| 1283 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1284 | ar.exception.getClass().getName(), |
| 1285 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1286 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1287 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1288 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1289 | } else { |
| 1290 | // use the result as returned |
| 1291 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1292 | } |
| 1293 | } catch (RemoteException re) { |
| 1294 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1295 | } |
| 1296 | break; |
| 1297 | case CMD_GET_CELL_LOCATION: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1298 | request = (MainThreadRequest) msg.obj; |
| 1299 | WorkSource ws = (WorkSource) request.argument; |
| 1300 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1301 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1302 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1303 | case EVENT_GET_CELL_LOCATION_DONE: |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1304 | ar = (AsyncResult) msg.obj; |
| 1305 | request = (MainThreadRequest) ar.userObj; |
| 1306 | if (ar.exception == null) { |
| 1307 | request.result = ar.result; |
| 1308 | } else { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1309 | phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1310 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1311 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1312 | } |
| 1313 | |
| 1314 | synchronized (request) { |
| 1315 | request.notifyAll(); |
| 1316 | } |
| 1317 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1318 | case CMD_MODEM_REBOOT: |
| 1319 | request = (MainThreadRequest) msg.obj; |
| 1320 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1321 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1322 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1323 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1324 | handleNullReturnEvent(msg, "rebootModem"); |
| 1325 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1326 | case CMD_REQUEST_ENABLE_MODEM: |
| 1327 | request = (MainThreadRequest) msg.obj; |
| 1328 | boolean enable = (boolean) request.argument; |
| 1329 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1330 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1331 | PhoneConfigurationManager.getInstance() |
| 1332 | .enablePhone(request.phone, enable, onCompleted); |
| 1333 | break; |
| 1334 | case EVENT_ENABLE_MODEM_DONE: |
| 1335 | ar = (AsyncResult) msg.obj; |
| 1336 | request = (MainThreadRequest) ar.userObj; |
| 1337 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1338 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1339 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1340 | if ((boolean) request.result) { |
| 1341 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1342 | updateModemStateMetrics(); |
| 1343 | } else { |
| 1344 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1345 | + ar.exception); |
| 1346 | } |
| 1347 | notifyRequester(request); |
| 1348 | break; |
| 1349 | case CMD_GET_MODEM_STATUS: |
| 1350 | request = (MainThreadRequest) msg.obj; |
| 1351 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1352 | PhoneConfigurationManager.getInstance() |
| 1353 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1354 | break; |
| 1355 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1356 | ar = (AsyncResult) msg.obj; |
| 1357 | request = (MainThreadRequest) ar.userObj; |
| 1358 | int id = request.phone.getPhoneId(); |
| 1359 | if (ar.exception == null && ar.result != null) { |
| 1360 | request.result = ar.result; |
| 1361 | //update the cache as modem status has changed |
| 1362 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1363 | (boolean) request.result); |
| 1364 | } else { |
| 1365 | // Return true if modem status cannot be retrieved. For most cases, |
| 1366 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1367 | // and disable modem are not supported. Modem is always on. |
| 1368 | // TODO: this should be fixed in R to support a third |
| 1369 | // status UNKNOWN b/131631629 |
| 1370 | request.result = true; |
| 1371 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1372 | + ar.exception); |
| 1373 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1374 | notifyRequester(request); |
| 1375 | break; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1376 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1377 | request = (MainThreadRequest) msg.obj; |
| 1378 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1379 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1380 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1381 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1382 | break; |
| 1383 | } |
| 1384 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1385 | ar = (AsyncResult) msg.obj; |
| 1386 | request = (MainThreadRequest) ar.userObj; |
| 1387 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1388 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1389 | args.second.accept(ar.exception == null); |
| 1390 | notifyRequester(request); |
| 1391 | break; |
| 1392 | } |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1393 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1394 | ar = (AsyncResult) msg.obj; |
| 1395 | request = (MainThreadRequest) ar.userObj; |
| 1396 | if (ar.exception == null && ar.result != null) { |
| 1397 | request.result = ar.result; |
| 1398 | } else { |
| 1399 | request.result = -1; |
| 1400 | loge("Failed to set Forbidden Plmns"); |
| 1401 | if (ar.result == null) { |
| 1402 | loge("setForbidenPlmns: Empty response"); |
| 1403 | } else if (ar.exception != null) { |
| 1404 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1405 | request.result = -1; |
| 1406 | } else { |
| 1407 | loge("setForbiddenPlmns: Unknown exception"); |
| 1408 | } |
| 1409 | } |
| 1410 | notifyRequester(request); |
| 1411 | break; |
| 1412 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1413 | request = (MainThreadRequest) msg.obj; |
| 1414 | uiccCard = getUiccCardFromRequest(request); |
| 1415 | if (uiccCard == null) { |
| 1416 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1417 | request.result = -1; |
| 1418 | notifyRequester(request); |
| 1419 | break; |
| 1420 | } |
| 1421 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1422 | (Pair<Integer, List<String>>) request.argument; |
| 1423 | appType = setFplmnsArgs.first; |
| 1424 | List<String> fplmns = setFplmnsArgs.second; |
| 1425 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1426 | if (uiccApp == null) { |
| 1427 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1428 | request.result = -1; |
| 1429 | loge("Failed to get UICC App"); |
| 1430 | notifyRequester(request); |
| 1431 | } else { |
| 1432 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1433 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1434 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1435 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1436 | break; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1437 | case CMD_ERASE_MODEM_CONFIG: |
| 1438 | request = (MainThreadRequest) msg.obj; |
| 1439 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1440 | defaultPhone.eraseModemConfig(onCompleted); |
| 1441 | break; |
| 1442 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1443 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1444 | break; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1445 | |
| 1446 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1447 | request = (MainThreadRequest) msg.obj; |
| 1448 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1449 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1450 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1451 | changed.first, changed.second, onCompleted); |
| 1452 | break; |
| 1453 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1454 | ar = (AsyncResult) msg.obj; |
| 1455 | request = (MainThreadRequest) ar.userObj; |
| 1456 | if (ar.exception == null) { |
| 1457 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1458 | } else { |
| 1459 | request.result = msg.arg1; |
| 1460 | } |
| 1461 | notifyRequester(request); |
| 1462 | break; |
| 1463 | |
| 1464 | case CMD_SET_ICC_LOCK_ENABLED: |
| 1465 | request = (MainThreadRequest) msg.obj; |
| 1466 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1467 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1468 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1469 | enabled.first, enabled.second, onCompleted); |
| 1470 | break; |
| 1471 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1472 | ar = (AsyncResult) msg.obj; |
| 1473 | request = (MainThreadRequest) ar.userObj; |
| 1474 | if (ar.exception == null) { |
| 1475 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1476 | } else { |
| 1477 | request.result = msg.arg1; |
| 1478 | } |
| 1479 | notifyRequester(request); |
| 1480 | break; |
| 1481 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1482 | default: |
| 1483 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1484 | break; |
| 1485 | } |
| 1486 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1487 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1488 | private void notifyRequester(MainThreadRequest request) { |
| 1489 | synchronized (request) { |
| 1490 | request.notifyAll(); |
| 1491 | } |
| 1492 | } |
| 1493 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1494 | private void handleNullReturnEvent(Message msg, String command) { |
| 1495 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1496 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1497 | if (ar.exception == null) { |
| 1498 | request.result = true; |
| 1499 | } else { |
| 1500 | request.result = false; |
| 1501 | if (ar.exception instanceof CommandException) { |
| 1502 | loge(command + ": CommandException: " + ar.exception); |
| 1503 | } else { |
| 1504 | loge(command + ": Unknown exception"); |
| 1505 | } |
| 1506 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1507 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1508 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1509 | } |
| 1510 | |
| 1511 | /** |
| 1512 | * Posts the specified command to be executed on the main thread, |
| 1513 | * waits for the request to complete, and returns the result. |
| 1514 | * @see #sendRequestAsync |
| 1515 | */ |
| 1516 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1517 | return sendRequest( |
| 1518 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | /** |
| 1522 | * Posts the specified command to be executed on the main thread, |
| 1523 | * waits for the request to complete, and returns the result. |
| 1524 | * @see #sendRequestAsync |
| 1525 | */ |
| 1526 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1527 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1528 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1529 | } |
| 1530 | |
| 1531 | /** |
| 1532 | * Posts the specified command to be executed on the main thread, |
| 1533 | * waits for the request to complete, and returns the result. |
| 1534 | * @see #sendRequestAsync |
| 1535 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1536 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1537 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1538 | } |
| 1539 | |
| 1540 | /** |
| 1541 | * Posts the specified command to be executed on the main thread, |
| 1542 | * waits for the request to complete, and returns the result. |
| 1543 | * @see #sendRequestAsync |
| 1544 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1545 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1546 | return sendRequest(command, argument, subId, null, workSource); |
| 1547 | } |
| 1548 | |
| 1549 | /** |
| 1550 | * Posts the specified command to be executed on the main thread, |
| 1551 | * waits for the request to complete, and returns the result. |
| 1552 | * @see #sendRequestAsync |
| 1553 | */ |
| 1554 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1555 | return sendRequest( |
| 1556 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1557 | } |
| 1558 | |
| 1559 | /** |
| 1560 | * Posts the specified command to be executed on the main thread, |
| 1561 | * waits for the request to complete, and returns the result. |
| 1562 | * @see #sendRequestAsync |
| 1563 | */ |
| 1564 | private Object sendRequest( |
| 1565 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1566 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1567 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1568 | } |
| 1569 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1570 | MainThreadRequest request = null; |
| 1571 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1572 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1573 | } else if (phone != null) { |
| 1574 | request = new MainThreadRequest(argument, phone, workSource); |
| 1575 | } else { |
| 1576 | request = new MainThreadRequest(argument, subId, workSource); |
| 1577 | } |
| 1578 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1579 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1580 | msg.sendToTarget(); |
| 1581 | |
| 1582 | // Wait for the request to complete |
| 1583 | synchronized (request) { |
| 1584 | while (request.result == null) { |
| 1585 | try { |
| 1586 | request.wait(); |
| 1587 | } catch (InterruptedException e) { |
| 1588 | // Do nothing, go back and wait until the request is complete |
| 1589 | } |
| 1590 | } |
| 1591 | } |
| 1592 | return request.result; |
| 1593 | } |
| 1594 | |
| 1595 | /** |
| 1596 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1597 | * Posts the specified command to be executed on the main thread, and |
| 1598 | * returns immediately. |
| 1599 | * @see #sendRequest |
| 1600 | */ |
| 1601 | private void sendRequestAsync(int command) { |
| 1602 | mMainThreadHandler.sendEmptyMessage(command); |
| 1603 | } |
| 1604 | |
| 1605 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1606 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1607 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1608 | */ |
| 1609 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1610 | sendRequestAsync(command, argument, null, null); |
| 1611 | } |
| 1612 | |
| 1613 | /** |
| 1614 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1615 | * @see {@link #sendRequest(int,Object)} |
| 1616 | */ |
| 1617 | private void sendRequestAsync( |
| 1618 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1619 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1620 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1621 | msg.sendToTarget(); |
| 1622 | } |
| 1623 | |
| 1624 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1625 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1626 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1627 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1628 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1629 | synchronized (PhoneInterfaceManager.class) { |
| 1630 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1631 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1632 | } else { |
| 1633 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1634 | } |
| 1635 | return sInstance; |
| 1636 | } |
| 1637 | } |
| 1638 | |
| 1639 | /** Private constructor; @see init() */ |
Jordan Liu | a39e6c1 | 2020-03-04 13:59:23 -0800 | [diff] [blame] | 1640 | @VisibleForTesting |
| 1641 | /* package */ PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1642 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1643 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1644 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1645 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1646 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1647 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1648 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1649 | mTelephonySharedPreferences = |
| 1650 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1651 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1652 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1653 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1654 | publish(); |
| 1655 | } |
| 1656 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1657 | private Phone getDefaultPhone() { |
| 1658 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1659 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1660 | } |
| 1661 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1662 | private void publish() { |
| 1663 | if (DBG) log("publish: " + this); |
| 1664 | |
| 1665 | ServiceManager.addService("phone", this); |
| 1666 | } |
| 1667 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1668 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1669 | if (request.phone != null) { |
| 1670 | return request.phone; |
| 1671 | } else { |
| 1672 | return getPhoneFromSubId(request.subId); |
| 1673 | } |
| 1674 | } |
| 1675 | |
| 1676 | private Phone getPhoneFromSubId(int subId) { |
| 1677 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1678 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1679 | } |
| 1680 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1681 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1682 | Phone phone = getPhoneFromRequest(request); |
| 1683 | return phone == null ? null : |
| 1684 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1685 | } |
| 1686 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1687 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1688 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1689 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1690 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1691 | |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1692 | private void sendEraseModemConfig(Phone phone) { |
| 1693 | if (phone != null) { |
| 1694 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 1695 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 1696 | final long identity = Binder.clearCallingIdentity(); |
| 1697 | try { |
| 1698 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 1699 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 1700 | } finally { |
| 1701 | Binder.restoreCallingIdentity(identity); |
| 1702 | } |
| 1703 | } |
| 1704 | } |
| 1705 | |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 1706 | private boolean isImsAvailableOnDevice() { |
| 1707 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 1708 | if (pm == null) { |
| 1709 | // For some reason package manger is not available.. This will fail internally anyway, |
| 1710 | // so do not throw error and allow. |
| 1711 | return true; |
| 1712 | } |
| 1713 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 1714 | } |
| 1715 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1716 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1717 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1718 | } |
| 1719 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1720 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1721 | if (DBG) log("dial: " + number); |
| 1722 | // No permission check needed here: This is just a wrapper around the |
| 1723 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1724 | // the UI before it does anything. |
| 1725 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1726 | final long identity = Binder.clearCallingIdentity(); |
| 1727 | try { |
| 1728 | String url = createTelUrl(number); |
| 1729 | if (url == null) { |
| 1730 | return; |
| 1731 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1732 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1733 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1734 | PhoneConstants.State state = mCM.getState(subId); |
| 1735 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1736 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1737 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1738 | mApp.startActivity(intent); |
| 1739 | } |
| 1740 | } finally { |
| 1741 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1742 | } |
| 1743 | } |
| 1744 | |
| 1745 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1746 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1747 | } |
| 1748 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1749 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1750 | if (DBG) log("call: " + number); |
| 1751 | |
| 1752 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1753 | // need to do a permission check since we're calling startActivity() |
| 1754 | // from the context of the phone app. |
| 1755 | enforceCallPermission(); |
| 1756 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 1757 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1758 | != AppOpsManager.MODE_ALLOWED) { |
| 1759 | return; |
| 1760 | } |
| 1761 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1762 | final long identity = Binder.clearCallingIdentity(); |
| 1763 | try { |
| 1764 | String url = createTelUrl(number); |
| 1765 | if (url == null) { |
| 1766 | return; |
| 1767 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1768 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1769 | boolean isValid = false; |
| 1770 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1771 | if (slist != null) { |
| 1772 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1773 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1774 | isValid = true; |
| 1775 | break; |
| 1776 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1777 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1778 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1779 | if (!isValid) { |
| 1780 | return; |
| 1781 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1782 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1783 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1784 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1785 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1786 | mApp.startActivity(intent); |
| 1787 | } finally { |
| 1788 | Binder.restoreCallingIdentity(identity); |
| 1789 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1790 | } |
| 1791 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1792 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1793 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1794 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1795 | } |
| 1796 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1797 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1798 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1799 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1800 | } |
| 1801 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1802 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1803 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1804 | |
| 1805 | final long identity = Binder.clearCallingIdentity(); |
| 1806 | try { |
| 1807 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 1808 | checkSimPin.start(); |
| 1809 | return checkSimPin.unlockSim(null, pin); |
| 1810 | } finally { |
| 1811 | Binder.restoreCallingIdentity(identity); |
| 1812 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1813 | } |
| 1814 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1815 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1816 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1817 | |
| 1818 | final long identity = Binder.clearCallingIdentity(); |
| 1819 | try { |
| 1820 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 1821 | checkSimPuk.start(); |
| 1822 | return checkSimPuk.unlockSim(puk, pin); |
| 1823 | } finally { |
| 1824 | Binder.restoreCallingIdentity(identity); |
| 1825 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1826 | } |
| 1827 | |
| 1828 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1829 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1830 | * a synchronous one. |
| 1831 | */ |
| 1832 | private static class UnlockSim extends Thread { |
| 1833 | |
| 1834 | private final IccCard mSimCard; |
| 1835 | |
| 1836 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1837 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1838 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1839 | |
| 1840 | // For replies from SimCard interface |
| 1841 | private Handler mHandler; |
| 1842 | |
| 1843 | // For async handler to identify request type |
| 1844 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 1845 | |
| 1846 | public UnlockSim(IccCard simCard) { |
| 1847 | mSimCard = simCard; |
| 1848 | } |
| 1849 | |
| 1850 | @Override |
| 1851 | public void run() { |
| 1852 | Looper.prepare(); |
| 1853 | synchronized (UnlockSim.this) { |
| 1854 | mHandler = new Handler() { |
| 1855 | @Override |
| 1856 | public void handleMessage(Message msg) { |
| 1857 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1858 | switch (msg.what) { |
| 1859 | case SUPPLY_PIN_COMPLETE: |
| 1860 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 1861 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1862 | mRetryCount = msg.arg1; |
| 1863 | if (ar.exception != null) { |
| 1864 | if (ar.exception instanceof CommandException && |
| 1865 | ((CommandException)(ar.exception)).getCommandError() |
| 1866 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 1867 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 1868 | } //When UiccCardApp dispose,handle message and return exception |
| 1869 | else if (ar.exception instanceof CommandException && |
| 1870 | ((CommandException) (ar.exception)).getCommandError() |
| 1871 | == CommandException.Error.ABORTED) { |
| 1872 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1873 | } else { |
| 1874 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 1875 | } |
| 1876 | } else { |
| 1877 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 1878 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1879 | mDone = true; |
| 1880 | UnlockSim.this.notifyAll(); |
| 1881 | } |
| 1882 | break; |
| 1883 | } |
| 1884 | } |
| 1885 | }; |
| 1886 | UnlockSim.this.notifyAll(); |
| 1887 | } |
| 1888 | Looper.loop(); |
| 1889 | } |
| 1890 | |
| 1891 | /* |
| 1892 | * Use PIN or PUK to unlock SIM card |
| 1893 | * |
| 1894 | * If PUK is null, unlock SIM card with PIN |
| 1895 | * |
| 1896 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 1897 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1898 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1899 | |
| 1900 | while (mHandler == null) { |
| 1901 | try { |
| 1902 | wait(); |
| 1903 | } catch (InterruptedException e) { |
| 1904 | Thread.currentThread().interrupt(); |
| 1905 | } |
| 1906 | } |
| 1907 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 1908 | |
| 1909 | if (puk == null) { |
| 1910 | mSimCard.supplyPin(pin, callback); |
| 1911 | } else { |
| 1912 | mSimCard.supplyPuk(puk, pin, callback); |
| 1913 | } |
| 1914 | |
| 1915 | while (!mDone) { |
| 1916 | try { |
| 1917 | Log.d(LOG_TAG, "wait for done"); |
| 1918 | wait(); |
| 1919 | } catch (InterruptedException e) { |
| 1920 | // Restore the interrupted status |
| 1921 | Thread.currentThread().interrupt(); |
| 1922 | } |
| 1923 | } |
| 1924 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1925 | int[] resultArray = new int[2]; |
| 1926 | resultArray[0] = mResult; |
| 1927 | resultArray[1] = mRetryCount; |
| 1928 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1929 | } |
| 1930 | } |
| 1931 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame^] | 1932 | /** |
| 1933 | * This method has been removed due to privacy and stability concerns. |
| 1934 | */ |
| 1935 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1936 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame^] | 1937 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 1938 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1939 | } |
| 1940 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 1941 | @Override |
| 1942 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 1943 | mApp.getSystemService(AppOpsManager.class) |
| 1944 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 1945 | |
| 1946 | final int targetSdk = getTargetSdk(callingPackage); |
| 1947 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 1948 | // Callers targeting S have no business invoking this method. |
| 1949 | return; |
| 1950 | } |
| 1951 | |
| 1952 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 1953 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 1954 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 1955 | .setCallingPackage(callingPackage) |
| 1956 | .setCallingFeatureId(null) |
| 1957 | .setCallingPid(Binder.getCallingPid()) |
| 1958 | .setCallingUid(Binder.getCallingUid()) |
| 1959 | .setMethod("updateServiceLocation") |
| 1960 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 1961 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 1962 | .build()); |
| 1963 | // Apps that lack location permission have no business calling this method; |
| 1964 | // however, because no permission was declared in the public API, denials must |
| 1965 | // all be "soft". |
| 1966 | switch (locationResult) { |
| 1967 | case DENIED_HARD: /* fall through */ |
| 1968 | case DENIED_SOFT: |
| 1969 | return; |
| 1970 | } |
| 1971 | |
| 1972 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 1973 | final long identity = Binder.clearCallingIdentity(); |
| 1974 | try { |
| 1975 | final Phone phone = getPhone(getDefaultSubscription()); |
| 1976 | if (phone != null) { |
| 1977 | phone.updateServiceLocation(workSource); |
| 1978 | } |
| 1979 | } finally { |
| 1980 | Binder.restoreCallingIdentity(identity); |
| 1981 | } |
| 1982 | } |
| 1983 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1984 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1985 | @Override |
| 1986 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1987 | return isRadioOnWithFeature(callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1988 | } |
| 1989 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1990 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1991 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 1992 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 1993 | callingFeatureId); |
| 1994 | } |
| 1995 | |
| 1996 | @Deprecated |
| 1997 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1998 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1999 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
| 2000 | } |
| 2001 | |
| 2002 | @Override |
| 2003 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2004 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2005 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2006 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2007 | return false; |
| 2008 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2009 | |
| 2010 | final long identity = Binder.clearCallingIdentity(); |
| 2011 | try { |
| 2012 | return isRadioOnForSubscriber(subId); |
| 2013 | } finally { |
| 2014 | Binder.restoreCallingIdentity(identity); |
| 2015 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2019 | final long identity = Binder.clearCallingIdentity(); |
| 2020 | try { |
| 2021 | final Phone phone = getPhone(subId); |
| 2022 | if (phone != null) { |
| 2023 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2024 | } else { |
| 2025 | return false; |
| 2026 | } |
| 2027 | } finally { |
| 2028 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2029 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2030 | } |
| 2031 | |
| 2032 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2033 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2034 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2035 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2036 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2037 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2038 | |
| 2039 | final long identity = Binder.clearCallingIdentity(); |
| 2040 | try { |
| 2041 | final Phone phone = getPhone(subId); |
| 2042 | if (phone != null) { |
| 2043 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2044 | } |
| 2045 | } finally { |
| 2046 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2047 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2048 | } |
| 2049 | |
| 2050 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2051 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2052 | } |
| 2053 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2054 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2055 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2056 | |
| 2057 | final long identity = Binder.clearCallingIdentity(); |
| 2058 | try { |
| 2059 | final Phone phone = getPhone(subId); |
| 2060 | if (phone == null) { |
| 2061 | return false; |
| 2062 | } |
| 2063 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2064 | toggleRadioOnOffForSubscriber(subId); |
| 2065 | } |
| 2066 | return true; |
| 2067 | } finally { |
| 2068 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2069 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2070 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2071 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2072 | public boolean needMobileRadioShutdown() { |
Shuo Qian | afeaf7d | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2073 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2074 | /* |
| 2075 | * If any of the Radios are available, it will need to be |
| 2076 | * shutdown. So return true if any Radio is available. |
| 2077 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2078 | final long identity = Binder.clearCallingIdentity(); |
| 2079 | try { |
| 2080 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2081 | Phone phone = PhoneFactory.getPhone(i); |
| 2082 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2083 | } |
| 2084 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2085 | return false; |
| 2086 | } finally { |
| 2087 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2088 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2089 | } |
| 2090 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2091 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2092 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2093 | enforceModifyPermission(); |
| 2094 | |
| 2095 | final long identity = Binder.clearCallingIdentity(); |
| 2096 | try { |
| 2097 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2098 | logv("Shutting down Phone " + i); |
| 2099 | shutdownRadioUsingPhoneId(i); |
| 2100 | } |
| 2101 | } finally { |
| 2102 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2103 | } |
| 2104 | } |
| 2105 | |
| 2106 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2107 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2108 | if (phone != null && phone.isRadioAvailable()) { |
| 2109 | phone.shutdownRadio(); |
| 2110 | } |
| 2111 | } |
| 2112 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2113 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2114 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2115 | |
| 2116 | final long identity = Binder.clearCallingIdentity(); |
| 2117 | try { |
| 2118 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2119 | if (defaultPhone != null) { |
| 2120 | defaultPhone.setRadioPower(turnOn); |
| 2121 | return true; |
| 2122 | } else { |
| 2123 | loge("There's no default phone."); |
| 2124 | return false; |
| 2125 | } |
| 2126 | } finally { |
| 2127 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2128 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2129 | } |
| 2130 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2131 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2132 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2133 | |
| 2134 | final long identity = Binder.clearCallingIdentity(); |
| 2135 | try { |
| 2136 | final Phone phone = getPhone(subId); |
| 2137 | if (phone != null) { |
| 2138 | phone.setRadioPower(turnOn); |
| 2139 | return true; |
| 2140 | } else { |
| 2141 | return false; |
| 2142 | } |
| 2143 | } finally { |
| 2144 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2145 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2146 | } |
| 2147 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2148 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2149 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2150 | public boolean enableDataConnectivity() { |
| 2151 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2152 | |
| 2153 | final long identity = Binder.clearCallingIdentity(); |
| 2154 | try { |
| 2155 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2156 | final Phone phone = getPhone(subId); |
| 2157 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 2158 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2159 | return true; |
| 2160 | } else { |
| 2161 | return false; |
| 2162 | } |
| 2163 | } finally { |
| 2164 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2165 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2166 | } |
| 2167 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2168 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2169 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2170 | public boolean disableDataConnectivity() { |
| 2171 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2172 | |
| 2173 | final long identity = Binder.clearCallingIdentity(); |
| 2174 | try { |
| 2175 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2176 | final Phone phone = getPhone(subId); |
| 2177 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 2178 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2179 | return true; |
| 2180 | } else { |
| 2181 | return false; |
| 2182 | } |
| 2183 | } finally { |
| 2184 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2185 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2186 | } |
| 2187 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2188 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2189 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2190 | final long identity = Binder.clearCallingIdentity(); |
| 2191 | try { |
| 2192 | final Phone phone = getPhone(subId); |
| 2193 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2194 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2195 | } else { |
| 2196 | return false; |
| 2197 | } |
| 2198 | } finally { |
| 2199 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2200 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2201 | } |
| 2202 | |
| 2203 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2204 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2205 | } |
| 2206 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2207 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2208 | enforceCallPermission(); |
| 2209 | |
| 2210 | final long identity = Binder.clearCallingIdentity(); |
| 2211 | try { |
| 2212 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2213 | return; |
| 2214 | } |
| 2215 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2216 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2217 | } finally { |
| 2218 | Binder.restoreCallingIdentity(identity); |
| 2219 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2220 | }; |
| 2221 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2222 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2223 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2224 | |
| 2225 | final long identity = Binder.clearCallingIdentity(); |
| 2226 | try { |
| 2227 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2228 | return false; |
| 2229 | } |
| 2230 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2231 | } finally { |
| 2232 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2233 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2234 | } |
| 2235 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2236 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2237 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2238 | } |
| 2239 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2240 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2241 | final long identity = Binder.clearCallingIdentity(); |
| 2242 | try { |
| 2243 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2244 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2245 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2246 | } finally { |
| 2247 | Binder.restoreCallingIdentity(identity); |
| 2248 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2249 | } |
| 2250 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2251 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2252 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2253 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2254 | } |
| 2255 | |
| 2256 | @Override |
| 2257 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2258 | final long identity = Binder.clearCallingIdentity(); |
| 2259 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2260 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2261 | if (phone != null) { |
| 2262 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2263 | } else { |
| 2264 | return PhoneConstantConversions.convertDataState( |
| 2265 | PhoneConstants.DataState.DISCONNECTED); |
| 2266 | } |
| 2267 | } finally { |
| 2268 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2269 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2270 | } |
| 2271 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2272 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2273 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2274 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2275 | } |
| 2276 | |
| 2277 | @Override |
| 2278 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2279 | final long identity = Binder.clearCallingIdentity(); |
| 2280 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2281 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2282 | if (phone != null) { |
| 2283 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2284 | } else { |
| 2285 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2286 | } |
| 2287 | } finally { |
| 2288 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2289 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2290 | } |
| 2291 | |
| 2292 | @Override |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2293 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2294 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2295 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2296 | |
| 2297 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2298 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2299 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2300 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2301 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2302 | .setCallingPid(Binder.getCallingPid()) |
| 2303 | .setCallingUid(Binder.getCallingUid()) |
| 2304 | .setMethod("getCellLocation") |
Hall Liu | c3f8eb6 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2305 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2306 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2307 | .build()); |
| 2308 | switch (locationResult) { |
| 2309 | case DENIED_HARD: |
| 2310 | throw new SecurityException("Not allowed to access cell location"); |
| 2311 | case DENIED_SOFT: |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2312 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2313 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2314 | } |
| 2315 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2316 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2317 | final long identity = Binder.clearCallingIdentity(); |
| 2318 | try { |
| 2319 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2320 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2321 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2322 | } finally { |
| 2323 | Binder.restoreCallingIdentity(identity); |
| 2324 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2325 | } |
| 2326 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2327 | @Override |
Jack Yu | 0142503 | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2328 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2329 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2330 | // registered cell info, so return a NULL country instead. |
| 2331 | final long identity = Binder.clearCallingIdentity(); |
| 2332 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2333 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2334 | // Get default phone in this case. |
| 2335 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2336 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2337 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2338 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | cf38ed9 | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2339 | if (phone == null) return ""; |
| 2340 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2341 | if (sst == null) return ""; |
| 2342 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2343 | if (lt == null) return ""; |
| 2344 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry(); |
| 2345 | EmergencyNumberTracker ent = phone.getEmergencyNumberTracker(); |
| 2346 | return (ent == null) ? "" : ent.getEmergencyCountryIso(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2347 | } finally { |
| 2348 | Binder.restoreCallingIdentity(identity); |
| 2349 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2350 | } |
| 2351 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame^] | 2352 | /** |
| 2353 | * This method was removed due to potential issues caused by performing partial |
| 2354 | * updates of service state, and lack of a credible use case. |
| 2355 | * |
| 2356 | * This has the ability to break the telephony implementation by disabling notification of |
| 2357 | * changes in device connectivity. DO NOT USE THIS! |
| 2358 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2359 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2360 | public void enableLocationUpdates() { |
| 2361 | mApp.enforceCallingOrSelfPermission( |
| 2362 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2363 | } |
| 2364 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame^] | 2365 | /** |
| 2366 | * This method was removed due to potential issues caused by performing partial |
| 2367 | * updates of service state, and lack of a credible use case. |
| 2368 | * |
| 2369 | * This has the ability to break the telephony implementation by disabling notification of |
| 2370 | * changes in device connectivity. DO NOT USE THIS! |
| 2371 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2372 | @Override |
| 2373 | public void disableLocationUpdates() { |
| 2374 | mApp.enforceCallingOrSelfPermission( |
| 2375 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2376 | } |
| 2377 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2378 | /** |
| 2379 | * Returns the target SDK version number for a given package name. |
| 2380 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2381 | * This call MUST be invoked before clearing the calling UID. |
| 2382 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2383 | * @return target SDK if the package is found or INT_MAX. |
| 2384 | */ |
| 2385 | private int getTargetSdk(String packageName) { |
| 2386 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2387 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 54d2030 | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2388 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2389 | if (ai != null) return ai.targetSdkVersion; |
| 2390 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2391 | loge("Failed to get package info for pkg=" |
| 2392 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2393 | } |
| 2394 | return Integer.MAX_VALUE; |
| 2395 | } |
| 2396 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2397 | @Override |
| 2398 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2399 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2400 | String callingFeatureId) { |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2401 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2402 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2403 | throw new SecurityException( |
| 2404 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2405 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2406 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2407 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2408 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2409 | return null; |
| 2410 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2411 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2412 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2413 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2414 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2415 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2416 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2417 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2418 | for (CellInfo ci : info) { |
| 2419 | if (ci instanceof CellInfoGsm) { |
| 2420 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2421 | } else if (ci instanceof CellInfoWcdma) { |
| 2422 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2423 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2424 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2425 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2426 | } |
| 2427 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2428 | private List<CellInfo> getCachedCellInfo() { |
| 2429 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2430 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2431 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2432 | if (info != null) cellInfos.addAll(info); |
| 2433 | } |
| 2434 | return cellInfos; |
| 2435 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2436 | |
| 2437 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2438 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2439 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2440 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2441 | |
| 2442 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2443 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2444 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2445 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2446 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2447 | .setCallingPid(Binder.getCallingPid()) |
| 2448 | .setCallingUid(Binder.getCallingUid()) |
| 2449 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2450 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2451 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2452 | .build()); |
| 2453 | switch (locationResult) { |
| 2454 | case DENIED_HARD: |
| 2455 | throw new SecurityException("Not allowed to access cell info"); |
| 2456 | case DENIED_SOFT: |
| 2457 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2458 | } |
| 2459 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2460 | final int targetSdk = getTargetSdk(callingPackage); |
| 2461 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2462 | return getCachedCellInfo(); |
| 2463 | } |
| 2464 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2465 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2466 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2467 | final long identity = Binder.clearCallingIdentity(); |
| 2468 | try { |
| 2469 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2470 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2471 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2472 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2473 | if (info != null) cellInfos.addAll(info); |
| 2474 | } |
| 2475 | return cellInfos; |
| 2476 | } finally { |
| 2477 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2478 | } |
| 2479 | } |
| 2480 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2481 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2482 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2483 | String callingFeatureId) { |
| 2484 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2485 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2486 | } |
| 2487 | |
| 2488 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2489 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2490 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2491 | enforceModifyPermission(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2492 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2493 | } |
| 2494 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2495 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2496 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2497 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2498 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2499 | |
| 2500 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2501 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2502 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2503 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2504 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2505 | .setCallingPid(Binder.getCallingPid()) |
| 2506 | .setCallingUid(Binder.getCallingUid()) |
| 2507 | .setMethod("requestCellInfoUpdate") |
| 2508 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2509 | .build()); |
| 2510 | switch (locationResult) { |
| 2511 | case DENIED_HARD: |
| 2512 | throw new SecurityException("Not allowed to access cell info"); |
| 2513 | case DENIED_SOFT: |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2514 | try { |
| 2515 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2516 | } catch (RemoteException re) { |
| 2517 | // Drop without consequences |
| 2518 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2519 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2520 | } |
| 2521 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2522 | |
| 2523 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2524 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2525 | |
| 2526 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2527 | } |
| 2528 | |
| 2529 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2530 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2531 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2532 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2533 | |
| 2534 | final long identity = Binder.clearCallingIdentity(); |
| 2535 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2536 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2537 | } finally { |
| 2538 | Binder.restoreCallingIdentity(identity); |
| 2539 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2540 | } |
| 2541 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2542 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2543 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2544 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2545 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2546 | return null; |
| 2547 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2548 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2549 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2550 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2551 | return null; |
| 2552 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2553 | |
| 2554 | final long identity = Binder.clearCallingIdentity(); |
| 2555 | try { |
| 2556 | return phone.getImei(); |
| 2557 | } finally { |
| 2558 | Binder.restoreCallingIdentity(identity); |
| 2559 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2560 | } |
| 2561 | |
| 2562 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2563 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2564 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2565 | String tac = null; |
| 2566 | if (phone != null) { |
| 2567 | String imei = phone.getImei(); |
| 2568 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2569 | } |
| 2570 | return tac; |
| 2571 | } |
| 2572 | |
| 2573 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2574 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2575 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2576 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2577 | return null; |
| 2578 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2579 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2580 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2581 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2582 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2583 | return null; |
| 2584 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2585 | |
| 2586 | final long identity = Binder.clearCallingIdentity(); |
| 2587 | try { |
| 2588 | return phone.getMeid(); |
| 2589 | } finally { |
| 2590 | Binder.restoreCallingIdentity(identity); |
| 2591 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2592 | } |
| 2593 | |
| 2594 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2595 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2596 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2597 | String manufacturerCode = null; |
| 2598 | if (phone != null) { |
| 2599 | String meid = phone.getMeid(); |
| 2600 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2601 | } |
| 2602 | return manufacturerCode; |
| 2603 | } |
| 2604 | |
| 2605 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2606 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2607 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2608 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2609 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2610 | return null; |
| 2611 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2612 | int subId = phone.getSubId(); |
| 2613 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2614 | mApp, subId, callingPackage, callingFeatureId, |
| 2615 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2616 | return null; |
| 2617 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2618 | |
| 2619 | final long identity = Binder.clearCallingIdentity(); |
| 2620 | try { |
| 2621 | return phone.getDeviceSvn(); |
| 2622 | } finally { |
| 2623 | Binder.restoreCallingIdentity(identity); |
| 2624 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2625 | } |
| 2626 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2627 | @Override |
| 2628 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2629 | final long identity = Binder.clearCallingIdentity(); |
| 2630 | try { |
| 2631 | final Phone phone = getPhone(subId); |
| 2632 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2633 | } finally { |
| 2634 | Binder.restoreCallingIdentity(identity); |
| 2635 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2636 | } |
| 2637 | |
| 2638 | @Override |
| 2639 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2640 | final long identity = Binder.clearCallingIdentity(); |
| 2641 | try { |
| 2642 | final Phone phone = getPhone(subId); |
| 2643 | return phone == null ? null : phone.getCarrierName(); |
| 2644 | } finally { |
| 2645 | Binder.restoreCallingIdentity(identity); |
| 2646 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2647 | } |
| 2648 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2649 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2650 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2651 | final long identity = Binder.clearCallingIdentity(); |
| 2652 | try { |
| 2653 | final Phone phone = getPhone(subId); |
| 2654 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2655 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2656 | } finally { |
| 2657 | Binder.restoreCallingIdentity(identity); |
| 2658 | } |
| 2659 | } |
| 2660 | |
| 2661 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2662 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2663 | final long identity = Binder.clearCallingIdentity(); |
| 2664 | try { |
| 2665 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2666 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2667 | } finally { |
| 2668 | Binder.restoreCallingIdentity(identity); |
| 2669 | } |
| 2670 | } |
| 2671 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2672 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2673 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2674 | if (!isSubscriptionMccMnc) { |
| 2675 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2676 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2677 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2678 | if (phone == null) { |
| 2679 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2680 | } |
| 2681 | final long identity = Binder.clearCallingIdentity(); |
| 2682 | try { |
| 2683 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2684 | } finally { |
| 2685 | Binder.restoreCallingIdentity(identity); |
| 2686 | } |
| 2687 | } |
| 2688 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2689 | // |
| 2690 | // Internal helper methods. |
| 2691 | // |
| 2692 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2693 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2694 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2695 | * |
| 2696 | * @throws SecurityException if the caller does not have the required permission |
| 2697 | */ |
| 2698 | private void enforceModifyPermission() { |
| 2699 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2700 | } |
| 2701 | |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 2702 | /** |
| 2703 | * Make sure the caller is system. |
| 2704 | * |
| 2705 | * @throws SecurityException if the caller is not system. |
| 2706 | */ |
| 2707 | private void enforceSystemCaller() { |
| 2708 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 2709 | throw new SecurityException("Caller must be system"); |
| 2710 | } |
| 2711 | } |
| 2712 | |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 2713 | private void enforceActiveEmergencySessionPermission() { |
| 2714 | mApp.enforceCallingOrSelfPermission( |
| 2715 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 2716 | } |
| 2717 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2718 | /** |
| 2719 | * Make sure the caller has the CALL_PHONE permission. |
| 2720 | * |
| 2721 | * @throws SecurityException if the caller does not have the required permission |
| 2722 | */ |
| 2723 | private void enforceCallPermission() { |
| 2724 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2725 | } |
| 2726 | |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 2727 | private void enforceSettingsPermission() { |
| 2728 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2729 | } |
| 2730 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2731 | private String createTelUrl(String number) { |
| 2732 | if (TextUtils.isEmpty(number)) { |
| 2733 | return null; |
| 2734 | } |
| 2735 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2736 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2737 | } |
| 2738 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2739 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2740 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2741 | } |
| 2742 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2743 | private static void logv(String msg) { |
| 2744 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2745 | } |
| 2746 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2747 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2748 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2749 | } |
| 2750 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2751 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2752 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2753 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2754 | } |
| 2755 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2756 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2757 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2758 | final long identity = Binder.clearCallingIdentity(); |
| 2759 | try { |
| 2760 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2761 | if (phone == null) { |
| 2762 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2763 | } else { |
| 2764 | return phone.getPhoneType(); |
| 2765 | } |
| 2766 | } finally { |
| 2767 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2768 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2769 | } |
| 2770 | |
| 2771 | /** |
| 2772 | * Returns the CDMA ERI icon index to display |
| 2773 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2774 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2775 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 2776 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 2777 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2778 | } |
| 2779 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2780 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2781 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 2782 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2783 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2784 | mApp, subId, callingPackage, callingFeatureId, |
| 2785 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2786 | return -1; |
| 2787 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2788 | |
| 2789 | final long identity = Binder.clearCallingIdentity(); |
| 2790 | try { |
| 2791 | final Phone phone = getPhone(subId); |
| 2792 | if (phone != null) { |
| 2793 | return phone.getCdmaEriIconIndex(); |
| 2794 | } else { |
| 2795 | return -1; |
| 2796 | } |
| 2797 | } finally { |
| 2798 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2799 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2800 | } |
| 2801 | |
| 2802 | /** |
| 2803 | * Returns the CDMA ERI icon mode, |
| 2804 | * 0 - ON |
| 2805 | * 1 - FLASHING |
| 2806 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2807 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2808 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 2809 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 2810 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2811 | } |
| 2812 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2813 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2814 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 2815 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2816 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2817 | mApp, subId, callingPackage, callingFeatureId, |
| 2818 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2819 | return -1; |
| 2820 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2821 | |
| 2822 | final long identity = Binder.clearCallingIdentity(); |
| 2823 | try { |
| 2824 | final Phone phone = getPhone(subId); |
| 2825 | if (phone != null) { |
| 2826 | return phone.getCdmaEriIconMode(); |
| 2827 | } else { |
| 2828 | return -1; |
| 2829 | } |
| 2830 | } finally { |
| 2831 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2832 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2833 | } |
| 2834 | |
| 2835 | /** |
| 2836 | * Returns the CDMA ERI text, |
| 2837 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2838 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2839 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 2840 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 2841 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2842 | } |
| 2843 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2844 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2845 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 2846 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2847 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2848 | mApp, subId, callingPackage, callingFeatureId, |
| 2849 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2850 | return null; |
| 2851 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2852 | |
| 2853 | final long identity = Binder.clearCallingIdentity(); |
| 2854 | try { |
| 2855 | final Phone phone = getPhone(subId); |
| 2856 | if (phone != null) { |
| 2857 | return phone.getCdmaEriText(); |
| 2858 | } else { |
| 2859 | return null; |
| 2860 | } |
| 2861 | } finally { |
| 2862 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2863 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2864 | } |
| 2865 | |
| 2866 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2867 | * Returns the CDMA MDN. |
| 2868 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2869 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2870 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2871 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2872 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2873 | |
| 2874 | final long identity = Binder.clearCallingIdentity(); |
| 2875 | try { |
| 2876 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2877 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2878 | return phone.getLine1Number(); |
| 2879 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2880 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2881 | return null; |
| 2882 | } |
| 2883 | } finally { |
| 2884 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2885 | } |
| 2886 | } |
| 2887 | |
| 2888 | /** |
| 2889 | * Returns the CDMA MIN. |
| 2890 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2891 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2892 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2893 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2894 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2895 | |
| 2896 | final long identity = Binder.clearCallingIdentity(); |
| 2897 | try { |
| 2898 | final Phone phone = getPhone(subId); |
| 2899 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2900 | return phone.getCdmaMin(); |
| 2901 | } else { |
| 2902 | return null; |
| 2903 | } |
| 2904 | } finally { |
| 2905 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2906 | } |
| 2907 | } |
| 2908 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2909 | @Override |
| 2910 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2911 | INumberVerificationCallback callback, String callingPackage) { |
| 2912 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2913 | != PERMISSION_GRANTED) { |
| 2914 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2915 | } |
| 2916 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2917 | |
| 2918 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2919 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2920 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2921 | } |
| 2922 | |
| 2923 | if (range == null) { |
| 2924 | throw new NullPointerException("Range must be non-null"); |
| 2925 | } |
| 2926 | |
| 2927 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2928 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2929 | |
| 2930 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2931 | } |
| 2932 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2933 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2934 | * Returns true if CDMA provisioning needs to run. |
| 2935 | */ |
| 2936 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2937 | final long identity = Binder.clearCallingIdentity(); |
| 2938 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2939 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2940 | } finally { |
| 2941 | Binder.restoreCallingIdentity(identity); |
| 2942 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2943 | } |
| 2944 | |
| 2945 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2946 | * Sets the voice mail number of a given subId. |
| 2947 | */ |
| 2948 | @Override |
| 2949 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 2950 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2951 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2952 | |
| 2953 | final long identity = Binder.clearCallingIdentity(); |
| 2954 | try { |
| 2955 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2956 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2957 | return success; |
| 2958 | } finally { |
| 2959 | Binder.restoreCallingIdentity(identity); |
| 2960 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2961 | } |
| 2962 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2963 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2964 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2965 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 2966 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 2967 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2968 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2969 | throw new SecurityException("caller must be system dialer"); |
| 2970 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2971 | |
| 2972 | final long identity = Binder.clearCallingIdentity(); |
| 2973 | try { |
| 2974 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2975 | if (phoneAccountHandle == null) { |
| 2976 | return null; |
| 2977 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2978 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2979 | } finally { |
| 2980 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2981 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2982 | } |
| 2983 | |
| 2984 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2985 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 2986 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2987 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2988 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2989 | mApp, subId, callingPackage, callingFeatureId, |
| 2990 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2991 | return null; |
| 2992 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2993 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2994 | final long identity = Binder.clearCallingIdentity(); |
| 2995 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2996 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2997 | } finally { |
| 2998 | Binder.restoreCallingIdentity(identity); |
| 2999 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3000 | } |
| 3001 | |
| 3002 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3003 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3004 | VisualVoicemailSmsFilterSettings settings) { |
| 3005 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3006 | |
| 3007 | final long identity = Binder.clearCallingIdentity(); |
| 3008 | try { |
| 3009 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3010 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3011 | } finally { |
| 3012 | Binder.restoreCallingIdentity(identity); |
| 3013 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3014 | } |
| 3015 | |
| 3016 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3017 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3018 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3019 | |
| 3020 | final long identity = Binder.clearCallingIdentity(); |
| 3021 | try { |
| 3022 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3023 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3024 | } finally { |
| 3025 | Binder.restoreCallingIdentity(identity); |
| 3026 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3027 | } |
| 3028 | |
| 3029 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3030 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3031 | String callingPackage, int subId) { |
| 3032 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3033 | |
| 3034 | final long identity = Binder.clearCallingIdentity(); |
| 3035 | try { |
| 3036 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3037 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3038 | } finally { |
| 3039 | Binder.restoreCallingIdentity(identity); |
| 3040 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3041 | } |
| 3042 | |
| 3043 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3044 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3045 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3046 | |
| 3047 | final long identity = Binder.clearCallingIdentity(); |
| 3048 | try { |
| 3049 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3050 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3051 | } finally { |
| 3052 | Binder.restoreCallingIdentity(identity); |
| 3053 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3054 | } |
| 3055 | |
| 3056 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3057 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3058 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3059 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3060 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3061 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3062 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3063 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3064 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3065 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3066 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3067 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3068 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3069 | * Sets the voice activation state of a given subId. |
| 3070 | */ |
| 3071 | @Override |
| 3072 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3073 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3074 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3075 | |
| 3076 | final long identity = Binder.clearCallingIdentity(); |
| 3077 | try { |
| 3078 | final Phone phone = getPhone(subId); |
| 3079 | if (phone != null) { |
| 3080 | phone.setVoiceActivationState(activationState); |
| 3081 | } else { |
| 3082 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3083 | } |
| 3084 | } finally { |
| 3085 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3086 | } |
| 3087 | } |
| 3088 | |
| 3089 | /** |
| 3090 | * Sets the data activation state of a given subId. |
| 3091 | */ |
| 3092 | @Override |
| 3093 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3094 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3095 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3096 | |
| 3097 | final long identity = Binder.clearCallingIdentity(); |
| 3098 | try { |
| 3099 | final Phone phone = getPhone(subId); |
| 3100 | if (phone != null) { |
| 3101 | phone.setDataActivationState(activationState); |
| 3102 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3103 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3104 | } |
| 3105 | } finally { |
| 3106 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3107 | } |
| 3108 | } |
| 3109 | |
| 3110 | /** |
| 3111 | * Returns the voice activation state of a given subId. |
| 3112 | */ |
| 3113 | @Override |
| 3114 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3115 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3116 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3117 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3118 | final long identity = Binder.clearCallingIdentity(); |
| 3119 | try { |
| 3120 | if (phone != null) { |
| 3121 | return phone.getVoiceActivationState(); |
| 3122 | } else { |
| 3123 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3124 | } |
| 3125 | } finally { |
| 3126 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3127 | } |
| 3128 | } |
| 3129 | |
| 3130 | /** |
| 3131 | * Returns the data activation state of a given subId. |
| 3132 | */ |
| 3133 | @Override |
| 3134 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3135 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3136 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3137 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3138 | final long identity = Binder.clearCallingIdentity(); |
| 3139 | try { |
| 3140 | if (phone != null) { |
| 3141 | return phone.getDataActivationState(); |
| 3142 | } else { |
| 3143 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3144 | } |
| 3145 | } finally { |
| 3146 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3147 | } |
| 3148 | } |
| 3149 | |
| 3150 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3151 | * Returns the unread count of voicemails for a subId |
| 3152 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3153 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3154 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3155 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3156 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3157 | mApp, subId, callingPackage, callingFeatureId, |
| 3158 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3159 | return 0; |
| 3160 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3161 | final long identity = Binder.clearCallingIdentity(); |
| 3162 | try { |
| 3163 | final Phone phone = getPhone(subId); |
| 3164 | if (phone != null) { |
| 3165 | return phone.getVoiceMessageCount(); |
| 3166 | } else { |
| 3167 | return 0; |
| 3168 | } |
| 3169 | } finally { |
| 3170 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3171 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3172 | } |
| 3173 | |
| 3174 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3175 | * returns true, if the device is in a state where both voice and data |
| 3176 | * are supported simultaneously. This can change based on location or network condition. |
| 3177 | */ |
| 3178 | @Override |
| 3179 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3180 | final long identity = Binder.clearCallingIdentity(); |
| 3181 | try { |
| 3182 | final Phone phone = getPhone(subId); |
| 3183 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3184 | } finally { |
| 3185 | Binder.restoreCallingIdentity(identity); |
| 3186 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3187 | } |
| 3188 | |
| 3189 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3190 | * Send the dialer code if called from the current default dialer or the caller has |
| 3191 | * carrier privilege. |
| 3192 | * @param inputCode The dialer code to send |
| 3193 | */ |
| 3194 | @Override |
| 3195 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3196 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3197 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3198 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3199 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3200 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3201 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3202 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3203 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3204 | |
| 3205 | final long identity = Binder.clearCallingIdentity(); |
| 3206 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3207 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3208 | } finally { |
| 3209 | Binder.restoreCallingIdentity(identity); |
| 3210 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3211 | } |
| 3212 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3213 | @Override |
| 3214 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3215 | TelephonyPermissions |
| 3216 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3217 | mApp, subId, "getNetworkSelectionMode"); |
| 3218 | final long identity = Binder.clearCallingIdentity(); |
| 3219 | try { |
| 3220 | if (!isActiveSubscription(subId)) { |
| 3221 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3222 | } |
| 3223 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3224 | } finally { |
| 3225 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3226 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3227 | } |
| 3228 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3229 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3230 | public boolean isInEmergencySmsMode() { |
| 3231 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3232 | final long identity = Binder.clearCallingIdentity(); |
| 3233 | try { |
| 3234 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3235 | if (phone.isInEmergencySmsMode()) { |
| 3236 | return true; |
| 3237 | } |
| 3238 | } |
| 3239 | } finally { |
| 3240 | Binder.restoreCallingIdentity(identity); |
| 3241 | } |
| 3242 | return false; |
| 3243 | } |
| 3244 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3245 | /** |
| 3246 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3247 | * @param subId The subscription to use to check the configuration. |
| 3248 | * @param c The callback that will be used to send the result. |
| 3249 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3250 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3251 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3252 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3253 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3254 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3255 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3256 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3257 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3258 | "IMS not available on device."); |
| 3259 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3260 | final long token = Binder.clearCallingIdentity(); |
| 3261 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3262 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3263 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3264 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3265 | } catch (ImsException e) { |
| 3266 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3267 | } finally { |
| 3268 | Binder.restoreCallingIdentity(token); |
| 3269 | } |
| 3270 | } |
| 3271 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3272 | /** |
| 3273 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3274 | * @param subId The subscription to use to check the configuration. |
| 3275 | * @param c The callback that will be used to send the result. |
| 3276 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3277 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3278 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3279 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3280 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3281 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3282 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3283 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3284 | final long token = Binder.clearCallingIdentity(); |
| 3285 | try { |
| 3286 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3287 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3288 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3289 | } catch (ImsException e) { |
| 3290 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3291 | + "is inactive, ignoring unregister."); |
| 3292 | // If the subscription is no longer active, just return, since the callback |
| 3293 | // will already have been removed internally. |
| 3294 | } finally { |
| 3295 | Binder.restoreCallingIdentity(token); |
| 3296 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3297 | } |
| 3298 | |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3299 | /** |
| 3300 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3301 | */ |
| 3302 | @Override |
| 3303 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3304 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3305 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3306 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3307 | "IMS not available on device."); |
| 3308 | } |
| 3309 | final long token = Binder.clearCallingIdentity(); |
| 3310 | try { |
| 3311 | Phone phone = getPhone(subId); |
| 3312 | if (phone == null) { |
| 3313 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3314 | + subId + "'"); |
| 3315 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3316 | } |
| 3317 | phone.getImsRegistrationState(regState -> { |
| 3318 | try { |
| 3319 | consumer.accept((regState == null) |
| 3320 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3321 | } catch (RemoteException e) { |
| 3322 | // Ignore if the remote process is no longer available to call back. |
| 3323 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3324 | } |
| 3325 | }); |
| 3326 | } finally { |
| 3327 | Binder.restoreCallingIdentity(token); |
| 3328 | } |
| 3329 | } |
| 3330 | |
| 3331 | /** |
| 3332 | * Get the transport type for the IMS service registration state. |
| 3333 | */ |
| 3334 | @Override |
| 3335 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3336 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3337 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3338 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3339 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3340 | "IMS not available on device."); |
| 3341 | } |
| 3342 | final long token = Binder.clearCallingIdentity(); |
| 3343 | try { |
| 3344 | Phone phone = getPhone(subId); |
| 3345 | if (phone == null) { |
| 3346 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3347 | + subId + "'"); |
| 3348 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3349 | } |
| 3350 | phone.getImsRegistrationTech(regTech -> { |
| 3351 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3352 | int regTechConverted = (regTech == null) |
| 3353 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3354 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3355 | regTechConverted); |
| 3356 | try { |
| 3357 | consumer.accept(regTechConverted); |
| 3358 | } catch (RemoteException e) { |
| 3359 | // Ignore if the remote process is no longer available to call back. |
| 3360 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3361 | } |
| 3362 | }); |
| 3363 | } finally { |
| 3364 | Binder.restoreCallingIdentity(token); |
| 3365 | } |
| 3366 | } |
| 3367 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3368 | /** |
| 3369 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3370 | * @param subId The subscription to use to check the configuration. |
| 3371 | * @param c The callback that will be used to send the result. |
| 3372 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3373 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3374 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3375 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3376 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3377 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3378 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3379 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3380 | "IMS not available on device."); |
| 3381 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3382 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3383 | final long token = Binder.clearCallingIdentity(); |
| 3384 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3385 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3386 | .addCapabilitiesCallbackForSubscription(c, subId); |
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(token); |
| 3391 | } |
| 3392 | } |
| 3393 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3394 | /** |
| 3395 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3396 | * @param subId The subscription to use to check the configuration. |
| 3397 | * @param c The callback that will be used to send the result. |
| 3398 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3399 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3400 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3401 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3402 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3403 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3404 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3405 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3406 | |
| 3407 | final long token = Binder.clearCallingIdentity(); |
| 3408 | try { |
| 3409 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3410 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3411 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3412 | } catch (ImsException e) { |
| 3413 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3414 | + "is inactive, ignoring unregister."); |
| 3415 | // If the subscription is no longer active, just return, since the callback |
| 3416 | // will already have been removed internally. |
| 3417 | } finally { |
| 3418 | Binder.restoreCallingIdentity(token); |
| 3419 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3420 | } |
| 3421 | |
| 3422 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3423 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3424 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3425 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3426 | final long token = Binder.clearCallingIdentity(); |
| 3427 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3428 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3429 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3430 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3431 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3432 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3433 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3434 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3435 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3436 | } finally { |
| 3437 | Binder.restoreCallingIdentity(token); |
| 3438 | } |
| 3439 | } |
| 3440 | |
| 3441 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3442 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3443 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3444 | final long token = Binder.clearCallingIdentity(); |
| 3445 | try { |
| 3446 | Phone phone = getPhone(subId); |
| 3447 | if (phone == null) return false; |
| 3448 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 32706d9 | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3449 | } catch (com.android.ims.ImsException e) { |
| 3450 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3451 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3452 | } finally { |
| 3453 | Binder.restoreCallingIdentity(token); |
| 3454 | } |
| 3455 | } |
| 3456 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3457 | /** |
| 3458 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3459 | * subscription. |
| 3460 | * @param subId The subscription to use to check the configuration. |
| 3461 | * @param callback The callback that will be used to send the result. |
| 3462 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3463 | * @param transportType The transport type of the MmTelFeature capability. |
| 3464 | */ |
| 3465 | @Override |
| 3466 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3467 | int transportType) { |
| 3468 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3469 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3470 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3471 | "IMS not available on device."); |
| 3472 | } |
| 3473 | final long token = Binder.clearCallingIdentity(); |
| 3474 | try { |
| 3475 | int slotId = getSlotIndex(subId); |
| 3476 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3477 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3478 | + subId + "'"); |
| 3479 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3480 | } |
| 3481 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3482 | transportType, aBoolean -> { |
| 3483 | try { |
| 3484 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3485 | } catch (RemoteException e) { |
| 3486 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3487 | + "running. Ignore"); |
| 3488 | } |
| 3489 | }); |
| 3490 | } finally { |
| 3491 | Binder.restoreCallingIdentity(token); |
| 3492 | } |
| 3493 | } |
| 3494 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3495 | /** |
| 3496 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3497 | * @param subId The subscription to use to check the configuration. |
| 3498 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3499 | @Override |
| 3500 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3501 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3502 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3503 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3504 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3505 | final long token = Binder.clearCallingIdentity(); |
| 3506 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3507 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3508 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3509 | } catch (ImsException e) { |
| 3510 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3511 | } finally { |
| 3512 | Binder.restoreCallingIdentity(token); |
| 3513 | } |
| 3514 | } |
| 3515 | |
| 3516 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3517 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3518 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3519 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3520 | final long identity = Binder.clearCallingIdentity(); |
| 3521 | try { |
| 3522 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3523 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3524 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3525 | } catch (ImsException e) { |
| 3526 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3527 | } finally { |
| 3528 | Binder.restoreCallingIdentity(identity); |
| 3529 | } |
| 3530 | } |
| 3531 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3532 | /** |
| 3533 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3534 | * @param subId The subscription to use to check the configuration. |
| 3535 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3536 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3537 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3538 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3539 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3540 | final long identity = Binder.clearCallingIdentity(); |
| 3541 | try { |
| 3542 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3543 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3544 | } catch (ImsException e) { |
| 3545 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3546 | } finally { |
| 3547 | Binder.restoreCallingIdentity(identity); |
| 3548 | } |
| 3549 | } |
| 3550 | |
| 3551 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3552 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3553 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3554 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3555 | final long identity = Binder.clearCallingIdentity(); |
| 3556 | try { |
| 3557 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3558 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3559 | } catch (ImsException e) { |
| 3560 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3561 | } finally { |
| 3562 | Binder.restoreCallingIdentity(identity); |
| 3563 | } |
| 3564 | } |
| 3565 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3566 | /** |
| 3567 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3568 | * @param subId The subscription to use to check the configuration. |
| 3569 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3570 | @Override |
| 3571 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3572 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3573 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3574 | final long identity = Binder.clearCallingIdentity(); |
| 3575 | try { |
| 3576 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3577 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3578 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3579 | } catch (ImsException e) { |
| 3580 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3581 | } finally { |
| 3582 | Binder.restoreCallingIdentity(identity); |
| 3583 | } |
| 3584 | } |
| 3585 | |
| 3586 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3587 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3588 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3589 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3590 | final long identity = Binder.clearCallingIdentity(); |
| 3591 | try { |
| 3592 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3593 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3594 | } catch (ImsException e) { |
| 3595 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3596 | } finally { |
| 3597 | Binder.restoreCallingIdentity(identity); |
| 3598 | } |
| 3599 | } |
| 3600 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3601 | /** |
| 3602 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3603 | * @param subId The subscription to use to check the configuration. |
| 3604 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3605 | @Override |
| 3606 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3607 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3608 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3609 | final long identity = Binder.clearCallingIdentity(); |
| 3610 | try { |
| 3611 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3612 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3613 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3614 | } catch (ImsException e) { |
| 3615 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3616 | } finally { |
| 3617 | Binder.restoreCallingIdentity(identity); |
| 3618 | } |
| 3619 | } |
| 3620 | |
| 3621 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3622 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3623 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3624 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3625 | final long identity = Binder.clearCallingIdentity(); |
| 3626 | try { |
| 3627 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3628 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3629 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3630 | } catch (ImsException e) { |
| 3631 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3632 | } finally { |
| 3633 | Binder.restoreCallingIdentity(identity); |
| 3634 | } |
| 3635 | } |
| 3636 | |
| 3637 | @Override |
| 3638 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3639 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3640 | "setVoWiFiNonPersistent"); |
| 3641 | final long identity = Binder.clearCallingIdentity(); |
| 3642 | try { |
| 3643 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3644 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3645 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3646 | } catch (ImsException e) { |
| 3647 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3648 | } finally { |
| 3649 | Binder.restoreCallingIdentity(identity); |
| 3650 | } |
| 3651 | } |
| 3652 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3653 | /** |
| 3654 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3655 | * @param subId The subscription to use to check the configuration. |
| 3656 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3657 | @Override |
| 3658 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3659 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3660 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3661 | final long identity = Binder.clearCallingIdentity(); |
| 3662 | try { |
| 3663 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3664 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3665 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3666 | } catch (ImsException e) { |
| 3667 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3668 | } finally { |
| 3669 | Binder.restoreCallingIdentity(identity); |
| 3670 | } |
| 3671 | } |
| 3672 | |
| 3673 | @Override |
| 3674 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3675 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3676 | "setVoWiFiModeSetting"); |
| 3677 | final long identity = Binder.clearCallingIdentity(); |
| 3678 | try { |
| 3679 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3680 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3681 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3682 | } catch (ImsException e) { |
| 3683 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3684 | } finally { |
| 3685 | Binder.restoreCallingIdentity(identity); |
| 3686 | } |
| 3687 | } |
| 3688 | |
| 3689 | @Override |
| 3690 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3691 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3692 | final long identity = Binder.clearCallingIdentity(); |
| 3693 | try { |
| 3694 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3695 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3696 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3697 | } catch (ImsException e) { |
| 3698 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3699 | } finally { |
| 3700 | Binder.restoreCallingIdentity(identity); |
| 3701 | } |
| 3702 | } |
| 3703 | |
| 3704 | @Override |
| 3705 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3706 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3707 | "setVoWiFiRoamingModeSetting"); |
| 3708 | final long identity = Binder.clearCallingIdentity(); |
| 3709 | try { |
| 3710 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3711 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3712 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3713 | } catch (ImsException e) { |
| 3714 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3715 | } finally { |
| 3716 | Binder.restoreCallingIdentity(identity); |
| 3717 | } |
| 3718 | } |
| 3719 | |
| 3720 | @Override |
| 3721 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3722 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3723 | "setRttCapabilityEnabled"); |
| 3724 | final long identity = Binder.clearCallingIdentity(); |
| 3725 | try { |
| 3726 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3727 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3728 | } catch (ImsException e) { |
| 3729 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3730 | } finally { |
| 3731 | Binder.restoreCallingIdentity(identity); |
| 3732 | } |
| 3733 | } |
| 3734 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3735 | /** |
| 3736 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3737 | * @param subId The subscription to use to check the configuration. |
| 3738 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3739 | @Override |
| 3740 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3741 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3742 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3743 | final long identity = Binder.clearCallingIdentity(); |
| 3744 | try { |
| 3745 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3746 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3747 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3748 | } catch (ImsException e) { |
| 3749 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3750 | } finally { |
| 3751 | Binder.restoreCallingIdentity(identity); |
| 3752 | } |
| 3753 | } |
| 3754 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3755 | @Override |
| 3756 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3757 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3758 | final long identity = Binder.clearCallingIdentity(); |
| 3759 | try { |
Brad Ebinger | 6cf0f65 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 3760 | if (!isImsAvailableOnDevice()) { |
| 3761 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3762 | "IMS not available on device."); |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 3763 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3764 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3765 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3766 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3767 | } catch (ImsException e) { |
| 3768 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3769 | } finally { |
| 3770 | Binder.restoreCallingIdentity(identity); |
| 3771 | } |
| 3772 | } |
| 3773 | |
| 3774 | @Override |
| 3775 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3776 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3777 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3778 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3779 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3780 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3781 | try { |
| 3782 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3783 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3784 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3785 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3786 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3787 | + "is inactive, ignoring unregister."); |
| 3788 | // If the subscription is no longer active, just return, since the callback will already |
| 3789 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3790 | } finally { |
| 3791 | Binder.restoreCallingIdentity(identity); |
| 3792 | } |
| 3793 | } |
| 3794 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3795 | |
| 3796 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 3797 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3798 | message); |
| 3799 | } |
| 3800 | |
| 3801 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 3802 | boolean isMmtelCapability) { |
| 3803 | Phone phone = getPhone(subId); |
| 3804 | if (phone == null) { |
| 3805 | loge("phone instance null for subid " + subId); |
| 3806 | return false; |
| 3807 | } |
| 3808 | if (isMmtelCapability) { |
| 3809 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3810 | return false; |
| 3811 | } |
| 3812 | } else { |
| 3813 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3814 | return false; |
| 3815 | } |
| 3816 | } |
| 3817 | return true; |
| 3818 | } |
| 3819 | |
| 3820 | @Override |
| 3821 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 3822 | boolean isProvisioned) { |
| 3823 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 3824 | |
| 3825 | final long identity = Binder.clearCallingIdentity(); |
| 3826 | try { |
| 3827 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3828 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3829 | return; |
| 3830 | } |
| 3831 | |
| 3832 | // this capability requires provisioning, route to the correct API. |
| 3833 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3834 | switch (capability) { |
| 3835 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3836 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3837 | ims.setEabProvisioned(isProvisioned); |
| 3838 | break; |
| 3839 | default: { |
| 3840 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3841 | + "rcs capability '" + capability + "', which does not require " |
| 3842 | + "provisioning."); |
| 3843 | } |
| 3844 | } |
| 3845 | } finally { |
| 3846 | Binder.restoreCallingIdentity(identity); |
| 3847 | } |
| 3848 | |
| 3849 | } |
| 3850 | |
| 3851 | |
| 3852 | @Override |
| 3853 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 3854 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 3855 | final long identity = Binder.clearCallingIdentity(); |
| 3856 | try { |
| 3857 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3858 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3859 | return true; |
| 3860 | } |
| 3861 | |
| 3862 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3863 | switch (capability) { |
| 3864 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3865 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3866 | return ims.isEabProvisionedOnDevice(); |
| 3867 | |
| 3868 | default: { |
| 3869 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 3870 | + "capability '" + capability + "', which does not require " |
| 3871 | + "provisioning."); |
| 3872 | } |
| 3873 | } |
| 3874 | |
| 3875 | } finally { |
| 3876 | Binder.restoreCallingIdentity(identity); |
| 3877 | } |
| 3878 | } |
| 3879 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3880 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3881 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3882 | boolean isProvisioned) { |
| 3883 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3884 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3885 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3886 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3887 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3888 | final long identity = Binder.clearCallingIdentity(); |
| 3889 | try { |
| 3890 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3891 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3892 | return; |
| 3893 | } |
| 3894 | |
| 3895 | // this capability requires provisioning, route to the correct API. |
| 3896 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3897 | switch (capability) { |
| 3898 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3899 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3900 | ims.setVolteProvisioned(isProvisioned); |
| 3901 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3902 | ims.setWfcProvisioned(isProvisioned); |
| 3903 | } |
| 3904 | break; |
| 3905 | } |
| 3906 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3907 | // There is currently no difference in VT provisioning type. |
| 3908 | ims.setVtProvisioned(isProvisioned); |
| 3909 | break; |
| 3910 | } |
| 3911 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3912 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3913 | // change the capability of the feature instead if needed. |
| 3914 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3915 | == isProvisioned) { |
| 3916 | // No change in provisioning. |
| 3917 | return; |
| 3918 | } |
| 3919 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3920 | try { |
| 3921 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3922 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3923 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3924 | + ", Exception" + e.getMessage()); |
| 3925 | } |
| 3926 | break; |
| 3927 | } |
| 3928 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3929 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3930 | + "MmTel capability '" + capability + "', which does not require " |
| 3931 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3932 | } |
| 3933 | } |
| 3934 | |
| 3935 | } finally { |
| 3936 | Binder.restoreCallingIdentity(identity); |
| 3937 | } |
| 3938 | } |
| 3939 | |
| 3940 | @Override |
| 3941 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3942 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3943 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3944 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3945 | } |
| 3946 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3947 | final long identity = Binder.clearCallingIdentity(); |
| 3948 | try { |
| 3949 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3950 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3951 | return true; |
| 3952 | } |
| 3953 | |
| 3954 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3955 | switch (capability) { |
| 3956 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3957 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3958 | return ims.isVolteProvisionedOnDevice(); |
| 3959 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3960 | return ims.isWfcProvisionedOnDevice(); |
| 3961 | } |
| 3962 | // This should never happen, since we are checking tech above to make sure it |
| 3963 | // is either LTE or IWLAN. |
| 3964 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3965 | + "capability."); |
| 3966 | } |
| 3967 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3968 | // There is currently no difference in VT provisioning type. |
| 3969 | return ims.isVtProvisionedOnDevice(); |
| 3970 | } |
| 3971 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3972 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3973 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3974 | } |
| 3975 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3976 | throw new IllegalArgumentException( |
| 3977 | "Tried to get provisioning for MmTel capability '" + capability |
| 3978 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3979 | } |
| 3980 | } |
| 3981 | |
| 3982 | } finally { |
| 3983 | Binder.restoreCallingIdentity(identity); |
| 3984 | } |
| 3985 | } |
| 3986 | |
| 3987 | @Override |
| 3988 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3989 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3990 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3991 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3992 | } |
| 3993 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3994 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3995 | return (provisionedBits & capability) > 0; |
| 3996 | } |
| 3997 | |
| 3998 | @Override |
| 3999 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4000 | boolean isProvisioned) { |
| 4001 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4002 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4003 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4004 | } |
| 4005 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4006 | "setProvisioningStatusForCapability"); |
| 4007 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4008 | // If the current provisioning status for capability already matches isProvisioned, |
| 4009 | // do nothing. |
| 4010 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4011 | return; |
| 4012 | } |
| 4013 | if (isProvisioned) { |
| 4014 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4015 | } else { |
| 4016 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4017 | } |
| 4018 | } |
| 4019 | |
| 4020 | /** |
| 4021 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4022 | * technology. The bitfield should mirror the bitfield defined by |
| 4023 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4024 | */ |
| 4025 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4026 | String key = getMmTelProvisioningKey(subId, tech); |
| 4027 | // Default is no capabilities are provisioned. |
| 4028 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4029 | } |
| 4030 | |
| 4031 | /** |
| 4032 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4033 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4034 | * technology specified. |
| 4035 | * |
| 4036 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4037 | */ |
| 4038 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4039 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4040 | String key = getMmTelProvisioningKey(subId, tech); |
| 4041 | editor.putInt(key, newField); |
| 4042 | editor.commit(); |
| 4043 | } |
| 4044 | |
| 4045 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4046 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4047 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4048 | } |
| 4049 | |
| 4050 | /** |
| 4051 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4052 | * carrier associated with the subscription id. |
| 4053 | */ |
| 4054 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4055 | int capability) { |
| 4056 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4057 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4058 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4059 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4060 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4061 | false); |
| 4062 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4063 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4064 | |
| 4065 | // First check to make sure that the capability requires provisioning. |
| 4066 | switch (capability) { |
| 4067 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4068 | // intentional fallthrough |
| 4069 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4070 | if (requireVoiceVtProvisioning) { |
| 4071 | // Voice and Video requires provisioning |
| 4072 | return true; |
| 4073 | } |
| 4074 | break; |
| 4075 | } |
| 4076 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4077 | if (requireUtProvisioning) { |
| 4078 | // UT requires provisioning |
| 4079 | return true; |
| 4080 | } |
| 4081 | break; |
| 4082 | } |
| 4083 | } |
| 4084 | return false; |
| 4085 | } |
| 4086 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4087 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4088 | int capability) { |
| 4089 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4090 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4091 | |
| 4092 | boolean requireRcsProvisioning = c.getBoolean( |
| 4093 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4094 | |
| 4095 | // First check to make sure that the capability requires provisioning. |
| 4096 | switch (capability) { |
| 4097 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4098 | // intentional fallthrough |
| 4099 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4100 | if (requireRcsProvisioning) { |
| 4101 | // OPTION or PRESENCE requires provisioning |
| 4102 | return true; |
| 4103 | } |
| 4104 | break; |
| 4105 | } |
| 4106 | } |
| 4107 | return false; |
| 4108 | } |
| 4109 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4110 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4111 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4112 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4113 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4114 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4115 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4116 | final long identity = Binder.clearCallingIdentity(); |
| 4117 | try { |
| 4118 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4119 | int slotId = getSlotIndex(subId); |
| 4120 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4121 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4122 | + subId + "' for key:" + key); |
| 4123 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4124 | } |
| 4125 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4126 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4127 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4128 | + subId + "' for key:" + key); |
| 4129 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4130 | } finally { |
| 4131 | Binder.restoreCallingIdentity(identity); |
| 4132 | } |
| 4133 | } |
| 4134 | |
| 4135 | @Override |
| 4136 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4137 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4138 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4139 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4140 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4141 | final long identity = Binder.clearCallingIdentity(); |
| 4142 | try { |
| 4143 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4144 | int slotId = getSlotIndex(subId); |
| 4145 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4146 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4147 | + subId + "' for key:" + key); |
| 4148 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4149 | } |
| 4150 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4151 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4152 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4153 | + subId + "' for key:" + key); |
| 4154 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4155 | } finally { |
| 4156 | Binder.restoreCallingIdentity(identity); |
| 4157 | } |
| 4158 | } |
| 4159 | |
| 4160 | @Override |
| 4161 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4162 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4163 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4164 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4165 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4166 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4167 | final long identity = Binder.clearCallingIdentity(); |
| 4168 | try { |
| 4169 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4170 | int slotId = getSlotIndex(subId); |
| 4171 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4172 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4173 | + subId + "' for key:" + key); |
| 4174 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4175 | } |
| 4176 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4177 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4178 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4179 | + "' for key:" + key); |
| 4180 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4181 | } finally { |
| 4182 | Binder.restoreCallingIdentity(identity); |
| 4183 | } |
| 4184 | } |
| 4185 | |
| 4186 | @Override |
| 4187 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4188 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4189 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4190 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4191 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4192 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4193 | final long identity = Binder.clearCallingIdentity(); |
| 4194 | try { |
| 4195 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4196 | int slotId = getSlotIndex(subId); |
| 4197 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4198 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4199 | + subId + "' for key:" + key); |
| 4200 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4201 | } |
| 4202 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4203 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4204 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4205 | + "' for key:" + key); |
| 4206 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4207 | } finally { |
| 4208 | Binder.restoreCallingIdentity(identity); |
| 4209 | } |
| 4210 | } |
| 4211 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4212 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4213 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4214 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4215 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4216 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4217 | } |
| 4218 | return slotId; |
| 4219 | } |
| 4220 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4221 | private int getSlotIndex(int subId) { |
| 4222 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4223 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4224 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4225 | } |
| 4226 | return slotId; |
| 4227 | } |
| 4228 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4229 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4230 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4231 | */ |
| 4232 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4233 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4234 | String callingFeatureId) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4235 | final int targetSdk = getTargetSdk(callingPackage); |
| 4236 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4237 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4238 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4239 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4240 | mApp, subId, callingPackage, callingFeatureId, |
| 4241 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4242 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4243 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4244 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4245 | final long identity = Binder.clearCallingIdentity(); |
| 4246 | try { |
| 4247 | final Phone phone = getPhone(subId); |
| 4248 | if (phone != null) { |
| 4249 | return phone.getServiceState().getDataNetworkType(); |
| 4250 | } else { |
| 4251 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4252 | } |
| 4253 | } finally { |
| 4254 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4255 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4256 | } |
| 4257 | |
| 4258 | /** |
| 4259 | * Returns the data network type |
| 4260 | */ |
| 4261 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4262 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4263 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4264 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4265 | } |
| 4266 | |
| 4267 | /** |
| 4268 | * Returns the data network type for a subId |
| 4269 | */ |
| 4270 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4271 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4272 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4273 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4274 | mApp, subId, callingPackage, callingFeatureId, |
| 4275 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4276 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4277 | } |
| 4278 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4279 | final long identity = Binder.clearCallingIdentity(); |
| 4280 | try { |
| 4281 | final Phone phone = getPhone(subId); |
| 4282 | if (phone != null) { |
| 4283 | return phone.getServiceState().getDataNetworkType(); |
| 4284 | } else { |
| 4285 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4286 | } |
| 4287 | } finally { |
| 4288 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4289 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4290 | } |
| 4291 | |
| 4292 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4293 | * Returns the Voice network type for a subId |
| 4294 | */ |
| 4295 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4296 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4297 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4298 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4299 | mApp, subId, callingPackage, callingFeatureId, |
| 4300 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4301 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4302 | } |
| 4303 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4304 | final long identity = Binder.clearCallingIdentity(); |
| 4305 | try { |
| 4306 | final Phone phone = getPhone(subId); |
| 4307 | if (phone != null) { |
| 4308 | return phone.getServiceState().getVoiceNetworkType(); |
| 4309 | } else { |
| 4310 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4311 | } |
| 4312 | } finally { |
| 4313 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4314 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4315 | } |
| 4316 | |
| 4317 | /** |
| 4318 | * @return true if a ICC card is present |
| 4319 | */ |
| 4320 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4321 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4322 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4323 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4324 | } |
| 4325 | |
| 4326 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4327 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4328 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4329 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4330 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4331 | final long identity = Binder.clearCallingIdentity(); |
| 4332 | try { |
| 4333 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4334 | if (phone != null) { |
| 4335 | return phone.getIccCard().hasIccCard(); |
| 4336 | } else { |
| 4337 | return false; |
| 4338 | } |
| 4339 | } finally { |
| 4340 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4341 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4342 | } |
| 4343 | |
| 4344 | /** |
| 4345 | * Return if the current radio is LTE on CDMA. This |
| 4346 | * is a tri-state return value as for a period of time |
| 4347 | * the mode may be unknown. |
| 4348 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4349 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4350 | * @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] | 4351 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4352 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4353 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4354 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4355 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4356 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4357 | } |
| 4358 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4359 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4360 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4361 | String callingFeatureId) { |
Sarah Chin | f6656a6 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4362 | try { |
| 4363 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4364 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4365 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4366 | } |
| 4367 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4368 | final long identity = Binder.clearCallingIdentity(); |
| 4369 | try { |
| 4370 | final Phone phone = getPhone(subId); |
| 4371 | if (phone == null) { |
| 4372 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4373 | } else { |
| 4374 | return phone.getLteOnCdmaMode(); |
| 4375 | } |
| 4376 | } finally { |
| 4377 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4378 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4379 | } |
| 4380 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4381 | /** |
| 4382 | * {@hide} |
| 4383 | * Returns Default subId, 0 in the case of single standby. |
| 4384 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4385 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4386 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4387 | } |
| 4388 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4389 | private int getSlotForDefaultSubscription() { |
| 4390 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4391 | } |
| 4392 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4393 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4394 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4395 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4396 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4397 | private boolean isActiveSubscription(int subId) { |
| 4398 | return mSubscriptionController.isActiveSubId(subId); |
| 4399 | } |
| 4400 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4401 | /** |
| 4402 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4403 | */ |
| 4404 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4405 | final long identity = Binder.clearCallingIdentity(); |
| 4406 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4407 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4408 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4409 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4410 | } finally { |
| 4411 | Binder.restoreCallingIdentity(identity); |
| 4412 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4413 | } |
| 4414 | |
| 4415 | /** |
| 4416 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4417 | */ |
| 4418 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4419 | final long identity = Binder.clearCallingIdentity(); |
| 4420 | try { |
| 4421 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4422 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4423 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4424 | } finally { |
| 4425 | Binder.restoreCallingIdentity(identity); |
| 4426 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4427 | } |
| 4428 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4429 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4430 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4431 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4432 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4433 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4434 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4435 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4436 | if (phoneId == -1) { |
| 4437 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4438 | + " does not correspond to an active phone"); |
| 4439 | } |
| 4440 | return PhoneFactory.getPhone(phoneId); |
| 4441 | } |
| 4442 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4443 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4444 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4445 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4446 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4447 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4448 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4449 | if (DBG) { |
| 4450 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4451 | } |
| 4452 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4453 | p2); |
| 4454 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4455 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4456 | |
| 4457 | @Override |
| 4458 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4459 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4460 | enforceModifyPermission(); |
| 4461 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4462 | if (DBG) { |
| 4463 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4464 | } |
| 4465 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4466 | callingPackage, aid, p2); |
| 4467 | } |
| 4468 | |
| 4469 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4470 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4471 | final long identity = Binder.clearCallingIdentity(); |
| 4472 | try { |
| 4473 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4474 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4475 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4476 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4477 | if (bestComponent == null |
| 4478 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4479 | loge("The calling package is not allowed to access ISD-R."); |
| 4480 | throw new SecurityException( |
| 4481 | "The calling package is not allowed to access ISD-R."); |
| 4482 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4483 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4484 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4485 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4486 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4487 | null /* workSource */); |
| 4488 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4489 | return response; |
| 4490 | } finally { |
| 4491 | Binder.restoreCallingIdentity(identity); |
| 4492 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4493 | } |
| 4494 | |
| 4495 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4496 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4497 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4498 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4499 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4500 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4501 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4502 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4503 | @Override |
| 4504 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4505 | enforceModifyPermission(); |
| 4506 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4507 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4508 | channel); |
| 4509 | } |
| 4510 | |
| 4511 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4512 | final long identity = Binder.clearCallingIdentity(); |
| 4513 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4514 | if (channel < 0) { |
| 4515 | return false; |
| 4516 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4517 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4518 | null /* workSource */); |
| 4519 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4520 | return success; |
| 4521 | } finally { |
| 4522 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4523 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4524 | } |
| 4525 | |
| 4526 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4527 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4528 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4529 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4530 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4531 | if (DBG) { |
| 4532 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4533 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4534 | + p3 + " data=" + data); |
| 4535 | } |
| 4536 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4537 | command, p1, p2, p3, data); |
| 4538 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4539 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4540 | @Override |
| 4541 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4542 | int command, int p1, int p2, int p3, String data) { |
| 4543 | enforceModifyPermission(); |
| 4544 | if (DBG) { |
| 4545 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4546 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4547 | + p3 + " data=" + data); |
| 4548 | } |
| 4549 | return iccTransmitApduLogicalChannelWithPermission( |
| 4550 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4551 | data); |
| 4552 | } |
| 4553 | |
| 4554 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4555 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4556 | final long identity = Binder.clearCallingIdentity(); |
| 4557 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4558 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4559 | return ""; |
| 4560 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4561 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4562 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4563 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4564 | null /* workSource */); |
| 4565 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4566 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4567 | // Append the returned status code to the end of the response payload. |
| 4568 | String s = Integer.toHexString( |
| 4569 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4570 | if (response.payload != null) { |
| 4571 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4572 | } |
| 4573 | return s; |
| 4574 | } finally { |
| 4575 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4576 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4577 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4578 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4579 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4580 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4581 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4582 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4583 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4584 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4585 | if (DBG) { |
| 4586 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4587 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4588 | } |
| 4589 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4590 | cla, command, p1, p2, p3, data); |
| 4591 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4592 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4593 | @Override |
| 4594 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4595 | int command, int p1, int p2, int p3, String data) { |
| 4596 | enforceModifyPermission(); |
| 4597 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4598 | if (DBG) { |
| 4599 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4600 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4601 | + " data=" + data); |
| 4602 | } |
| 4603 | |
| 4604 | return iccTransmitApduBasicChannelWithPermission( |
| 4605 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4606 | p2, p3, data); |
| 4607 | } |
| 4608 | |
| 4609 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4610 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4611 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4612 | final long identity = Binder.clearCallingIdentity(); |
| 4613 | try { |
| 4614 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4615 | && TextUtils.equals(ISDR_AID, data)) { |
| 4616 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4617 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4618 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4619 | if (bestComponent == null |
| 4620 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4621 | loge("The calling package is not allowed to select ISD-R."); |
| 4622 | throw new SecurityException( |
| 4623 | "The calling package is not allowed to select ISD-R."); |
| 4624 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4625 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4626 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4627 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4628 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4629 | null /* workSource */); |
| 4630 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4631 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4632 | // Append the returned status code to the end of the response payload. |
| 4633 | String s = Integer.toHexString( |
| 4634 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4635 | if (response.payload != null) { |
| 4636 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4637 | } |
| 4638 | return s; |
| 4639 | } finally { |
| 4640 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4641 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4642 | } |
| 4643 | |
| 4644 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4645 | 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] | 4646 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4647 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4648 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4649 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4650 | final long identity = Binder.clearCallingIdentity(); |
| 4651 | try { |
| 4652 | if (DBG) { |
| 4653 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4654 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4655 | } |
| 4656 | |
| 4657 | IccIoResult response = |
| 4658 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4659 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4660 | subId); |
| 4661 | |
| 4662 | if (DBG) { |
| 4663 | log("Exchange SIM_IO [R]" + response); |
| 4664 | } |
| 4665 | |
| 4666 | byte[] result = null; |
| 4667 | int length = 2; |
| 4668 | if (response.payload != null) { |
| 4669 | length = 2 + response.payload.length; |
| 4670 | result = new byte[length]; |
| 4671 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4672 | } else { |
| 4673 | result = new byte[length]; |
| 4674 | } |
| 4675 | |
| 4676 | result[length - 1] = (byte) response.sw2; |
| 4677 | result[length - 2] = (byte) response.sw1; |
| 4678 | return result; |
| 4679 | } finally { |
| 4680 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4681 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4682 | } |
| 4683 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4684 | /** |
| 4685 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4686 | * on a particular subscription |
| 4687 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4688 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 4689 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4690 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4691 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4692 | return null; |
| 4693 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4694 | |
| 4695 | final long identity = Binder.clearCallingIdentity(); |
| 4696 | try { |
| 4697 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4698 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4699 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4700 | return null; |
| 4701 | } |
| 4702 | Object response = sendRequest( |
| 4703 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4704 | if (response instanceof String[]) { |
| 4705 | return (String[]) response; |
| 4706 | } |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4707 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4708 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4709 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4710 | } finally { |
| 4711 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4712 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4713 | } |
| 4714 | |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4715 | /** |
| 4716 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 4717 | * subscription. |
| 4718 | * |
| 4719 | * @param subId the id of the subscription. |
| 4720 | * @param appType the uicc app type, must be USIM or SIM. |
| 4721 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 4722 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4723 | * @param callingFeatureId the feature in the package. |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4724 | * @return number of fplmns that is successfully written to the SIM. |
| 4725 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4726 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 4727 | String callingFeatureId) { |
| 4728 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 4729 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4730 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 4731 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 4732 | } |
| 4733 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 4734 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4735 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 4736 | } |
| 4737 | if (fplmns == null) { |
| 4738 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 4739 | } |
| 4740 | for (String fplmn : fplmns) { |
| 4741 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 4742 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 4743 | } |
| 4744 | } |
| 4745 | final long identity = Binder.clearCallingIdentity(); |
| 4746 | try { |
| 4747 | Object response = sendRequest( |
| 4748 | CMD_SET_FORBIDDEN_PLMNS, |
| 4749 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 4750 | subId); |
| 4751 | return (int) response; |
| 4752 | } finally { |
| 4753 | Binder.restoreCallingIdentity(identity); |
| 4754 | } |
| 4755 | } |
| 4756 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4757 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4758 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4759 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4760 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4761 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4762 | final long identity = Binder.clearCallingIdentity(); |
| 4763 | try { |
| 4764 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4765 | if (response.payload == null) { |
| 4766 | return ""; |
| 4767 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4768 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4769 | // Append the returned status code to the end of the response payload. |
| 4770 | String s = Integer.toHexString( |
| 4771 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4772 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4773 | return s; |
| 4774 | } finally { |
| 4775 | Binder.restoreCallingIdentity(identity); |
| 4776 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4777 | } |
| 4778 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4779 | /** |
| 4780 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4781 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4782 | * |
| 4783 | * @param itemID the ID of the item to read |
| 4784 | * @return the NV item as a String, or null on error. |
| 4785 | */ |
| 4786 | @Override |
| 4787 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4788 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4789 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4790 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4791 | |
| 4792 | final long identity = Binder.clearCallingIdentity(); |
| 4793 | try { |
| 4794 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4795 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4796 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4797 | return value; |
| 4798 | } finally { |
| 4799 | Binder.restoreCallingIdentity(identity); |
| 4800 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4801 | } |
| 4802 | |
| 4803 | /** |
| 4804 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4805 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4806 | * |
| 4807 | * @param itemID the ID of the item to read |
| 4808 | * @param itemValue the value to write, as a String |
| 4809 | * @return true on success; false on any failure |
| 4810 | */ |
| 4811 | @Override |
| 4812 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4813 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4814 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4815 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4816 | |
| 4817 | final long identity = Binder.clearCallingIdentity(); |
| 4818 | try { |
| 4819 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4820 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4821 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4822 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4823 | return success; |
| 4824 | } finally { |
| 4825 | Binder.restoreCallingIdentity(identity); |
| 4826 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4827 | } |
| 4828 | |
| 4829 | /** |
| 4830 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4831 | * Used for device configuration by some CDMA operators. |
| 4832 | * |
| 4833 | * @param preferredRoamingList byte array containing the new PRL |
| 4834 | * @return true on success; false on any failure |
| 4835 | */ |
| 4836 | @Override |
| 4837 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4838 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4839 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4840 | |
| 4841 | final long identity = Binder.clearCallingIdentity(); |
| 4842 | try { |
| 4843 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4844 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4845 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4846 | return success; |
| 4847 | } finally { |
| 4848 | Binder.restoreCallingIdentity(identity); |
| 4849 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4850 | } |
| 4851 | |
| 4852 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4853 | * 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] | 4854 | * Used for device configuration by some CDMA operators. |
| 4855 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4856 | * @param slotIndex - device slot. |
| 4857 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4858 | * @return true on success; false on any failure |
| 4859 | */ |
| 4860 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4861 | public boolean resetModemConfig(int slotIndex) { |
| 4862 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4863 | if (phone != null) { |
| 4864 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4865 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4866 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4867 | final long identity = Binder.clearCallingIdentity(); |
| 4868 | try { |
| 4869 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4870 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4871 | return success; |
| 4872 | } finally { |
| 4873 | Binder.restoreCallingIdentity(identity); |
| 4874 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4875 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4876 | return false; |
| 4877 | } |
| 4878 | |
| 4879 | /** |
| 4880 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4881 | * |
| 4882 | * @param slotIndex - device slot. |
| 4883 | * |
| 4884 | * @return true on success; false on any failure |
| 4885 | */ |
| 4886 | @Override |
| 4887 | public boolean rebootModem(int slotIndex) { |
| 4888 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4889 | if (phone != null) { |
| 4890 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4891 | mApp, phone.getSubId(), "rebootModem"); |
| 4892 | |
| 4893 | final long identity = Binder.clearCallingIdentity(); |
| 4894 | try { |
| 4895 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4896 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4897 | return success; |
| 4898 | } finally { |
| 4899 | Binder.restoreCallingIdentity(identity); |
| 4900 | } |
| 4901 | } |
| 4902 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4903 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4904 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4905 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 4906 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4907 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4908 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4909 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4910 | return new String[0]; |
| 4911 | } |
| 4912 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4913 | final long identity = Binder.clearCallingIdentity(); |
| 4914 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4915 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4916 | } finally { |
| 4917 | Binder.restoreCallingIdentity(identity); |
| 4918 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4919 | } |
| 4920 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4921 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 4922 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 4923 | * {@link #disableIms(int)}. |
| 4924 | * @param slotIndex device slot. |
| 4925 | */ |
| 4926 | public void resetIms(int slotIndex) { |
| 4927 | enforceModifyPermission(); |
| 4928 | |
| 4929 | final long identity = Binder.clearCallingIdentity(); |
| 4930 | try { |
| 4931 | if (mImsResolver == null) { |
| 4932 | // may happen if the does not support IMS. |
| 4933 | return; |
| 4934 | } |
| 4935 | mImsResolver.disableIms(slotIndex); |
| 4936 | mImsResolver.enableIms(slotIndex); |
| 4937 | } finally { |
| 4938 | Binder.restoreCallingIdentity(identity); |
| 4939 | } |
| 4940 | } |
| 4941 | |
| 4942 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4943 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4944 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4945 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4946 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4947 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4948 | |
| 4949 | final long identity = Binder.clearCallingIdentity(); |
| 4950 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4951 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4952 | // may happen if the device does not support IMS. |
| 4953 | return; |
| 4954 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4955 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4956 | } finally { |
| 4957 | Binder.restoreCallingIdentity(identity); |
| 4958 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4959 | } |
| 4960 | |
| 4961 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4962 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4963 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4964 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4965 | public void disableIms(int slotId) { |
| 4966 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4967 | |
| 4968 | final long identity = Binder.clearCallingIdentity(); |
| 4969 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4970 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4971 | // may happen if the device does not support IMS. |
| 4972 | return; |
| 4973 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4974 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4975 | } finally { |
| 4976 | Binder.restoreCallingIdentity(identity); |
| 4977 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4978 | } |
| 4979 | |
| 4980 | /** |
| 4981 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4982 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4983 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4984 | */ |
| 4985 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4986 | IImsServiceFeatureCallback callback) { |
| 4987 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4988 | |
| 4989 | final long identity = Binder.clearCallingIdentity(); |
| 4990 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4991 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4992 | // may happen if the device does not support IMS. |
| 4993 | return null; |
| 4994 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4995 | return mImsResolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4996 | } finally { |
| 4997 | Binder.restoreCallingIdentity(identity); |
| 4998 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4999 | } |
| 5000 | |
| 5001 | /** |
| 5002 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 5003 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 5004 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 5005 | * listener for feature updates. |
| 5006 | */ |
| 5007 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 5008 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5009 | |
| 5010 | final long identity = Binder.clearCallingIdentity(); |
| 5011 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5012 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5013 | // may happen if the device does not support IMS. |
| 5014 | return null; |
| 5015 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5016 | return mImsResolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5017 | } finally { |
| 5018 | Binder.restoreCallingIdentity(identity); |
| 5019 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5020 | } |
| 5021 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5022 | /** |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5023 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5024 | */ |
| 5025 | public void unregisterImsFeatureCallback(int slotId, int featureType, |
| 5026 | IImsServiceFeatureCallback callback) { |
| 5027 | enforceModifyPermission(); |
| 5028 | |
| 5029 | final long identity = Binder.clearCallingIdentity(); |
| 5030 | try { |
| 5031 | if (mImsResolver == null) return; |
| 5032 | mImsResolver.unregisterImsFeatureCallback(slotId, featureType, callback); |
| 5033 | } finally { |
| 5034 | Binder.restoreCallingIdentity(identity); |
| 5035 | } |
| 5036 | } |
| 5037 | |
| 5038 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5039 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5040 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5041 | */ |
| 5042 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5043 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5044 | |
| 5045 | final long identity = Binder.clearCallingIdentity(); |
| 5046 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5047 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5048 | // may happen if the device does not support IMS. |
| 5049 | return null; |
| 5050 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5051 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5052 | } finally { |
| 5053 | Binder.restoreCallingIdentity(identity); |
| 5054 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5055 | } |
| 5056 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5057 | /** |
| 5058 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5059 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5060 | */ |
| 5061 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5062 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5063 | |
| 5064 | final long identity = Binder.clearCallingIdentity(); |
| 5065 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5066 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5067 | // may happen if the device does not support IMS. |
| 5068 | return null; |
| 5069 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5070 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5071 | } finally { |
| 5072 | Binder.restoreCallingIdentity(identity); |
| 5073 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5074 | } |
| 5075 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5076 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5077 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5078 | * |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5079 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5080 | * @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] | 5081 | * ImsService is the device default ImsService. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5082 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5083 | * @param packageName The name of the package that the current configuration will be replaced |
| 5084 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5085 | * @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] | 5086 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5087 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5088 | int[] featureTypes, String packageName) { |
| 5089 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5090 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5091 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5092 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5093 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5094 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5095 | final long identity = Binder.clearCallingIdentity(); |
| 5096 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5097 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5098 | // may happen if the device does not support IMS. |
| 5099 | return false; |
| 5100 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5101 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5102 | for (int featureType : featureTypes) { |
| 5103 | featureConfig.put(featureType, packageName); |
| 5104 | } |
| 5105 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5106 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5107 | } finally { |
| 5108 | Binder.restoreCallingIdentity(identity); |
| 5109 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5110 | } |
| 5111 | |
| 5112 | /** |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5113 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5114 | * |
| 5115 | * @param slotId The slot that the ImsService is associated with. |
| 5116 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5117 | * the device default. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5118 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5119 | * @return the package name of the ImsService configuration. |
| 5120 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5121 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5122 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5123 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5124 | TelephonyPermissions |
| 5125 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5126 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5127 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5128 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5129 | final long identity = Binder.clearCallingIdentity(); |
| 5130 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5131 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5132 | // may happen if the device does not support IMS. |
| 5133 | return ""; |
| 5134 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5135 | // TODO: change API to query RCS separately. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5136 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5137 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5138 | } finally { |
| 5139 | Binder.restoreCallingIdentity(identity); |
| 5140 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5141 | } |
| 5142 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5143 | /** |
| 5144 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5145 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5146 | * @param callback A callback with an integer containing the |
| 5147 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5148 | */ |
| 5149 | @Override |
| 5150 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5151 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5152 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5153 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5154 | "IMS not available on device."); |
| 5155 | } |
| 5156 | final long token = Binder.clearCallingIdentity(); |
| 5157 | try { |
| 5158 | int slotId = getSlotIndex(subId); |
| 5159 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5160 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5161 | + subId + "'"); |
| 5162 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5163 | } |
| 5164 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5165 | try { |
| 5166 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5167 | } catch (RemoteException e) { |
| 5168 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5169 | + "Ignore"); |
| 5170 | } |
| 5171 | }); |
| 5172 | } finally { |
| 5173 | Binder.restoreCallingIdentity(token); |
| 5174 | } |
| 5175 | } |
| 5176 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5177 | public void setImsRegistrationState(boolean registered) { |
| 5178 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5179 | |
| 5180 | final long identity = Binder.clearCallingIdentity(); |
| 5181 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5182 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5183 | } finally { |
| 5184 | Binder.restoreCallingIdentity(identity); |
| 5185 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5186 | } |
| 5187 | |
| 5188 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5189 | * Set the network selection mode to automatic. |
| 5190 | * |
| 5191 | */ |
| 5192 | @Override |
| 5193 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5194 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5195 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5196 | |
| 5197 | final long identity = Binder.clearCallingIdentity(); |
| 5198 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5199 | if (!isActiveSubscription(subId)) { |
| 5200 | return; |
| 5201 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5202 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 5203 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 5204 | } finally { |
| 5205 | Binder.restoreCallingIdentity(identity); |
| 5206 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5207 | } |
| 5208 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5209 | /** |
| 5210 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5211 | * |
| 5212 | * @param subId the id of the subscription. |
| 5213 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5214 | * the operator to attach to. |
| 5215 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5216 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5217 | * normal network selection next time. |
| 5218 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5219 | */ |
| 5220 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5221 | public boolean setNetworkSelectionModeManual( |
| 5222 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5223 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5224 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5225 | |
| 5226 | if (!isActiveSubscription(subId)) { |
| 5227 | return false; |
| 5228 | } |
| 5229 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5230 | final long identity = Binder.clearCallingIdentity(); |
| 5231 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5232 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5233 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5234 | if (DBG) { |
| 5235 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5236 | + " operator: " + operatorInfo); |
| 5237 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5238 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5239 | } finally { |
| 5240 | Binder.restoreCallingIdentity(identity); |
| 5241 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5242 | } |
| 5243 | |
| 5244 | /** |
| 5245 | * Scans for available networks. |
| 5246 | */ |
| 5247 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5248 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5249 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5250 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5251 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5252 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5253 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5254 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5255 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5256 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5257 | .setCallingPid(Binder.getCallingPid()) |
| 5258 | .setCallingUid(Binder.getCallingUid()) |
| 5259 | .setMethod("getCellNetworkScanResults") |
| 5260 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5261 | .build()); |
| 5262 | switch (locationResult) { |
| 5263 | case DENIED_HARD: |
| 5264 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5265 | case DENIED_SOFT: |
| 5266 | return null; |
| 5267 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5268 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5269 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5270 | try { |
| 5271 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5272 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5273 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5274 | } finally { |
| 5275 | Binder.restoreCallingIdentity(identity); |
| 5276 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5277 | } |
| 5278 | |
| 5279 | /** |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5280 | * Get the call forwarding info, given the call forwarding reason. |
| 5281 | */ |
| 5282 | @Override |
| 5283 | public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) { |
| 5284 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5285 | long identity = Binder.clearCallingIdentity(); |
| 5286 | try { |
| 5287 | if (DBG) { |
| 5288 | log("getCallForwarding: subId " + subId |
| 5289 | + " callForwardingReason" + callForwardingReason); |
| 5290 | } |
| 5291 | return (CallForwardingInfo) sendRequest( |
| 5292 | CMD_GET_CALL_FORWARDING, callForwardingReason, subId); |
| 5293 | } finally { |
| 5294 | Binder.restoreCallingIdentity(identity); |
| 5295 | } |
| 5296 | } |
| 5297 | |
| 5298 | /** |
| 5299 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5300 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5301 | */ |
| 5302 | @Override |
| 5303 | public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) { |
| 5304 | enforceModifyPermission(); |
| 5305 | long identity = Binder.clearCallingIdentity(); |
| 5306 | try { |
| 5307 | if (DBG) { |
| 5308 | log("setCallForwarding: subId " + subId |
| 5309 | + " callForwardingInfo" + callForwardingInfo); |
| 5310 | } |
| 5311 | return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId); |
| 5312 | } finally { |
| 5313 | Binder.restoreCallingIdentity(identity); |
| 5314 | } |
| 5315 | } |
| 5316 | |
| 5317 | /** |
| 5318 | * Get the call forwarding info, given the call forwarding reason. |
| 5319 | */ |
| 5320 | @Override |
| 5321 | public int getCallWaitingStatus(int subId) { |
| 5322 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5323 | long identity = Binder.clearCallingIdentity(); |
| 5324 | try { |
| 5325 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 5326 | return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId); |
| 5327 | } finally { |
| 5328 | Binder.restoreCallingIdentity(identity); |
| 5329 | } |
| 5330 | } |
| 5331 | |
| 5332 | /** |
| 5333 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5334 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5335 | */ |
| 5336 | @Override |
| 5337 | public boolean setCallWaitingStatus(int subId, boolean isEnable) { |
| 5338 | enforceModifyPermission(); |
| 5339 | long identity = Binder.clearCallingIdentity(); |
| 5340 | try { |
| 5341 | if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable); |
| 5342 | return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId); |
| 5343 | } finally { |
| 5344 | Binder.restoreCallingIdentity(identity); |
| 5345 | } |
| 5346 | } |
| 5347 | |
| 5348 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5349 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5350 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5351 | * @param subId id of the subscription |
| 5352 | * @param request contains the radio access networks with bands/channels to scan |
| 5353 | * @param messenger callback messenger for scan results or errors |
| 5354 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5355 | * @return the id of the requested scan which can be used to stop the scan. |
| 5356 | */ |
| 5357 | @Override |
| 5358 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5359 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5360 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5361 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5362 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5363 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5364 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5365 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5366 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5367 | .setCallingPid(Binder.getCallingPid()) |
| 5368 | .setCallingUid(Binder.getCallingUid()) |
| 5369 | .setMethod("requestNetworkScan") |
| 5370 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5371 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5372 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5373 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5374 | if (e != null) { |
| 5375 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5376 | throw e; |
| 5377 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5378 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5379 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5380 | } |
| 5381 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5382 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5383 | int callingUid = Binder.getCallingUid(); |
| 5384 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5385 | final long identity = Binder.clearCallingIdentity(); |
| 5386 | try { |
| 5387 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5388 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5389 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5390 | } finally { |
| 5391 | Binder.restoreCallingIdentity(identity); |
| 5392 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5393 | } |
| 5394 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5395 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5396 | NetworkScanRequest request, int subId) { |
| 5397 | boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid()) |
| 5398 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5399 | boolean hasNetworkScanPermission = |
| 5400 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5401 | == PERMISSION_GRANTED; |
| 5402 | |
| 5403 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5404 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5405 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5406 | } |
| 5407 | |
| 5408 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5409 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5410 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5411 | return new SecurityException("Specific channels must not be" |
| 5412 | + " scanned without location access."); |
| 5413 | } |
| 5414 | } |
| 5415 | } |
| 5416 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5417 | return null; |
| 5418 | } |
| 5419 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5420 | /** |
| 5421 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5422 | * |
| 5423 | * @param subId id of the subscription |
| 5424 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5425 | */ |
| 5426 | @Override |
| 5427 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5428 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5429 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5430 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5431 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5432 | final long identity = Binder.clearCallingIdentity(); |
| 5433 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5434 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5435 | } finally { |
| 5436 | Binder.restoreCallingIdentity(identity); |
| 5437 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5438 | } |
| 5439 | |
| 5440 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5441 | * Get the calculated preferred network type. |
| 5442 | * Used for debugging incorrect network type. |
| 5443 | * |
| 5444 | * @return the preferred network type, defined in RILConstants.java. |
| 5445 | */ |
| 5446 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5447 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5448 | final Phone defaultPhone = getDefaultPhone(); |
| 5449 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5450 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5451 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5452 | } |
| 5453 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5454 | final long identity = Binder.clearCallingIdentity(); |
| 5455 | try { |
| 5456 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5457 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5458 | } finally { |
| 5459 | Binder.restoreCallingIdentity(identity); |
| 5460 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5461 | } |
| 5462 | |
| 5463 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5464 | * Get the preferred network type. |
| 5465 | * Used for device configuration by some CDMA operators. |
| 5466 | * |
| 5467 | * @return the preferred network type, defined in RILConstants.java. |
| 5468 | */ |
| 5469 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5470 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5471 | TelephonyPermissions |
| 5472 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5473 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5474 | |
| 5475 | final long identity = Binder.clearCallingIdentity(); |
| 5476 | try { |
| 5477 | if (DBG) log("getPreferredNetworkType"); |
| 5478 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5479 | int networkType = (result != null ? result[0] : -1); |
| 5480 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5481 | return networkType; |
| 5482 | } finally { |
| 5483 | Binder.restoreCallingIdentity(identity); |
| 5484 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5485 | } |
| 5486 | |
| 5487 | /** |
| 5488 | * Set the preferred network type. |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5489 | * |
| 5490 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5491 | * @return true on success; false on any failure. |
| 5492 | */ |
| 5493 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5494 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5495 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5496 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5497 | |
| 5498 | final long identity = Binder.clearCallingIdentity(); |
| 5499 | try { |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5500 | Settings.Global.putInt(mApp.getContentResolver(), |
| 5501 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5502 | |
| 5503 | Boolean success = (Boolean) sendRequest( |
| 5504 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 5505 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 5506 | return success; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5507 | } finally { |
| 5508 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5509 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5510 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5511 | |
| 5512 | /** |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5513 | * Get the allowed network types that store in the telephony provider. |
| 5514 | * |
| 5515 | * @param subId the id of the subscription. |
| 5516 | * @return allowedNetworkTypes the allowed network types. |
| 5517 | */ |
| 5518 | @Override |
| 5519 | public long getAllowedNetworkTypes(int subId) { |
| 5520 | TelephonyPermissions |
| 5521 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5522 | mApp, subId, "getAllowedNetworkTypes"); |
| 5523 | |
| 5524 | final long identity = Binder.clearCallingIdentity(); |
| 5525 | try { |
| 5526 | return SubscriptionManager.getLongSubscriptionProperty( |
| 5527 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5528 | } finally { |
| 5529 | Binder.restoreCallingIdentity(identity); |
| 5530 | } |
| 5531 | } |
| 5532 | |
| 5533 | /** |
| 5534 | * Set the allowed network types. |
| 5535 | * |
| 5536 | * @param subId the id of the subscription. |
| 5537 | * @param allowedNetworkTypes the allowed network types. |
| 5538 | * @return true on success; false on any failure. |
| 5539 | */ |
| 5540 | @Override |
| 5541 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 5542 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5543 | mApp, subId, "setAllowedNetworkTypes"); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5544 | |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5545 | SubscriptionManager.setSubscriptionProperty(subId, |
| 5546 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 5547 | String.valueOf(allowedNetworkTypes)); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5548 | |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5549 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 5550 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5551 | RILConstants.PREFERRED_NETWORK_MODE); |
| 5552 | return setPreferredNetworkType(subId, preferredNetworkMode); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5553 | } |
| 5554 | |
| 5555 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5556 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5557 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5558 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 5559 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5560 | * @hide |
| 5561 | */ |
| 5562 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 5563 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5564 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5565 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5566 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5567 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5568 | if (phone != null) { |
| 5569 | return phone.hasMatchedTetherApnSetting(); |
| 5570 | } else { |
| 5571 | return false; |
| 5572 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5573 | } finally { |
| 5574 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5575 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5576 | } |
| 5577 | |
| 5578 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5579 | * Set mobile data enabled |
| 5580 | * Used by the user through settings etc to turn on/off mobile data |
| 5581 | * |
| 5582 | * @param enable {@code true} turn turn data on, else {@code false} |
| 5583 | */ |
| 5584 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5585 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5586 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5587 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5588 | |
| 5589 | final long identity = Binder.clearCallingIdentity(); |
| 5590 | try { |
| 5591 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5592 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5593 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5594 | if (phone != null) { |
| 5595 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5596 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5597 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5598 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5599 | } |
| 5600 | } finally { |
| 5601 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5602 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5603 | } |
| 5604 | |
| 5605 | /** |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 5606 | * Enable or disable always reporting signal strength changes from radio. |
| 5607 | * |
| 5608 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 5609 | */ |
| 5610 | @Override |
| 5611 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 5612 | enforceModifyPermission(); |
| 5613 | enforceSystemCaller(); |
| 5614 | |
| 5615 | final long identity = Binder.clearCallingIdentity(); |
| 5616 | final Phone phone = getPhone(subId); |
| 5617 | try { |
| 5618 | if (phone != null) { |
| 5619 | if (DBG) { |
| 5620 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 5621 | + " isEnable=" + isEnable); |
| 5622 | } |
| 5623 | phone.setAlwaysReportSignalStrength(isEnable); |
| 5624 | } else { |
| 5625 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 5626 | + subId); |
| 5627 | } |
| 5628 | } finally { |
| 5629 | Binder.restoreCallingIdentity(identity); |
| 5630 | } |
| 5631 | } |
| 5632 | |
| 5633 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5634 | * Get the user enabled state of Mobile Data. |
| 5635 | * |
| 5636 | * TODO: remove and use isUserDataEnabled. |
| 5637 | * This can't be removed now because some vendor codes |
| 5638 | * calls through ITelephony directly while they should |
| 5639 | * use TelephonyManager. |
| 5640 | * |
| 5641 | * @return true on enabled |
| 5642 | */ |
| 5643 | @Override |
| 5644 | public boolean getDataEnabled(int subId) { |
| 5645 | return isUserDataEnabled(subId); |
| 5646 | } |
| 5647 | |
| 5648 | /** |
| 5649 | * Get whether mobile data is enabled per user setting. |
| 5650 | * |
| 5651 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 5652 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5653 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 5654 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5655 | * |
| 5656 | * @return {@code true} if data is enabled else {@code false} |
| 5657 | */ |
| 5658 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5659 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5660 | try { |
| 5661 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 5662 | null); |
| 5663 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5664 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5665 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5666 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5667 | |
| 5668 | final long identity = Binder.clearCallingIdentity(); |
| 5669 | try { |
| 5670 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5671 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5672 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5673 | if (phone != null) { |
| 5674 | boolean retVal = phone.isUserDataEnabled(); |
| 5675 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5676 | return retVal; |
| 5677 | } else { |
| 5678 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5679 | return false; |
| 5680 | } |
| 5681 | } finally { |
| 5682 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5683 | } |
| 5684 | } |
| 5685 | |
| 5686 | /** |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5687 | * Checks if the device is capable of mobile data by considering whether whether the |
| 5688 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 5689 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5690 | * |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5691 | * @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] | 5692 | */ |
| 5693 | @Override |
| 5694 | public boolean isDataEnabled(int subId) { |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5695 | enforceReadPrivilegedPermission("isDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5696 | |
| 5697 | final long identity = Binder.clearCallingIdentity(); |
| 5698 | try { |
| 5699 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5700 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5701 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5702 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5703 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5704 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5705 | return retVal; |
| 5706 | } else { |
| 5707 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5708 | return false; |
| 5709 | } |
| 5710 | } finally { |
| 5711 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5712 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5713 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5714 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 5715 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5716 | Phone phone) { |
| 5717 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5718 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5719 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5720 | || subController == null) return privilegeFromSim; |
| 5721 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5722 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 5723 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 5724 | |
| 5725 | final long identity = Binder.clearCallingIdentity(); |
| 5726 | try { |
| 5727 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5728 | SubscriptionManager subManager = (SubscriptionManager) |
| 5729 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5730 | for (String pkg : packages) { |
| 5731 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 5732 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5733 | } |
| 5734 | } |
| 5735 | return privilegeFromSim; |
| 5736 | } finally { |
| 5737 | Binder.restoreCallingIdentity(identity); |
| 5738 | } |
| 5739 | } |
| 5740 | |
| 5741 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 5742 | String pkgName) { |
| 5743 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5744 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5745 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5746 | || subController == null) return privilegeFromSim; |
| 5747 | |
| 5748 | final long identity = Binder.clearCallingIdentity(); |
| 5749 | try { |
| 5750 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5751 | SubscriptionManager subManager = (SubscriptionManager) |
| 5752 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5753 | return subManager.canManageSubscription(subInfo, pkgName) |
| 5754 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 5755 | } finally { |
| 5756 | Binder.restoreCallingIdentity(identity); |
| 5757 | } |
| 5758 | } |
| 5759 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5760 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5761 | public int getCarrierPrivilegeStatus(int subId) { |
| 5762 | final Phone phone = getPhone(subId); |
| 5763 | if (phone == null) { |
| 5764 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 5765 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5766 | } |
| 5767 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5768 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 5769 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5770 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5771 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5772 | |
| 5773 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5774 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 5775 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5776 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5777 | |
| 5778 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5779 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5780 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5781 | final Phone phone = getPhone(subId); |
| 5782 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5783 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5784 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5785 | } |
| 5786 | UiccProfile profile = |
| 5787 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 5788 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5789 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5790 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5791 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5792 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5793 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 5794 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5795 | } |
| 5796 | |
| 5797 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5798 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 5799 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5800 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5801 | } |
| 5802 | |
| 5803 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 5804 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5805 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5806 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5807 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5808 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5809 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5810 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5811 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5812 | } |
| 5813 | |
| 5814 | @Override |
| 5815 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5816 | if (TextUtils.isEmpty(pkgName)) |
| 5817 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5818 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5819 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5820 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 5821 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 5822 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5823 | continue; |
| 5824 | } |
| 5825 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5826 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5827 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5828 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5829 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 5830 | break; |
| 5831 | } |
| 5832 | } |
| 5833 | |
| 5834 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5835 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 5836 | |
| 5837 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 5838 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 5839 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 5840 | loge("phoneId " + phoneId + " is not valid."); |
| 5841 | return null; |
| 5842 | } |
| 5843 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5844 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5845 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5846 | return null ; |
| 5847 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5848 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5849 | } |
| 5850 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5851 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5852 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5853 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5854 | List<String> privilegedPackages = new ArrayList<>(); |
| 5855 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5856 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 5857 | // has UICC in that slot. |
| 5858 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5859 | if (card.hasCarrierPrivilegeRules()) { |
| 5860 | if (packages == null) { |
| 5861 | // Only check packages in user 0 for now |
| 5862 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5863 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 5864 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 5865 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 5866 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5867 | } |
| 5868 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 5869 | PackageInfo pkgInfo = packages.get(p); |
| 5870 | if (pkgInfo != null && pkgInfo.packageName != null |
| 5871 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5872 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5873 | privilegedPackages.add(pkgInfo.packageName); |
| 5874 | } |
| 5875 | } |
| 5876 | } |
| 5877 | } |
| 5878 | return privilegedPackages; |
| 5879 | } |
| 5880 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5881 | @Override |
| 5882 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5883 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 5884 | |
| 5885 | final long identity = Binder.clearCallingIdentity(); |
| 5886 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5887 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5888 | try { |
| 5889 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5890 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 5891 | } |
| 5892 | } finally { |
| 5893 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5894 | } |
| 5895 | return privilegedPackages; |
| 5896 | } |
| 5897 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5898 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5899 | final Phone phone = getPhone(subId); |
| 5900 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5901 | if (card == null) { |
| 5902 | loge("getIccId: No UICC"); |
| 5903 | return null; |
| 5904 | } |
| 5905 | String iccId = card.getIccId(); |
| 5906 | if (TextUtils.isEmpty(iccId)) { |
| 5907 | loge("getIccId: ICC ID is null or empty."); |
| 5908 | return null; |
| 5909 | } |
| 5910 | return iccId; |
| 5911 | } |
| 5912 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5913 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5914 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 5915 | String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5916 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5917 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5918 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5919 | final long identity = Binder.clearCallingIdentity(); |
| 5920 | try { |
| 5921 | final String iccId = getIccId(subId); |
| 5922 | final Phone phone = getPhone(subId); |
| 5923 | if (phone == null) { |
| 5924 | return false; |
| 5925 | } |
| 5926 | final String subscriberId = phone.getSubscriberId(); |
| 5927 | |
| 5928 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 5929 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5930 | + subscriberId + " to " + number); |
| 5931 | } |
| 5932 | |
| 5933 | if (TextUtils.isEmpty(iccId)) { |
| 5934 | return false; |
| 5935 | } |
| 5936 | |
| 5937 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 5938 | |
| 5939 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5940 | if (alphaTag == null) { |
| 5941 | editor.remove(alphaTagPrefKey); |
| 5942 | } else { |
| 5943 | editor.putString(alphaTagPrefKey, alphaTag); |
| 5944 | } |
| 5945 | |
| 5946 | // Record both the line number and IMSI for this ICCID, since we need to |
| 5947 | // track all merged IMSIs based on line number |
| 5948 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5949 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 5950 | if (number == null) { |
| 5951 | editor.remove(numberPrefKey); |
| 5952 | editor.remove(subscriberPrefKey); |
| 5953 | } else { |
| 5954 | editor.putString(numberPrefKey, number); |
| 5955 | editor.putString(subscriberPrefKey, subscriberId); |
| 5956 | } |
| 5957 | |
| 5958 | editor.commit(); |
| 5959 | return true; |
| 5960 | } finally { |
| 5961 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5962 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5963 | } |
| 5964 | |
| 5965 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5966 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 5967 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 5968 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5969 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5970 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5971 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5972 | return null; |
| 5973 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5974 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5975 | final long identity = Binder.clearCallingIdentity(); |
| 5976 | try { |
| 5977 | String iccId = getIccId(subId); |
| 5978 | if (iccId != null) { |
| 5979 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 5980 | if (DBG_MERGE) { |
| 5981 | log("getLine1NumberForDisplay returning " |
| 5982 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 5983 | } |
| 5984 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 5985 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5986 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 5987 | return null; |
| 5988 | } finally { |
| 5989 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5990 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 5991 | } |
| 5992 | |
| 5993 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5994 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 5995 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5996 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5997 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5998 | return null; |
| 5999 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6000 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6001 | final long identity = Binder.clearCallingIdentity(); |
| 6002 | try { |
| 6003 | String iccId = getIccId(subId); |
| 6004 | if (iccId != null) { |
| 6005 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6006 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6007 | } |
| 6008 | return null; |
| 6009 | } finally { |
| 6010 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6011 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6012 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6013 | |
| 6014 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6015 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6016 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6017 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6018 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6019 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6020 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6021 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6022 | return null; |
| 6023 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6024 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6025 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6026 | // the process, where TelephonyManager was instantiated. |
| 6027 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6028 | final long identity = Binder.clearCallingIdentity(); |
| 6029 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6030 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6031 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6032 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6033 | |
| 6034 | // Figure out what subscribers are currently active |
| 6035 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6036 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6037 | // Only consider subs which match the current subId |
| 6038 | // This logic can be simplified. See b/131189269 for progress. |
| 6039 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6040 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6041 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6042 | |
| 6043 | // First pass, find a number override for an active subscriber |
| 6044 | String mergeNumber = null; |
| 6045 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6046 | for (String key : prefs.keySet()) { |
| 6047 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6048 | final String subscriberId = (String) prefs.get(key); |
| 6049 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6050 | final String iccId = key.substring( |
| 6051 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6052 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6053 | mergeNumber = (String) prefs.get(numberKey); |
| 6054 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6055 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6056 | + " for active subscriber " + subscriberId); |
| 6057 | } |
| 6058 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6059 | break; |
| 6060 | } |
| 6061 | } |
| 6062 | } |
| 6063 | } |
| 6064 | |
| 6065 | // Shortcut when no active merged subscribers |
| 6066 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6067 | return null; |
| 6068 | } |
| 6069 | |
| 6070 | // Second pass, find all subscribers under that line override |
| 6071 | final ArraySet<String> result = new ArraySet<>(); |
| 6072 | for (String key : prefs.keySet()) { |
| 6073 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6074 | final String number = (String) prefs.get(key); |
| 6075 | if (mergeNumber.equals(number)) { |
| 6076 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6077 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6078 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6079 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6080 | result.add(subscriberId); |
| 6081 | } |
| 6082 | } |
| 6083 | } |
| 6084 | } |
| 6085 | |
| 6086 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6087 | Arrays.sort(resultArray); |
| 6088 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6089 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6090 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6091 | } |
| 6092 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6093 | } finally { |
| 6094 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6095 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6096 | } |
| 6097 | |
| 6098 | @Override |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6099 | public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) { |
| 6100 | enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup"); |
| 6101 | |
| 6102 | final long identity = Binder.clearCallingIdentity(); |
| 6103 | try { |
| 6104 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6105 | TelephonyManager.class); |
| 6106 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6107 | if (subscriberId == null) { |
| 6108 | if (DBG) { |
| 6109 | log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId " |
| 6110 | + subId); |
| 6111 | } |
| 6112 | return null; |
| 6113 | } |
| 6114 | |
| 6115 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6116 | .getSubscriptionInfo(subId); |
| 6117 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6118 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6119 | if (groupUuid == null) { |
| 6120 | return new String[]{subscriberId}; |
| 6121 | } |
| 6122 | |
| 6123 | // Get all subscriberIds from the group. |
| 6124 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6125 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6126 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 6127 | null); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6128 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6129 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6130 | if (subscriberId != null) { |
| 6131 | mergedSubscriberIds.add(subscriberId); |
| 6132 | } |
| 6133 | } |
| 6134 | |
| 6135 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6136 | } finally { |
| 6137 | Binder.restoreCallingIdentity(identity); |
| 6138 | |
| 6139 | } |
| 6140 | } |
| 6141 | |
| 6142 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6143 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6144 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6145 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6146 | |
| 6147 | final long identity = Binder.clearCallingIdentity(); |
| 6148 | try { |
| 6149 | final Phone phone = getPhone(subId); |
| 6150 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6151 | } finally { |
| 6152 | Binder.restoreCallingIdentity(identity); |
| 6153 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6154 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6155 | |
| 6156 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6157 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6158 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6159 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6160 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6161 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6162 | |
| 6163 | final long identity = Binder.clearCallingIdentity(); |
| 6164 | try { |
| 6165 | final Phone phone = getPhone(subId); |
| 6166 | if (phone == null) { |
| 6167 | return false; |
| 6168 | } |
| 6169 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6170 | cdmaNonRoamingList); |
| 6171 | } finally { |
| 6172 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6173 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6174 | } |
| 6175 | |
| 6176 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6177 | @Deprecated |
| 6178 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6179 | enforceModifyPermission(); |
| 6180 | |
| 6181 | int returnValue = 0; |
| 6182 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6183 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6184 | if(result.exception == null) { |
| 6185 | if (result.result != null) { |
| 6186 | byte[] responseData = (byte[])(result.result); |
| 6187 | if(responseData.length > oemResp.length) { |
| 6188 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6189 | responseData.length + "bytes. Buffer Size is " + |
| 6190 | oemResp.length + "bytes."); |
| 6191 | } |
| 6192 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6193 | returnValue = responseData.length; |
| 6194 | } |
| 6195 | } else { |
| 6196 | CommandException ex = (CommandException) result.exception; |
| 6197 | returnValue = ex.getCommandError().ordinal(); |
| 6198 | if(returnValue > 0) returnValue *= -1; |
| 6199 | } |
| 6200 | } catch (RuntimeException e) { |
| 6201 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6202 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6203 | if(returnValue > 0) returnValue *= -1; |
| 6204 | } |
| 6205 | |
| 6206 | return returnValue; |
| 6207 | } |
| 6208 | |
| 6209 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6210 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6211 | try { |
| 6212 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6213 | } catch (RuntimeException e) { |
| 6214 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6215 | } |
| 6216 | } |
| 6217 | |
| 6218 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6219 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6220 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6221 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6222 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6223 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6224 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6225 | final long identity = Binder.clearCallingIdentity(); |
| 6226 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6227 | TelephonyPermissions |
| 6228 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6229 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6230 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6231 | } finally { |
| 6232 | Binder.restoreCallingIdentity(identity); |
| 6233 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6234 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6235 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6236 | |
| 6237 | @Override |
| 6238 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6239 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6240 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6241 | |
| 6242 | final long identity = Binder.clearCallingIdentity(); |
| 6243 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6244 | ImsManager.getInstance(defaultPhone.getContext(), |
| 6245 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6246 | } finally { |
| 6247 | Binder.restoreCallingIdentity(identity); |
| 6248 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6249 | } |
| 6250 | |
| 6251 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6252 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6253 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6254 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 6255 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6256 | return false; |
| 6257 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6258 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6259 | final long identity = Binder.clearCallingIdentity(); |
| 6260 | try { |
| 6261 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 6262 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 6263 | // In the long run, we may instead need to check if there exists a connection service |
| 6264 | // which can support video calling. |
| 6265 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6266 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6267 | return imsManager.isVtEnabledByPlatform() |
| 6268 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 6269 | && imsManager.isVtEnabledByUser(); |
| 6270 | } finally { |
| 6271 | Binder.restoreCallingIdentity(identity); |
| 6272 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6273 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 6274 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6275 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6276 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 6277 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6278 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6279 | mApp, subId, callingPackage, callingFeatureId, |
| 6280 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6281 | return false; |
| 6282 | } |
| 6283 | |
| 6284 | final long identity = Binder.clearCallingIdentity(); |
| 6285 | try { |
| 6286 | CarrierConfigManager configManager = |
| 6287 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6288 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6289 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 6290 | } finally { |
| 6291 | Binder.restoreCallingIdentity(identity); |
| 6292 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6293 | } |
| 6294 | |
| 6295 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6296 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6297 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6298 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6299 | return false; |
| 6300 | } |
| 6301 | |
| 6302 | final long identity = Binder.clearCallingIdentity(); |
| 6303 | try { |
| 6304 | CarrierConfigManager configManager = |
| 6305 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6306 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6307 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 6308 | } finally { |
| 6309 | Binder.restoreCallingIdentity(identity); |
| 6310 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6311 | } |
| 6312 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6313 | @Override |
| 6314 | public boolean isTtyModeSupported() { |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6315 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 6316 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6317 | } |
| 6318 | |
| 6319 | @Override |
| 6320 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6321 | final long identity = Binder.clearCallingIdentity(); |
| 6322 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6323 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6324 | } finally { |
| 6325 | Binder.restoreCallingIdentity(identity); |
| 6326 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6327 | } |
| 6328 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6329 | /** |
| 6330 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 6331 | * support for the feature and device firmware support. |
| 6332 | * |
| 6333 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 6334 | */ |
| 6335 | @Override |
| 6336 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6337 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6338 | final Phone phone = getPhone(subscriptionId); |
| 6339 | if (phone == null) { |
| 6340 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 6341 | return false; |
| 6342 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6343 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6344 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6345 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 6346 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6347 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6348 | return isCarrierSupported && isDeviceSupported; |
| 6349 | } finally { |
| 6350 | Binder.restoreCallingIdentity(identity); |
| 6351 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 6352 | } |
| 6353 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6354 | /** |
Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 6355 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 6356 | * RTT setting, will return true if the device and carrier both support RTT. |
| 6357 | * 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] | 6358 | */ |
| 6359 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6360 | final long identity = Binder.clearCallingIdentity(); |
| 6361 | try { |
Hall Liu | 63767ec | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 6362 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 6363 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 6364 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 6365 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 6366 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 6367 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6368 | } finally { |
| 6369 | Binder.restoreCallingIdentity(identity); |
| 6370 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 6371 | } |
| 6372 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6373 | @Deprecated |
| 6374 | @Override |
| 6375 | public String getDeviceId(String callingPackage) { |
| 6376 | return getDeviceIdWithFeature(callingPackage, null); |
| 6377 | } |
| 6378 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6379 | /** |
| 6380 | * Returns the unique device ID of phone, for example, the IMEI for |
| 6381 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 6382 | * |
| 6383 | * <p>Requires Permission: |
| 6384 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 6385 | */ |
| 6386 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6387 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6388 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6389 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6390 | return null; |
| 6391 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6392 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 6393 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6394 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6395 | return null; |
| 6396 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6397 | |
| 6398 | final long identity = Binder.clearCallingIdentity(); |
| 6399 | try { |
| 6400 | return phone.getDeviceId(); |
| 6401 | } finally { |
| 6402 | Binder.restoreCallingIdentity(identity); |
| 6403 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6404 | } |
| 6405 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6406 | /** |
| 6407 | * {@hide} |
| 6408 | * Returns the IMS Registration Status on a particular subid |
| 6409 | * |
| 6410 | * @param subId |
| 6411 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6412 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6413 | Phone phone = getPhone(subId); |
| 6414 | if (phone != null) { |
| 6415 | return phone.isImsRegistered(); |
| 6416 | } else { |
| 6417 | return false; |
| 6418 | } |
| 6419 | } |
| 6420 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6421 | @Override |
| 6422 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6423 | final long identity = Binder.clearCallingIdentity(); |
| 6424 | try { |
| 6425 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 6426 | } finally { |
| 6427 | Binder.restoreCallingIdentity(identity); |
| 6428 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6429 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 6430 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6431 | @Override |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6432 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6433 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6434 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6435 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6436 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6437 | } |
| 6438 | final long identity = Binder.clearCallingIdentity(); |
| 6439 | try { |
| 6440 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 6441 | } finally { |
| 6442 | Binder.restoreCallingIdentity(identity); |
| 6443 | } |
| 6444 | } |
| 6445 | |
| 6446 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6447 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 6448 | final long identity = Binder.clearCallingIdentity(); |
| 6449 | try { |
| 6450 | Phone phone = getPhone(subscriptionId); |
| 6451 | if (phone == null) { |
| 6452 | return null; |
| 6453 | } |
| 6454 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 6455 | } finally { |
| 6456 | Binder.restoreCallingIdentity(identity); |
| 6457 | } |
| 6458 | } |
| 6459 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6460 | /** |
| 6461 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6462 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6463 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6464 | final long identity = Binder.clearCallingIdentity(); |
| 6465 | try { |
| 6466 | Phone phone = getPhone(subId); |
| 6467 | if (phone != null) { |
| 6468 | return phone.isWifiCallingEnabled(); |
| 6469 | } else { |
| 6470 | return false; |
| 6471 | } |
| 6472 | } finally { |
| 6473 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6474 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6475 | } |
| 6476 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6477 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6478 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6479 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6480 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6481 | final long identity = Binder.clearCallingIdentity(); |
| 6482 | try { |
| 6483 | Phone phone = getPhone(subId); |
| 6484 | if (phone != null) { |
| 6485 | return phone.isVideoEnabled(); |
| 6486 | } else { |
| 6487 | return false; |
| 6488 | } |
| 6489 | } finally { |
| 6490 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6491 | } |
| 6492 | } |
| 6493 | |
| 6494 | /** |
| 6495 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 6496 | * defined in {@link ImsRegistrationImplBase}. |
| 6497 | */ |
| 6498 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6499 | final long identity = Binder.clearCallingIdentity(); |
| 6500 | try { |
| 6501 | Phone phone = getPhone(subId); |
| 6502 | if (phone != null) { |
| 6503 | return phone.getImsRegistrationTech(); |
| 6504 | } else { |
| 6505 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 6506 | } |
| 6507 | } finally { |
| 6508 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6509 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6510 | } |
| 6511 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6512 | @Override |
| 6513 | public void factoryReset(int subId) { |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 6514 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6515 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 6516 | return; |
| 6517 | } |
| 6518 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6519 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6520 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6521 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6522 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 6523 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6524 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6525 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6526 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6527 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 6528 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6529 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6530 | // There has been issues when Sms raw table somehow stores orphan |
| 6531 | // fragments. They lead to garbled message when new fragments come |
| 6532 | // in and combined with those stale ones. In case this happens again, |
| 6533 | // user can reset all network settings which will clean up this table. |
| 6534 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6535 | // Clean up IMS settings as well here. |
| 6536 | int slotId = getSlotIndex(subId); |
| 6537 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6538 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 6539 | } |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 6540 | |
| 6541 | // Erase modem config if erase modem on network setting is enabled. |
| 6542 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 6543 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 6544 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 6545 | sendEraseModemConfig(getDefaultPhone()); |
| 6546 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6547 | } finally { |
| 6548 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6549 | } |
| 6550 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6551 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6552 | private void cleanUpSmsRawTable(Context context) { |
| 6553 | ContentResolver resolver = context.getContentResolver(); |
| 6554 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 6555 | resolver.delete(uri, null, null); |
| 6556 | } |
| 6557 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6558 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6559 | public String getSimLocaleForSubscriber(int subId) { |
| 6560 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 6561 | final Phone phone = getPhone(subId); |
| 6562 | if (phone == null) { |
| 6563 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 6564 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6565 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6566 | final long identity = Binder.clearCallingIdentity(); |
| 6567 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6568 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6569 | phone.getContext().getOpPackageName(), null); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 6570 | if (info == null) { |
| 6571 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 6572 | return null; |
| 6573 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6574 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 6575 | // preferences (EF-PL and EF-LI)... |
| 6576 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6577 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6578 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 6579 | if (localeFromDefaultSim != null) { |
| 6580 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 6581 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 6582 | + localeFromDefaultSim); |
| 6583 | return localeFromDefaultSim.toLanguageTag(); |
| 6584 | } else { |
| 6585 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6586 | } |
| 6587 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6588 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6589 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 6590 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 6591 | // the SIM and carrier preferences does not include a country we add the country |
| 6592 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 6593 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6594 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6595 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6596 | return mccLocale.toLanguageTag(); |
| 6597 | } |
| 6598 | |
| 6599 | if (DBG) log("No locale found - returning null"); |
| 6600 | return null; |
| 6601 | } finally { |
| 6602 | Binder.restoreCallingIdentity(identity); |
| 6603 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6604 | } |
| 6605 | |
| 6606 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6607 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
| 6608 | null); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6609 | } |
| 6610 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6611 | /** |
| 6612 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 6613 | */ |
| 6614 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6615 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
| 6616 | null); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6617 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6618 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6619 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6620 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6621 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6622 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6623 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 6624 | * representing the state of the modem. |
| 6625 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6626 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 6627 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6628 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6629 | */ |
| 6630 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6631 | public void requestModemActivityInfo(ResultReceiver result) { |
| 6632 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6633 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6634 | |
| 6635 | final long identity = Binder.clearCallingIdentity(); |
| 6636 | try { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 6637 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6638 | } finally { |
| 6639 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6640 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6641 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6642 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6643 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 6644 | // less than total activity duration. |
| 6645 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 6646 | if (info == null) { |
| 6647 | return false; |
| 6648 | } |
| 6649 | int activityDurationMs = |
| 6650 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 6651 | int totalTxTimeMs = 0; |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6652 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6653 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 6654 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6655 | } |
| 6656 | return (info.isValid() |
| 6657 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 6658 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6659 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6660 | && (totalTxTimeMs <= activityDurationMs)); |
| 6661 | } |
| 6662 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6663 | /** |
| 6664 | * {@hide} |
| 6665 | * Returns the service state information on specified subscription. |
| 6666 | */ |
| 6667 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6668 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 6669 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6670 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6671 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6672 | return null; |
| 6673 | } |
| 6674 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6675 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 6676 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6677 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6678 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6679 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6680 | .setCallingPid(Binder.getCallingPid()) |
| 6681 | .setCallingUid(Binder.getCallingUid()) |
| 6682 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6683 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6684 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6685 | .build()); |
| 6686 | |
| 6687 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 6688 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6689 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6690 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6691 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6692 | .setCallingPid(Binder.getCallingPid()) |
| 6693 | .setCallingUid(Binder.getCallingUid()) |
| 6694 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6695 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6696 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6697 | .build()); |
| 6698 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 6699 | boolean hasFinePermission = |
| 6700 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6701 | boolean hasCoarsePermission = |
| 6702 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6703 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6704 | final long identity = Binder.clearCallingIdentity(); |
| 6705 | try { |
| 6706 | final Phone phone = getPhone(subId); |
| 6707 | if (phone == null) { |
| 6708 | return null; |
| 6709 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6710 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6711 | ServiceState ss = phone.getServiceState(); |
| 6712 | |
| 6713 | // Scrub out the location info in ServiceState depending on what level of access |
| 6714 | // the caller has. |
| 6715 | if (hasFinePermission) return ss; |
Malcolm Chen | db33797 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 6716 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 6717 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6718 | } finally { |
| 6719 | Binder.restoreCallingIdentity(identity); |
| 6720 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6721 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6722 | |
| 6723 | /** |
| 6724 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 6725 | * |
| 6726 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6727 | * voicemail ringtone. |
| 6728 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 6729 | * PhoneAccount. |
| 6730 | */ |
| 6731 | @Override |
| 6732 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6733 | final long identity = Binder.clearCallingIdentity(); |
| 6734 | try { |
| 6735 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6736 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6737 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6738 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6739 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6740 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 6741 | } finally { |
| 6742 | Binder.restoreCallingIdentity(identity); |
| 6743 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6744 | } |
| 6745 | |
| 6746 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6747 | * Sets the per-account voicemail ringtone. |
| 6748 | * |
| 6749 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6750 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6751 | * |
| 6752 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6753 | * voicemail ringtone. |
| 6754 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 6755 | * PhoneAccount. |
| 6756 | */ |
| 6757 | @Override |
| 6758 | public void setVoicemailRingtoneUri(String callingPackage, |
| 6759 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6760 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6761 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6762 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6763 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6764 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6765 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6766 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6767 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6768 | |
| 6769 | final long identity = Binder.clearCallingIdentity(); |
| 6770 | try { |
| 6771 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6772 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6773 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6774 | } |
| 6775 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 6776 | } finally { |
| 6777 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6778 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6779 | } |
| 6780 | |
| 6781 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6782 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 6783 | * |
| 6784 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6785 | * voicemail vibration setting. |
| 6786 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 6787 | */ |
| 6788 | @Override |
| 6789 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6790 | final long identity = Binder.clearCallingIdentity(); |
| 6791 | try { |
| 6792 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6793 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6794 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6795 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6796 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6797 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 6798 | } finally { |
| 6799 | Binder.restoreCallingIdentity(identity); |
| 6800 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6801 | } |
| 6802 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6803 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6804 | * Sets the per-account voicemail vibration. |
| 6805 | * |
| 6806 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6807 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6808 | * |
| 6809 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6810 | * voicemail vibration setting. |
| 6811 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 6812 | * specific PhoneAccount. |
| 6813 | */ |
| 6814 | @Override |
| 6815 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 6816 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6817 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6818 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6819 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6820 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6821 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6822 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6823 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6824 | } |
| 6825 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6826 | final long identity = Binder.clearCallingIdentity(); |
| 6827 | try { |
| 6828 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6829 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6830 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6831 | } |
| 6832 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 6833 | } finally { |
| 6834 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6835 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6836 | } |
| 6837 | |
| 6838 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6839 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 6840 | * |
| 6841 | * @throws SecurityException if the caller does not have the required permission |
| 6842 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6843 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6844 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6845 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6846 | } |
| 6847 | |
| 6848 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6849 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 6850 | * permission. |
| 6851 | * |
| 6852 | * @throws SecurityException if the caller does not have the required permission |
| 6853 | */ |
| 6854 | private void enforceSendSmsPermission() { |
| 6855 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 6856 | } |
| 6857 | |
| 6858 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6859 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6860 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6861 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6862 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6863 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6864 | final long identity = Binder.clearCallingIdentity(); |
| 6865 | try { |
| 6866 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6867 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6868 | if (componentName == null) { |
| 6869 | throw new SecurityException( |
| 6870 | "Caller not current active visual voicemail package[null]"); |
| 6871 | } |
| 6872 | String vvmPackage = componentName.getPackageName(); |
| 6873 | if (!callingPackage.equals(vvmPackage)) { |
| 6874 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 6875 | + vvmPackage + "]"); |
| 6876 | } |
| 6877 | } finally { |
| 6878 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6879 | } |
| 6880 | } |
| 6881 | |
| 6882 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6883 | * Return the application ID for the app type. |
| 6884 | * |
| 6885 | * @param subId the subscription ID that this request applies to. |
| 6886 | * @param appType the uicc app type. |
| 6887 | * @return Application ID for specificied app type, or null if no uicc. |
| 6888 | */ |
| 6889 | @Override |
| 6890 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6891 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6892 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6893 | |
| 6894 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6895 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6896 | if (phone == null) { |
| 6897 | return null; |
| 6898 | } |
| 6899 | String aid = null; |
| 6900 | try { |
| 6901 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 6902 | .getApplicationByType(appType).getAid(); |
| 6903 | } catch (Exception e) { |
| 6904 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 6905 | } |
| 6906 | return aid; |
| 6907 | } finally { |
| 6908 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6909 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6910 | } |
| 6911 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6912 | /** |
| 6913 | * Return the Electronic Serial Number. |
| 6914 | * |
| 6915 | * @param subId the subscription ID that this request applies to. |
| 6916 | * @return ESN or null if error. |
| 6917 | */ |
| 6918 | @Override |
| 6919 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6920 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6921 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6922 | |
| 6923 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6924 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6925 | if (phone == null) { |
| 6926 | return null; |
| 6927 | } |
| 6928 | String esn = null; |
| 6929 | try { |
| 6930 | esn = phone.getEsn(); |
| 6931 | } catch (Exception e) { |
| 6932 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 6933 | } |
| 6934 | return esn; |
| 6935 | } finally { |
| 6936 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6937 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6938 | } |
| 6939 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6940 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6941 | * Return the Preferred Roaming List Version. |
| 6942 | * |
| 6943 | * @param subId the subscription ID that this request applies to. |
| 6944 | * @return PRLVersion or null if error. |
| 6945 | */ |
| 6946 | @Override |
| 6947 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6948 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6949 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6950 | |
| 6951 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6952 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6953 | if (phone == null) { |
| 6954 | return null; |
| 6955 | } |
| 6956 | String cdmaPrlVersion = null; |
| 6957 | try { |
| 6958 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 6959 | } catch (Exception e) { |
| 6960 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 6961 | } |
| 6962 | return cdmaPrlVersion; |
| 6963 | } finally { |
| 6964 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6965 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6966 | } |
| 6967 | |
| 6968 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6969 | * Get snapshot of Telephony histograms |
| 6970 | * @return List of Telephony histograms |
| 6971 | * @hide |
| 6972 | */ |
| 6973 | @Override |
| 6974 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6975 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6976 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6977 | |
| 6978 | final long identity = Binder.clearCallingIdentity(); |
| 6979 | try { |
| 6980 | return RIL.getTelephonyRILTimingHistograms(); |
| 6981 | } finally { |
| 6982 | Binder.restoreCallingIdentity(identity); |
| 6983 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6984 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6985 | |
| 6986 | /** |
| 6987 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6988 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 6989 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6990 | * Require system privileges. In the future we may add this to carrier APIs. |
| 6991 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6992 | * @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] | 6993 | */ |
| 6994 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 6995 | @TelephonyManager.SetCarrierRestrictionResult |
| 6996 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 6997 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6998 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 6999 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7000 | if (carrierRestrictionRules == null) { |
| 7001 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7002 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7003 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7004 | final long identity = Binder.clearCallingIdentity(); |
| 7005 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7006 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7007 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7008 | } finally { |
| 7009 | Binder.restoreCallingIdentity(identity); |
| 7010 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7011 | } |
| 7012 | |
| 7013 | /** |
| 7014 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7015 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7016 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7017 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7018 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7019 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7020 | */ |
| 7021 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7022 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7023 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7024 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7025 | |
| 7026 | final long identity = Binder.clearCallingIdentity(); |
| 7027 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7028 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7029 | if (response instanceof CarrierRestrictionRules) { |
| 7030 | return (CarrierRestrictionRules) response; |
| 7031 | } |
| 7032 | // Response is an Exception of some kind, |
| 7033 | // which is signalled to the user as a NULL retval |
| 7034 | return null; |
| 7035 | } catch (Exception e) { |
| 7036 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7037 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7038 | } finally { |
| 7039 | Binder.restoreCallingIdentity(identity); |
| 7040 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7041 | } |
| 7042 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7043 | /** |
| 7044 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 7045 | * @param subId the subscription ID that this action applies to. |
| 7046 | * @param enabled control enable or disable metered apns. |
| 7047 | * {@hide} |
| 7048 | */ |
| 7049 | @Override |
| 7050 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 7051 | enforceModifyPermission(); |
| 7052 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7053 | |
| 7054 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7055 | if (phone == null) { |
| 7056 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 7057 | return; |
| 7058 | } |
| 7059 | try { |
| 7060 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7061 | } catch (Exception e) { |
| 7062 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7063 | } finally { |
| 7064 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7065 | } |
| 7066 | } |
| 7067 | |
| 7068 | /** |
| 7069 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7070 | * @param subId the subscription ID that this action applies to. |
| 7071 | * @param enabled control enable or disable radio. |
| 7072 | * {@hide} |
| 7073 | */ |
| 7074 | @Override |
| 7075 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7076 | enforceModifyPermission(); |
| 7077 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7078 | |
| 7079 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7080 | if (phone == null) { |
| 7081 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7082 | return; |
| 7083 | } |
| 7084 | try { |
| 7085 | phone.carrierActionSetRadioEnabled(enabled); |
| 7086 | } catch (Exception e) { |
| 7087 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7088 | } finally { |
| 7089 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7090 | } |
| 7091 | } |
| 7092 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7093 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7094 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7095 | * network status based on which carrier apps could apply actions accordingly, |
| 7096 | * enable/disable default url handler for example. |
| 7097 | * |
| 7098 | * @param subId the subscription ID that this action applies to. |
| 7099 | * @param report control start/stop reporting the default network status. |
| 7100 | * {@hide} |
| 7101 | */ |
| 7102 | @Override |
| 7103 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7104 | enforceModifyPermission(); |
| 7105 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7106 | |
| 7107 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7108 | if (phone == null) { |
| 7109 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7110 | return; |
| 7111 | } |
| 7112 | try { |
| 7113 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7114 | } catch (Exception e) { |
| 7115 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7116 | } finally { |
| 7117 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7118 | } |
| 7119 | } |
| 7120 | |
| 7121 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7122 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7123 | * @param subId the subscription ID that this action applies to. |
| 7124 | * {@hide} |
| 7125 | */ |
| 7126 | @Override |
| 7127 | public void carrierActionResetAll(int subId) { |
| 7128 | enforceModifyPermission(); |
| 7129 | final Phone phone = getPhone(subId); |
| 7130 | if (phone == null) { |
| 7131 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7132 | return; |
| 7133 | } |
| 7134 | try { |
| 7135 | phone.carrierActionResetAll(); |
| 7136 | } catch (Exception e) { |
| 7137 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7138 | } |
| 7139 | } |
| 7140 | |
| 7141 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7142 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7143 | * bug report is being generated. |
| 7144 | */ |
| 7145 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7146 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7147 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7148 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7149 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7150 | + Binder.getCallingPid() |
| 7151 | + ", uid=" + Binder.getCallingUid() |
| 7152 | + "without permission " |
| 7153 | + android.Manifest.permission.DUMP); |
| 7154 | return; |
| 7155 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7156 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7157 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7158 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7159 | @Override |
| 7160 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 7161 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 7162 | throws RemoteException { |
Torbjorn Eklund | 1050cb0 | 2018-11-16 14:05:38 +0100 | [diff] [blame] | 7163 | (new TelephonyShellCommand(this, getDefaultPhone().getContext())) |
| 7164 | .exec(this, in, out, err, args, callback, resultReceiver); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7165 | } |
| 7166 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7167 | /** |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7168 | * Policy control of data connection. Usually used when data limit is passed. |
| 7169 | * @param enabled True if enabling the data, otherwise disabling. |
| 7170 | * @param subId Subscription index |
| 7171 | * {@hide} |
| 7172 | */ |
| 7173 | @Override |
| 7174 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 7175 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7176 | |
| 7177 | final long identity = Binder.clearCallingIdentity(); |
| 7178 | try { |
| 7179 | Phone phone = getPhone(subId); |
| 7180 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 7181 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7182 | } |
| 7183 | } finally { |
| 7184 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7185 | } |
| 7186 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7187 | |
| 7188 | /** |
| 7189 | * Get Client request stats |
| 7190 | * @return List of Client Request Stats |
| 7191 | * @hide |
| 7192 | */ |
| 7193 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7194 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7195 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7196 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7197 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7198 | return null; |
| 7199 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7200 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7201 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7202 | final long identity = Binder.clearCallingIdentity(); |
| 7203 | try { |
| 7204 | if (phone != null) { |
| 7205 | return phone.getClientRequestStats(); |
| 7206 | } |
| 7207 | |
| 7208 | return null; |
| 7209 | } finally { |
| 7210 | Binder.restoreCallingIdentity(identity); |
| 7211 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7212 | } |
| 7213 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7214 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7215 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7216 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7217 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7218 | |
| 7219 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7220 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7221 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7222 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7223 | * @param state State of SIM (power down, power up, pass through) |
| 7224 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7225 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7226 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7227 | * |
| 7228 | **/ |
| 7229 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7230 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7231 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7232 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7233 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7234 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7235 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7236 | final long identity = Binder.clearCallingIdentity(); |
| 7237 | try { |
| 7238 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7239 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7240 | } |
| 7241 | } finally { |
| 7242 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7243 | } |
| 7244 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7245 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7246 | private boolean isUssdApiAllowed(int subId) { |
| 7247 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7248 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7249 | if (configManager == null) { |
| 7250 | return false; |
| 7251 | } |
| 7252 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 7253 | if (pb == null) { |
| 7254 | return false; |
| 7255 | } |
| 7256 | return pb.getBoolean( |
| 7257 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 7258 | } |
| 7259 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7260 | /** |
| 7261 | * Check if phone is in emergency callback mode |
| 7262 | * @return true if phone is in emergency callback mode |
| 7263 | * @param subId sub id |
| 7264 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 7265 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7266 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7267 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7268 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7269 | |
| 7270 | final long identity = Binder.clearCallingIdentity(); |
| 7271 | try { |
| 7272 | if (phone != null) { |
| 7273 | return phone.isInEcm(); |
| 7274 | } else { |
| 7275 | return false; |
| 7276 | } |
| 7277 | } finally { |
| 7278 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7279 | } |
| 7280 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7281 | |
| 7282 | /** |
| 7283 | * Get the current signal strength information for the given subscription. |
| 7284 | * Because this information is not updated when the device is in a low power state |
| 7285 | * it should not be relied-upon to be current. |
| 7286 | * @param subId Subscription index |
| 7287 | * @return the most recent cached signal strength info from the modem |
| 7288 | */ |
| 7289 | @Override |
| 7290 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7291 | final long identity = Binder.clearCallingIdentity(); |
| 7292 | try { |
| 7293 | Phone p = getPhone(subId); |
| 7294 | if (p == null) { |
| 7295 | return null; |
| 7296 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7297 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7298 | return p.getSignalStrength(); |
| 7299 | } finally { |
| 7300 | Binder.restoreCallingIdentity(identity); |
| 7301 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7302 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7303 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7304 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7305 | * Get the current modem radio state for the given slot. |
| 7306 | * @param slotIndex slot index. |
| 7307 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7308 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7309 | * @return the current radio power state from the modem |
| 7310 | */ |
| 7311 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7312 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7313 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7314 | if (phone != null) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7315 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 7316 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7317 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7318 | } |
| 7319 | |
| 7320 | final long identity = Binder.clearCallingIdentity(); |
| 7321 | try { |
| 7322 | return phone.getRadioPowerState(); |
| 7323 | } finally { |
| 7324 | Binder.restoreCallingIdentity(identity); |
| 7325 | } |
| 7326 | } |
| 7327 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7328 | } |
| 7329 | |
| 7330 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7331 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 7332 | * |
| 7333 | * <p>Requires one of the following permissions: |
| 7334 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 7335 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 7336 | * privileges. |
| 7337 | * |
| 7338 | * @param subId subscription id |
| 7339 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 7340 | * {@code false}. |
| 7341 | */ |
| 7342 | @Override |
| 7343 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7344 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7345 | null /* message */); |
| 7346 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7347 | boolean isEnabled = false; |
| 7348 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7349 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7350 | Phone phone = getPhone(subId); |
| 7351 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7352 | } catch (Exception e) { |
| 7353 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 7354 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7355 | } finally { |
| 7356 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7357 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7358 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7359 | } |
| 7360 | |
| 7361 | |
| 7362 | /** |
| 7363 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 7364 | * |
| 7365 | * <p> Requires permission: |
| 7366 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 7367 | * privileges. |
| 7368 | * |
| 7369 | * @param subId subscription id |
| 7370 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 7371 | */ |
| 7372 | @Override |
| 7373 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7374 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7375 | mApp, subId, "setDataRoamingEnabled"); |
| 7376 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7377 | final long identity = Binder.clearCallingIdentity(); |
| 7378 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7379 | Phone phone = getPhone(subId); |
| 7380 | if (phone != null) { |
| 7381 | phone.setDataRoamingEnabled(isEnabled); |
| 7382 | } |
| 7383 | } finally { |
| 7384 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7385 | } |
| 7386 | } |
| 7387 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7388 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7389 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 7390 | TelephonyPermissions |
| 7391 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7392 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 7393 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7394 | boolean isAllowed = true; |
| 7395 | final long identity = Binder.clearCallingIdentity(); |
| 7396 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7397 | Phone phone = getPhone(subId); |
| 7398 | if (phone != null) { |
| 7399 | isAllowed = phone.isCspPlmnEnabled(); |
| 7400 | } |
| 7401 | } finally { |
| 7402 | Binder.restoreCallingIdentity(identity); |
| 7403 | } |
| 7404 | return isAllowed; |
| 7405 | } |
| 7406 | |
| 7407 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7408 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | a39e6c1 | 2020-03-04 13:59:23 -0800 | [diff] [blame] | 7409 | try { |
| 7410 | PackageManager pm = mApp.getPackageManager(); |
| 7411 | if (Binder.getCallingUid() != pm.getPackageUid(callingPackage, 0)) { |
| 7412 | throw new SecurityException("Calling package " + callingPackage + " does not match " |
| 7413 | + "calling UID"); |
| 7414 | } |
| 7415 | } catch (PackageManager.NameNotFoundException e) { |
| 7416 | throw new SecurityException("Invalid calling package. e=" + e); |
| 7417 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7418 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7419 | try { |
| 7420 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7421 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7422 | } catch (SecurityException e) { |
| 7423 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 7424 | // has carrier privileges on an active UICC |
| 7425 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 7426 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7427 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7428 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7429 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7430 | |
| 7431 | final long identity = Binder.clearCallingIdentity(); |
| 7432 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7433 | UiccController uiccController = UiccController.getInstance(); |
| 7434 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7435 | if (hasReadPermission) { |
| 7436 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7437 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7438 | |
| 7439 | // Remove private info if the caller doesn't have access |
| 7440 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 7441 | for (UiccCardInfo cardInfo : cardInfos) { |
| 7442 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 7443 | // is available |
| 7444 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 7445 | if (card == null || card.getUiccProfile() == null) { |
| 7446 | // assume no access if the card or profile is unavailable |
| 7447 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7448 | continue; |
| 7449 | } |
| 7450 | UiccProfile profile = card.getUiccProfile(); |
| 7451 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 7452 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7453 | filteredInfos.add(cardInfo); |
| 7454 | } else { |
| 7455 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7456 | } |
| 7457 | } |
| 7458 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7459 | } finally { |
| 7460 | Binder.restoreCallingIdentity(identity); |
| 7461 | } |
| 7462 | } |
| 7463 | |
| 7464 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7465 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7466 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7467 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7468 | final long identity = Binder.clearCallingIdentity(); |
| 7469 | try { |
| 7470 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 7471 | if (slots == null) { |
| 7472 | Rlog.i(LOG_TAG, "slots is null."); |
| 7473 | return null; |
| 7474 | } |
| 7475 | |
| 7476 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 7477 | for (int i = 0; i < slots.length; i++) { |
| 7478 | UiccSlot slot = slots[i]; |
| 7479 | if (slot == null) { |
| 7480 | continue; |
| 7481 | } |
| 7482 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7483 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7484 | UiccCard card = slot.getUiccCard(); |
| 7485 | if (card != null) { |
| 7486 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7487 | } else { |
Jordan Liu | d96b529 | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 7488 | cardId = slot.getEid(); |
| 7489 | if (TextUtils.isEmpty(cardId)) { |
| 7490 | cardId = slot.getIccId(); |
| 7491 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7492 | } |
| 7493 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 7494 | if (cardId != null) { |
| 7495 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 7496 | // if cardId is an EID, it's all digits so this is fine |
| 7497 | cardId = IccUtils.stripTrailingFs(cardId); |
| 7498 | } |
| 7499 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7500 | int cardState = 0; |
| 7501 | switch (slot.getCardState()) { |
| 7502 | case CARDSTATE_ABSENT: |
| 7503 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 7504 | break; |
| 7505 | case CARDSTATE_PRESENT: |
| 7506 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 7507 | break; |
| 7508 | case CARDSTATE_ERROR: |
| 7509 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 7510 | break; |
| 7511 | case CARDSTATE_RESTRICTED: |
| 7512 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 7513 | break; |
| 7514 | default: |
| 7515 | break; |
| 7516 | |
| 7517 | } |
| 7518 | |
| 7519 | infos[i] = new UiccSlotInfo( |
| 7520 | slot.isActive(), |
| 7521 | slot.isEuicc(), |
| 7522 | cardId, |
| 7523 | cardState, |
| 7524 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 7525 | slot.isExtendedApduSupported(), |
| 7526 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7527 | } |
| 7528 | return infos; |
| 7529 | } finally { |
| 7530 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 7531 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7532 | } |
| 7533 | |
| 7534 | @Override |
| 7535 | public boolean switchSlots(int[] physicalSlots) { |
| 7536 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7537 | |
| 7538 | final long identity = Binder.clearCallingIdentity(); |
| 7539 | try { |
| 7540 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 7541 | } finally { |
| 7542 | Binder.restoreCallingIdentity(identity); |
| 7543 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7544 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7545 | |
| 7546 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7547 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7548 | final long identity = Binder.clearCallingIdentity(); |
| 7549 | try { |
| 7550 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 7551 | } finally { |
| 7552 | Binder.restoreCallingIdentity(identity); |
| 7553 | } |
| 7554 | } |
| 7555 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7556 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 7557 | * A test API to reload the UICC profile. |
| 7558 | * |
| 7559 | * <p>Requires that the calling app has permission |
| 7560 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7561 | * @hide |
| 7562 | */ |
| 7563 | @Override |
| 7564 | public void refreshUiccProfile(int subId) { |
| 7565 | enforceModifyPermission(); |
| 7566 | |
| 7567 | final long identity = Binder.clearCallingIdentity(); |
| 7568 | try { |
| 7569 | Phone phone = getPhone(subId); |
| 7570 | if (phone == null) { |
| 7571 | return; |
| 7572 | } |
| 7573 | UiccCard uiccCard = phone.getUiccCard(); |
| 7574 | if (uiccCard == null) { |
| 7575 | return; |
| 7576 | } |
| 7577 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7578 | if (uiccProfile == null) { |
| 7579 | return; |
| 7580 | } |
| 7581 | uiccProfile.refresh(); |
| 7582 | } finally { |
| 7583 | Binder.restoreCallingIdentity(identity); |
| 7584 | } |
| 7585 | } |
| 7586 | |
| 7587 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7588 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 7589 | */ |
| 7590 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7591 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7592 | } |
| 7593 | |
| 7594 | /** |
| 7595 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 7596 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 7597 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 7598 | */ |
| 7599 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 7600 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7601 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7602 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7603 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 7604 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 7605 | return isDataRoamingEnabled; |
| 7606 | } |
| 7607 | |
| 7608 | /** |
| 7609 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 7610 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 7611 | */ |
| 7612 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7613 | List<Integer> list = TelephonyProperties.default_network(); |
| 7614 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 7615 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 7616 | return list.get(phoneId); |
| 7617 | } |
| 7618 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7619 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7620 | |
| 7621 | @Override |
| 7622 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7623 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7624 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7625 | |
| 7626 | final long identity = Binder.clearCallingIdentity(); |
| 7627 | try { |
| 7628 | final Phone phone = getPhone(subId); |
| 7629 | if (phone == null) { |
| 7630 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 7631 | return; |
| 7632 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7633 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 7634 | carrierPrivilegeRules, apn); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7635 | } finally { |
| 7636 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7637 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7638 | } |
| 7639 | |
| 7640 | @Override |
| 7641 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7642 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7643 | |
| 7644 | final long identity = Binder.clearCallingIdentity(); |
| 7645 | try { |
| 7646 | final Phone phone = getPhone(subId); |
| 7647 | if (phone == null) { |
| 7648 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 7649 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 7650 | } |
| 7651 | return phone.getCarrierIdListVersion(); |
| 7652 | } finally { |
| 7653 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7654 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7655 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7656 | |
| 7657 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7658 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 7659 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7660 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7661 | mApp, subId, callingPackage, callingFeatureId, |
| 7662 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7663 | return -1; |
| 7664 | } |
| 7665 | |
| 7666 | final long identity = Binder.clearCallingIdentity(); |
| 7667 | try { |
| 7668 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 7669 | } finally { |
| 7670 | Binder.restoreCallingIdentity(identity); |
| 7671 | } |
| 7672 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7673 | |
| 7674 | @Override |
| 7675 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 0723870 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 7676 | TelephonyPermissions |
| 7677 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7678 | mApp, subId, "getCdmaRoamingMode"); |
| 7679 | |
| 7680 | final long identity = Binder.clearCallingIdentity(); |
| 7681 | try { |
| 7682 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 7683 | } finally { |
| 7684 | Binder.restoreCallingIdentity(identity); |
| 7685 | } |
| 7686 | } |
| 7687 | |
| 7688 | @Override |
| 7689 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 7690 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7691 | mApp, subId, "setCdmaRoamingMode"); |
| 7692 | |
| 7693 | final long identity = Binder.clearCallingIdentity(); |
| 7694 | try { |
| 7695 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 7696 | } finally { |
| 7697 | Binder.restoreCallingIdentity(identity); |
| 7698 | } |
| 7699 | } |
| 7700 | |
| 7701 | @Override |
| 7702 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 7703 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7704 | mApp, subId, "setCdmaSubscriptionMode"); |
| 7705 | |
| 7706 | final long identity = Binder.clearCallingIdentity(); |
| 7707 | try { |
| 7708 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 7709 | } finally { |
| 7710 | Binder.restoreCallingIdentity(identity); |
| 7711 | } |
| 7712 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 7713 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7714 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7715 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7716 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7717 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7718 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 7719 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7720 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7721 | } |
| 7722 | final long identity = Binder.clearCallingIdentity(); |
| 7723 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7724 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 7725 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7726 | if (phone.getEmergencyNumberTracker() != null |
| 7727 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 7728 | emergencyNumberListInternal.put( |
| 7729 | phone.getSubId(), |
| 7730 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 7731 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7732 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7733 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7734 | } finally { |
| 7735 | Binder.restoreCallingIdentity(identity); |
| 7736 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7737 | } |
| 7738 | |
| 7739 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7740 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7741 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7742 | if (!exactMatch) { |
| 7743 | TelephonyPermissions |
| 7744 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7745 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7746 | } |
| 7747 | final long identity = Binder.clearCallingIdentity(); |
| 7748 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7749 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7750 | if (phone.getEmergencyNumberTracker() != null |
| 7751 | && phone.getEmergencyNumberTracker() != null) { |
| 7752 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 7753 | number, exactMatch)) { |
| 7754 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7755 | } |
| 7756 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7757 | } |
| 7758 | return false; |
| 7759 | } finally { |
| 7760 | Binder.restoreCallingIdentity(identity); |
| 7761 | } |
| 7762 | } |
| 7763 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 7764 | /** |
| 7765 | * Update emergency number list for test mode. |
| 7766 | */ |
| 7767 | @Override |
| 7768 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 7769 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7770 | "updateEmergencyNumberListTestMode"); |
| 7771 | |
| 7772 | final long identity = Binder.clearCallingIdentity(); |
| 7773 | try { |
| 7774 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7775 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7776 | if (tracker != null) { |
| 7777 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 7778 | } |
| 7779 | } |
| 7780 | } finally { |
| 7781 | Binder.restoreCallingIdentity(identity); |
| 7782 | } |
| 7783 | } |
| 7784 | |
| 7785 | /** |
| 7786 | * Get the full emergency number list for test mode. |
| 7787 | */ |
| 7788 | @Override |
| 7789 | public List<String> getEmergencyNumberListTestMode() { |
| 7790 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7791 | "getEmergencyNumberListTestMode"); |
| 7792 | |
| 7793 | final long identity = Binder.clearCallingIdentity(); |
| 7794 | try { |
| 7795 | Set<String> emergencyNumbers = new HashSet<>(); |
| 7796 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7797 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7798 | if (tracker != null) { |
| 7799 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 7800 | emergencyNumbers.add(num.getNumber()); |
| 7801 | } |
| 7802 | } |
| 7803 | } |
| 7804 | return new ArrayList<>(emergencyNumbers); |
| 7805 | } finally { |
| 7806 | Binder.restoreCallingIdentity(identity); |
| 7807 | } |
| 7808 | } |
| 7809 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7810 | @Override |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7811 | public int getEmergencyNumberDbVersion(int subId) { |
| 7812 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 7813 | |
| 7814 | final long identity = Binder.clearCallingIdentity(); |
| 7815 | try { |
| 7816 | final Phone phone = getPhone(subId); |
| 7817 | if (phone == null) { |
| 7818 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 7819 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 7820 | } |
| 7821 | return phone.getEmergencyNumberDbVersion(); |
| 7822 | } finally { |
| 7823 | Binder.restoreCallingIdentity(identity); |
| 7824 | } |
| 7825 | } |
| 7826 | |
| 7827 | @Override |
| 7828 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 7829 | enforceModifyPermission(); |
| 7830 | |
| 7831 | final long identity = Binder.clearCallingIdentity(); |
| 7832 | try { |
| 7833 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7834 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7835 | if (tracker != null) { |
| 7836 | tracker.updateOtaEmergencyNumberDatabase(); |
| 7837 | } |
| 7838 | } |
| 7839 | } finally { |
| 7840 | Binder.restoreCallingIdentity(identity); |
| 7841 | } |
| 7842 | } |
| 7843 | |
| 7844 | @Override |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 7845 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7846 | enforceActiveEmergencySessionPermission(); |
| 7847 | |
| 7848 | final long identity = Binder.clearCallingIdentity(); |
| 7849 | try { |
| 7850 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7851 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7852 | if (tracker != null) { |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 7853 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 7854 | } |
| 7855 | } |
| 7856 | } finally { |
| 7857 | Binder.restoreCallingIdentity(identity); |
| 7858 | } |
| 7859 | } |
| 7860 | |
| 7861 | @Override |
| 7862 | public void resetOtaEmergencyNumberDbFilePath() { |
| 7863 | enforceActiveEmergencySessionPermission(); |
| 7864 | |
| 7865 | final long identity = Binder.clearCallingIdentity(); |
| 7866 | try { |
| 7867 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7868 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7869 | if (tracker != null) { |
| 7870 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7871 | } |
| 7872 | } |
| 7873 | } finally { |
| 7874 | Binder.restoreCallingIdentity(identity); |
| 7875 | } |
| 7876 | } |
| 7877 | |
| 7878 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7879 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 7880 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 7881 | Phone phone = getPhone(subId); |
| 7882 | if (phone == null) { |
| 7883 | return null; |
| 7884 | } |
| 7885 | final long identity = Binder.clearCallingIdentity(); |
| 7886 | try { |
| 7887 | UiccProfile profile = UiccController.getInstance() |
| 7888 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 7889 | if (profile != null) { |
| 7890 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 7891 | } |
| 7892 | } finally { |
| 7893 | Binder.restoreCallingIdentity(identity); |
| 7894 | } |
| 7895 | return null; |
| 7896 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 7897 | |
| 7898 | /** |
| 7899 | * Enable or disable a modem stack. |
| 7900 | */ |
| 7901 | @Override |
| 7902 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 7903 | enforceModifyPermission(); |
| 7904 | |
| 7905 | final long identity = Binder.clearCallingIdentity(); |
| 7906 | try { |
| 7907 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7908 | if (phone == null) { |
| 7909 | return false; |
| 7910 | } else { |
| 7911 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 7912 | } |
| 7913 | } finally { |
| 7914 | Binder.restoreCallingIdentity(identity); |
| 7915 | } |
| 7916 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7917 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7918 | /** |
| 7919 | * Whether a modem stack is enabled or not. |
| 7920 | */ |
| 7921 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7922 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 7923 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7924 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7925 | if (phone == null) return false; |
| 7926 | |
| 7927 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7928 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 7929 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7930 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7931 | } |
| 7932 | |
| 7933 | final long identity = Binder.clearCallingIdentity(); |
| 7934 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 7935 | try { |
| 7936 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 7937 | } catch (NoSuchElementException ex) { |
| 7938 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 7939 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7940 | } finally { |
| 7941 | Binder.restoreCallingIdentity(identity); |
| 7942 | } |
| 7943 | } |
| 7944 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7945 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7946 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7947 | enforceModifyPermission(); |
| 7948 | |
| 7949 | final long identity = Binder.clearCallingIdentity(); |
| 7950 | try { |
| 7951 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7952 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7953 | .commit(); |
| 7954 | } finally { |
| 7955 | Binder.restoreCallingIdentity(identity); |
| 7956 | } |
| 7957 | } |
| 7958 | |
| 7959 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7960 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7961 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7962 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7963 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 7964 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7965 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 7966 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7967 | |
| 7968 | final long identity = Binder.clearCallingIdentity(); |
| 7969 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7970 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7971 | } finally { |
| 7972 | Binder.restoreCallingIdentity(identity); |
| 7973 | } |
| 7974 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 7975 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7976 | @TelephonyManager.IsMultiSimSupportedResult |
| 7977 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7978 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 7979 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 7980 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7981 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 7982 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7983 | } |
| 7984 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 7985 | // supported by the modem, indicate that it is restricted. |
| 7986 | PhoneCapability staticCapability = |
| 7987 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 7988 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7989 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 7990 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7991 | } |
Sarah Chin | 09f38ee | 2020-02-25 00:13:10 +0000 | [diff] [blame] | 7992 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7993 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 7994 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7995 | } |
| 7996 | // Check if support of multiple SIMs is restricted by carrier |
| 7997 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7998 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 7999 | } |
| 8000 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8001 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8002 | } |
| 8003 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8004 | /** |
| 8005 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8006 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8007 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8008 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8009 | * @param numOfSims number of active sims we want to switch to |
| 8010 | */ |
| 8011 | @Override |
| 8012 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8013 | if (numOfSims == 1) { |
| 8014 | enforceModifyPermission(); |
| 8015 | } else { |
| 8016 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8017 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8018 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8019 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8020 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8021 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8022 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8023 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8024 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8025 | return; |
| 8026 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8027 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8028 | } finally { |
| 8029 | Binder.restoreCallingIdentity(identity); |
| 8030 | } |
| 8031 | } |
| 8032 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8033 | @Override |
| 8034 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8035 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8036 | Phone phone = getPhone(subId); |
| 8037 | if (phone == null) { |
| 8038 | return false; |
| 8039 | } |
| 8040 | final long identity = Binder.clearCallingIdentity(); |
| 8041 | try { |
| 8042 | UiccCard uiccCard = phone.getUiccCard(); |
| 8043 | if (uiccCard == null) { |
| 8044 | return false; |
| 8045 | } |
| 8046 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8047 | if (uiccProfile == null) { |
| 8048 | return false; |
| 8049 | } |
| 8050 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8051 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8052 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8053 | } |
| 8054 | return false; |
| 8055 | } finally { |
| 8056 | Binder.restoreCallingIdentity(identity); |
| 8057 | } |
| 8058 | } |
| 8059 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8060 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8061 | * Get whether making changes to modem configurations will trigger reboot. |
| 8062 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8063 | */ |
| 8064 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8065 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8066 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8067 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8068 | mApp, subId, callingPackage, callingFeatureId, |
| 8069 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8070 | return false; |
| 8071 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8072 | final long identity = Binder.clearCallingIdentity(); |
| 8073 | try { |
| 8074 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8075 | } finally { |
| 8076 | Binder.restoreCallingIdentity(identity); |
| 8077 | } |
| 8078 | } |
| 8079 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8080 | private void updateModemStateMetrics() { |
| 8081 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8082 | // TODO: check the state for each modem if the api is ready. |
| 8083 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8084 | } |
| 8085 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8086 | @Override |
| 8087 | public int[] getSlotsMapping() { |
| 8088 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8089 | |
| 8090 | final long identity = Binder.clearCallingIdentity(); |
| 8091 | try { |
| 8092 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8093 | // All logical slots should have a mapping to a physical slot. |
| 8094 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8095 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8096 | for (int i = 0; i < slotInfos.length; i++) { |
| 8097 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8098 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8099 | } |
| 8100 | } |
| 8101 | return logicalSlotsMapping; |
| 8102 | } finally { |
| 8103 | Binder.restoreCallingIdentity(identity); |
| 8104 | } |
| 8105 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8106 | |
| 8107 | /** |
| 8108 | * Get the IRadio HAL Version |
| 8109 | */ |
| 8110 | @Override |
| 8111 | public int getRadioHalVersion() { |
| 8112 | Phone phone = getDefaultPhone(); |
| 8113 | if (phone == null) return -1; |
| 8114 | HalVersion hv = phone.getHalVersion(); |
| 8115 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8116 | return hv.major * 100 + hv.minor; |
| 8117 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8118 | |
| 8119 | /** |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8120 | * Get the current calling package name. |
| 8121 | * @return the current calling package name |
| 8122 | */ |
| 8123 | @Override |
| 8124 | public String getCurrentPackageName() { |
| 8125 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8126 | } |
| 8127 | |
| 8128 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8129 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8130 | * corresponding network requests on a subId. |
| 8131 | * |
| 8132 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8133 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8134 | * 2) APN is un-metered for this subscription, or |
| 8135 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
changbetty | 97defcf | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8136 | * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8137 | * |
| 8138 | * @return whether data is allowed for a apn type. |
| 8139 | * |
| 8140 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8141 | */ |
| 8142 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8143 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | f250974 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8144 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8145 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8146 | |
| 8147 | // Now that all security checks passes, perform the operation as ourselves. |
| 8148 | final long identity = Binder.clearCallingIdentity(); |
| 8149 | try { |
| 8150 | Phone phone = getPhone(subId); |
| 8151 | if (phone == null) return false; |
| 8152 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8153 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8154 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8155 | } finally { |
| 8156 | Binder.restoreCallingIdentity(identity); |
| 8157 | } |
| 8158 | } |
| 8159 | |
| 8160 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8161 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8162 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8163 | |
| 8164 | // Now that all security checks passes, perform the operation as ourselves. |
| 8165 | final long identity = Binder.clearCallingIdentity(); |
| 8166 | try { |
| 8167 | Phone phone = getPhone(subId); |
| 8168 | if (phone == null) return true; // By default return true. |
| 8169 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8170 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8171 | } finally { |
| 8172 | Binder.restoreCallingIdentity(identity); |
| 8173 | } |
| 8174 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8175 | |
| 8176 | @Override |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 8177 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 8178 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 8179 | enforceModifyPermission(); |
| 8180 | long token = Binder.clearCallingIdentity(); |
| 8181 | try { |
| 8182 | Phone phone = getPhone(subscriptionId); |
| 8183 | if (phone == null) { |
| 8184 | try { |
| 8185 | if (resultCallback != null) { |
| 8186 | resultCallback.accept(false); |
| 8187 | } |
| 8188 | } catch (RemoteException e) { |
| 8189 | // ignore |
| 8190 | } |
| 8191 | return; |
| 8192 | } |
| 8193 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 8194 | Pair.create(specifiers, (x) -> { |
| 8195 | try { |
| 8196 | if (resultCallback != null) { |
| 8197 | resultCallback.accept(x); |
| 8198 | } |
| 8199 | } catch (RemoteException e) { |
| 8200 | // ignore |
| 8201 | } |
| 8202 | }); |
| 8203 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 8204 | } finally { |
| 8205 | Binder.restoreCallingIdentity(token); |
| 8206 | } |
| 8207 | } |
| 8208 | |
| 8209 | @Override |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8210 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
| 8211 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 8212 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 8213 | if (iccRecords == null) { |
| 8214 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 8215 | return false; |
| 8216 | } |
| 8217 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 8218 | } |
| 8219 | |
| 8220 | @Override |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8221 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 8222 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8223 | if (callingPackage == null) { |
| 8224 | callingPackage = getCurrentPackageName(); |
| 8225 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8226 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 8227 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8228 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 8229 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8230 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 8231 | } |
| 8232 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 8233 | Intent intent = new Intent(); |
| 8234 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 8235 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 8236 | // Bring up choose default SMS subscription dialog right now |
| 8237 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 8238 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 8239 | mApp.startActivity(intent); |
| 8240 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8241 | |
| 8242 | @Override |
| 8243 | public String getMmsUAProfUrl(int subId) { |
| 8244 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8245 | final long identity = Binder.clearCallingIdentity(); |
| 8246 | try { |
| 8247 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8248 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 8249 | } finally { |
| 8250 | Binder.restoreCallingIdentity(identity); |
| 8251 | } |
| 8252 | } |
| 8253 | |
| 8254 | @Override |
| 8255 | public String getMmsUserAgent(int subId) { |
| 8256 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8257 | final long identity = Binder.clearCallingIdentity(); |
| 8258 | try { |
| 8259 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8260 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 8261 | } finally { |
| 8262 | Binder.restoreCallingIdentity(identity); |
| 8263 | } |
| 8264 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8265 | |
| 8266 | @Override |
| 8267 | public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) { |
| 8268 | enforceModifyPermission(); |
| 8269 | |
| 8270 | // Now that all security checks passes, perform the operation as ourselves. |
| 8271 | final long identity = Binder.clearCallingIdentity(); |
| 8272 | try { |
| 8273 | Phone phone = getPhone(subId); |
| 8274 | if (phone == null) return false; |
| 8275 | |
| 8276 | return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow); |
| 8277 | } finally { |
| 8278 | Binder.restoreCallingIdentity(identity); |
| 8279 | } |
| 8280 | } |
| 8281 | |
| 8282 | @Override |
| 8283 | public boolean isDataAllowedInVoiceCall(int subId) { |
| 8284 | enforceReadPrivilegedPermission("isDataAllowedInVoiceCall"); |
| 8285 | |
| 8286 | // Now that all security checks passes, perform the operation as ourselves. |
| 8287 | final long identity = Binder.clearCallingIdentity(); |
| 8288 | try { |
| 8289 | Phone phone = getPhone(subId); |
| 8290 | if (phone == null) return false; |
| 8291 | |
| 8292 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 8293 | } finally { |
| 8294 | Binder.restoreCallingIdentity(identity); |
| 8295 | } |
| 8296 | } |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8297 | |
changbetty | 97defcf | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8298 | @Override |
| 8299 | public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) { |
| 8300 | enforceModifyPermission(); |
| 8301 | |
| 8302 | // Now that all security checks passes, perform the operation as ourselves. |
| 8303 | final long identity = Binder.clearCallingIdentity(); |
| 8304 | try { |
| 8305 | Phone phone = getPhone(subId); |
| 8306 | if (phone == null) return false; |
| 8307 | |
| 8308 | return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow); |
| 8309 | } finally { |
| 8310 | Binder.restoreCallingIdentity(identity); |
| 8311 | } |
| 8312 | } |
| 8313 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8314 | /** |
| 8315 | * Updates whether conference event pacakge handling is enabled. |
| 8316 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 8317 | * otherwise. |
| 8318 | */ |
| 8319 | @Override |
| 8320 | public void setCepEnabled(boolean isCepEnabled) { |
| 8321 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 8322 | |
| 8323 | final long identity = Binder.clearCallingIdentity(); |
| 8324 | try { |
| 8325 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 8326 | for (Phone phone : PhoneFactory.getPhones()) { |
| 8327 | Phone defaultPhone = phone.getImsPhone(); |
| 8328 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 8329 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 8330 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 8331 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 8332 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 8333 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 8334 | + imsPhone.getMsisdn()); |
| 8335 | } |
| 8336 | } |
| 8337 | } finally { |
| 8338 | Binder.restoreCallingIdentity(identity); |
| 8339 | } |
| 8340 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 8341 | |
| 8342 | /** |
| 8343 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 8344 | * |
| 8345 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 8346 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 8347 | * before being read. |
| 8348 | */ |
| 8349 | @Override |
| 8350 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 8351 | isCompressed) { |
| 8352 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8353 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
| 8354 | try { |
| 8355 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 8356 | if (configBinder == null) { |
| 8357 | Rlog.e(LOG_TAG, "null result for getImsConfig"); |
| 8358 | } else { |
| 8359 | configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed); |
| 8360 | } |
| 8361 | } catch (RemoteException e) { |
| 8362 | Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage()); |
| 8363 | } |
| 8364 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8365 | |
| 8366 | @Override |
| 8367 | public boolean isIccLockEnabled(int subId) { |
| 8368 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 8369 | |
| 8370 | // Now that all security checks passes, perform the operation as ourselves. |
| 8371 | final long identity = Binder.clearCallingIdentity(); |
| 8372 | try { |
| 8373 | Phone phone = getPhone(subId); |
| 8374 | if (phone != null && phone.getIccCard() != null) { |
| 8375 | return phone.getIccCard().getIccLockEnabled(); |
| 8376 | } else { |
| 8377 | return false; |
| 8378 | } |
| 8379 | } finally { |
| 8380 | Binder.restoreCallingIdentity(identity); |
| 8381 | } |
| 8382 | } |
| 8383 | |
| 8384 | /** |
| 8385 | * Set the ICC pin lock enabled or disabled.. |
| 8386 | * |
| 8387 | * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return |
| 8388 | * 0 or a positive integer as the attempts remaining value. |
| 8389 | * |
| 8390 | */ |
| 8391 | @Override |
| 8392 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 8393 | enforceModifyPermission(); |
| 8394 | |
| 8395 | Phone phone = getPhone(subId); |
| 8396 | if (phone == null) { |
| 8397 | return 0; |
| 8398 | } |
| 8399 | // Now that all security checks passes, perform the operation as ourselves. |
| 8400 | final long identity = Binder.clearCallingIdentity(); |
| 8401 | try { |
| 8402 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 8403 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 8404 | return attemptsRemaining; |
| 8405 | |
| 8406 | } catch (Exception e) { |
| 8407 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 8408 | } finally { |
| 8409 | Binder.restoreCallingIdentity(identity); |
| 8410 | } |
| 8411 | return 0; |
| 8412 | } |
| 8413 | |
| 8414 | /** |
| 8415 | * Change the ICC password used in ICC pin lock. |
| 8416 | * |
| 8417 | * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return |
| 8418 | * 0 or a positive integer as the attempts remaining value. |
| 8419 | * |
| 8420 | */ |
| 8421 | @Override |
| 8422 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 8423 | enforceModifyPermission(); |
| 8424 | |
| 8425 | Phone phone = getPhone(subId); |
| 8426 | if (phone == null) { |
| 8427 | return 0; |
| 8428 | } |
| 8429 | // Now that all security checks passes, perform the operation as ourselves. |
| 8430 | final long identity = Binder.clearCallingIdentity(); |
| 8431 | try { |
| 8432 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 8433 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 8434 | return attemptsRemaining; |
| 8435 | |
| 8436 | } catch (Exception e) { |
| 8437 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 8438 | } finally { |
| 8439 | Binder.restoreCallingIdentity(identity); |
| 8440 | } |
| 8441 | return 0; |
| 8442 | } |
Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 8443 | |
| 8444 | @Override |
| 8445 | public boolean canConnectTo5GInDsdsMode() { |
| 8446 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 8447 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 8448 | } |