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 | |
| 1932 | public void updateServiceLocation() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1933 | updateServiceLocationForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1934 | |
| 1935 | } |
| 1936 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1937 | public void updateServiceLocationForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1938 | // No permission check needed here: this call is harmless, and it's |
| 1939 | // needed for the ServiceState.requestStateUpdate() call (which is |
| 1940 | // already intentionally exposed to 3rd parties.) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1941 | final long identity = Binder.clearCallingIdentity(); |
| 1942 | try { |
| 1943 | final Phone phone = getPhone(subId); |
| 1944 | if (phone != null) { |
| 1945 | phone.updateServiceLocation(); |
| 1946 | } |
| 1947 | } finally { |
| 1948 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1949 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1950 | } |
| 1951 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1952 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1953 | @Override |
| 1954 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1955 | return isRadioOnWithFeature(callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1956 | } |
| 1957 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1958 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1959 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 1960 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 1961 | callingFeatureId); |
| 1962 | } |
| 1963 | |
| 1964 | @Deprecated |
| 1965 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1966 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1967 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
| 1968 | } |
| 1969 | |
| 1970 | @Override |
| 1971 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 1972 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 1973 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 1974 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1975 | return false; |
| 1976 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1977 | |
| 1978 | final long identity = Binder.clearCallingIdentity(); |
| 1979 | try { |
| 1980 | return isRadioOnForSubscriber(subId); |
| 1981 | } finally { |
| 1982 | Binder.restoreCallingIdentity(identity); |
| 1983 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 1984 | } |
| 1985 | |
| 1986 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1987 | final long identity = Binder.clearCallingIdentity(); |
| 1988 | try { |
| 1989 | final Phone phone = getPhone(subId); |
| 1990 | if (phone != null) { |
| 1991 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 1992 | } else { |
| 1993 | return false; |
| 1994 | } |
| 1995 | } finally { |
| 1996 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 1997 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1998 | } |
| 1999 | |
| 2000 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2001 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2002 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2003 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2004 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2005 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2006 | |
| 2007 | final long identity = Binder.clearCallingIdentity(); |
| 2008 | try { |
| 2009 | final Phone phone = getPhone(subId); |
| 2010 | if (phone != null) { |
| 2011 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2012 | } |
| 2013 | } finally { |
| 2014 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2015 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2019 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2020 | } |
| 2021 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2022 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2023 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2024 | |
| 2025 | final long identity = Binder.clearCallingIdentity(); |
| 2026 | try { |
| 2027 | final Phone phone = getPhone(subId); |
| 2028 | if (phone == null) { |
| 2029 | return false; |
| 2030 | } |
| 2031 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2032 | toggleRadioOnOffForSubscriber(subId); |
| 2033 | } |
| 2034 | return true; |
| 2035 | } finally { |
| 2036 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2037 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2038 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2039 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2040 | public boolean needMobileRadioShutdown() { |
Shuo Qian | afeaf7d | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2041 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2042 | /* |
| 2043 | * If any of the Radios are available, it will need to be |
| 2044 | * shutdown. So return true if any Radio is available. |
| 2045 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2046 | final long identity = Binder.clearCallingIdentity(); |
| 2047 | try { |
| 2048 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2049 | Phone phone = PhoneFactory.getPhone(i); |
| 2050 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2051 | } |
| 2052 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2053 | return false; |
| 2054 | } finally { |
| 2055 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2056 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2057 | } |
| 2058 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2059 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2060 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2061 | enforceModifyPermission(); |
| 2062 | |
| 2063 | final long identity = Binder.clearCallingIdentity(); |
| 2064 | try { |
| 2065 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2066 | logv("Shutting down Phone " + i); |
| 2067 | shutdownRadioUsingPhoneId(i); |
| 2068 | } |
| 2069 | } finally { |
| 2070 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2071 | } |
| 2072 | } |
| 2073 | |
| 2074 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2075 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2076 | if (phone != null && phone.isRadioAvailable()) { |
| 2077 | phone.shutdownRadio(); |
| 2078 | } |
| 2079 | } |
| 2080 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2081 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2082 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2083 | |
| 2084 | final long identity = Binder.clearCallingIdentity(); |
| 2085 | try { |
| 2086 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2087 | if (defaultPhone != null) { |
| 2088 | defaultPhone.setRadioPower(turnOn); |
| 2089 | return true; |
| 2090 | } else { |
| 2091 | loge("There's no default phone."); |
| 2092 | return false; |
| 2093 | } |
| 2094 | } finally { |
| 2095 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2096 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2097 | } |
| 2098 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2099 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2100 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2101 | |
| 2102 | final long identity = Binder.clearCallingIdentity(); |
| 2103 | try { |
| 2104 | final Phone phone = getPhone(subId); |
| 2105 | if (phone != null) { |
| 2106 | phone.setRadioPower(turnOn); |
| 2107 | return true; |
| 2108 | } else { |
| 2109 | return false; |
| 2110 | } |
| 2111 | } finally { |
| 2112 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2113 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2114 | } |
| 2115 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2116 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2117 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2118 | public boolean enableDataConnectivity() { |
| 2119 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2120 | |
| 2121 | final long identity = Binder.clearCallingIdentity(); |
| 2122 | try { |
| 2123 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2124 | final Phone phone = getPhone(subId); |
| 2125 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 2126 | phone.getDataEnabledSettings().setUserDataEnabled(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2127 | return true; |
| 2128 | } else { |
| 2129 | return false; |
| 2130 | } |
| 2131 | } finally { |
| 2132 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2133 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2134 | } |
| 2135 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2136 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2137 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2138 | public boolean disableDataConnectivity() { |
| 2139 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2140 | |
| 2141 | final long identity = Binder.clearCallingIdentity(); |
| 2142 | try { |
| 2143 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2144 | final Phone phone = getPhone(subId); |
| 2145 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 2146 | phone.getDataEnabledSettings().setUserDataEnabled(false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2147 | return true; |
| 2148 | } else { |
| 2149 | return false; |
| 2150 | } |
| 2151 | } finally { |
| 2152 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2153 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2154 | } |
| 2155 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2156 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2157 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2158 | final long identity = Binder.clearCallingIdentity(); |
| 2159 | try { |
| 2160 | final Phone phone = getPhone(subId); |
| 2161 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2162 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2163 | } else { |
| 2164 | return false; |
| 2165 | } |
| 2166 | } finally { |
| 2167 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2168 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2169 | } |
| 2170 | |
| 2171 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2172 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2173 | } |
| 2174 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2175 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2176 | enforceCallPermission(); |
| 2177 | |
| 2178 | final long identity = Binder.clearCallingIdentity(); |
| 2179 | try { |
| 2180 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2181 | return; |
| 2182 | } |
| 2183 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2184 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2185 | } finally { |
| 2186 | Binder.restoreCallingIdentity(identity); |
| 2187 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2188 | }; |
| 2189 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2190 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2191 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2192 | |
| 2193 | final long identity = Binder.clearCallingIdentity(); |
| 2194 | try { |
| 2195 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2196 | return false; |
| 2197 | } |
| 2198 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2199 | } finally { |
| 2200 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2201 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2202 | } |
| 2203 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2204 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2205 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2206 | } |
| 2207 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2208 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2209 | final long identity = Binder.clearCallingIdentity(); |
| 2210 | try { |
| 2211 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2212 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2213 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2214 | } finally { |
| 2215 | Binder.restoreCallingIdentity(identity); |
| 2216 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2217 | } |
| 2218 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2219 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2220 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2221 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2222 | } |
| 2223 | |
| 2224 | @Override |
| 2225 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2226 | final long identity = Binder.clearCallingIdentity(); |
| 2227 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2228 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2229 | if (phone != null) { |
| 2230 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2231 | } else { |
| 2232 | return PhoneConstantConversions.convertDataState( |
| 2233 | PhoneConstants.DataState.DISCONNECTED); |
| 2234 | } |
| 2235 | } finally { |
| 2236 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2237 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2238 | } |
| 2239 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2240 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2241 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2242 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2243 | } |
| 2244 | |
| 2245 | @Override |
| 2246 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2247 | final long identity = Binder.clearCallingIdentity(); |
| 2248 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2249 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2250 | if (phone != null) { |
| 2251 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2252 | } else { |
| 2253 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2254 | } |
| 2255 | } finally { |
| 2256 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2257 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2258 | } |
| 2259 | |
| 2260 | @Override |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2261 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2262 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2263 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2264 | |
| 2265 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2266 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2267 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2268 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2269 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2270 | .setCallingPid(Binder.getCallingPid()) |
| 2271 | .setCallingUid(Binder.getCallingUid()) |
| 2272 | .setMethod("getCellLocation") |
Hall Liu | c3f8eb6 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2273 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2274 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2275 | .build()); |
| 2276 | switch (locationResult) { |
| 2277 | case DENIED_HARD: |
| 2278 | throw new SecurityException("Not allowed to access cell location"); |
| 2279 | case DENIED_SOFT: |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2280 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2281 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2282 | } |
| 2283 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2284 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2285 | final long identity = Binder.clearCallingIdentity(); |
| 2286 | try { |
| 2287 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2288 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2289 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2290 | } finally { |
| 2291 | Binder.restoreCallingIdentity(identity); |
| 2292 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2293 | } |
| 2294 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2295 | @Override |
Jack Yu | 0142503 | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2296 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2297 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2298 | // registered cell info, so return a NULL country instead. |
| 2299 | final long identity = Binder.clearCallingIdentity(); |
| 2300 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2301 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2302 | // Get default phone in this case. |
| 2303 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2304 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2305 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2306 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | cf38ed9 | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2307 | if (phone == null) return ""; |
| 2308 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2309 | if (sst == null) return ""; |
| 2310 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2311 | if (lt == null) return ""; |
| 2312 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry(); |
| 2313 | EmergencyNumberTracker ent = phone.getEmergencyNumberTracker(); |
| 2314 | return (ent == null) ? "" : ent.getEmergencyCountryIso(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2315 | } finally { |
| 2316 | Binder.restoreCallingIdentity(identity); |
| 2317 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2318 | } |
| 2319 | |
| 2320 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2321 | public void enableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2322 | enableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2323 | } |
| 2324 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2325 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2326 | public void enableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2327 | mApp.enforceCallingOrSelfPermission( |
| 2328 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2329 | |
| 2330 | final long identity = Binder.clearCallingIdentity(); |
| 2331 | try { |
| 2332 | final Phone phone = getPhone(subId); |
| 2333 | if (phone != null) { |
| 2334 | phone.enableLocationUpdates(); |
| 2335 | } |
| 2336 | } finally { |
| 2337 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2338 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2339 | } |
| 2340 | |
| 2341 | @Override |
| 2342 | public void disableLocationUpdates() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2343 | disableLocationUpdatesForSubscriber(getDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2344 | } |
| 2345 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2346 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2347 | public void disableLocationUpdatesForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2348 | mApp.enforceCallingOrSelfPermission( |
| 2349 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2350 | |
| 2351 | final long identity = Binder.clearCallingIdentity(); |
| 2352 | try { |
| 2353 | final Phone phone = getPhone(subId); |
| 2354 | if (phone != null) { |
| 2355 | phone.disableLocationUpdates(); |
| 2356 | } |
| 2357 | } finally { |
| 2358 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2359 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2360 | } |
| 2361 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2362 | /** |
| 2363 | * Returns the target SDK version number for a given package name. |
| 2364 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2365 | * This call MUST be invoked before clearing the calling UID. |
| 2366 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2367 | * @return target SDK if the package is found or INT_MAX. |
| 2368 | */ |
| 2369 | private int getTargetSdk(String packageName) { |
| 2370 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2371 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 54d2030 | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2372 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2373 | if (ai != null) return ai.targetSdkVersion; |
| 2374 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2375 | loge("Failed to get package info for pkg=" |
| 2376 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2377 | } |
| 2378 | return Integer.MAX_VALUE; |
| 2379 | } |
| 2380 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2381 | @Override |
| 2382 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2383 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2384 | String callingFeatureId) { |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2385 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2386 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2387 | throw new SecurityException( |
| 2388 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2389 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2390 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2391 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2392 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2393 | return null; |
| 2394 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2395 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2396 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2397 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2398 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2399 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2400 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2401 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2402 | for (CellInfo ci : info) { |
| 2403 | if (ci instanceof CellInfoGsm) { |
| 2404 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2405 | } else if (ci instanceof CellInfoWcdma) { |
| 2406 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2407 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2408 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2409 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2410 | } |
| 2411 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2412 | private List<CellInfo> getCachedCellInfo() { |
| 2413 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2414 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2415 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2416 | if (info != null) cellInfos.addAll(info); |
| 2417 | } |
| 2418 | return cellInfos; |
| 2419 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2420 | |
| 2421 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2422 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2423 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2424 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2425 | |
| 2426 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2427 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2428 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2429 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2430 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2431 | .setCallingPid(Binder.getCallingPid()) |
| 2432 | .setCallingUid(Binder.getCallingUid()) |
| 2433 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2434 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2435 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2436 | .build()); |
| 2437 | switch (locationResult) { |
| 2438 | case DENIED_HARD: |
| 2439 | throw new SecurityException("Not allowed to access cell info"); |
| 2440 | case DENIED_SOFT: |
| 2441 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2442 | } |
| 2443 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2444 | final int targetSdk = getTargetSdk(callingPackage); |
| 2445 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2446 | return getCachedCellInfo(); |
| 2447 | } |
| 2448 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2449 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2450 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2451 | final long identity = Binder.clearCallingIdentity(); |
| 2452 | try { |
| 2453 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2454 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2455 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2456 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2457 | if (info != null) cellInfos.addAll(info); |
| 2458 | } |
| 2459 | return cellInfos; |
| 2460 | } finally { |
| 2461 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2462 | } |
| 2463 | } |
| 2464 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2465 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2466 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2467 | String callingFeatureId) { |
| 2468 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2469 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2470 | } |
| 2471 | |
| 2472 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2473 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2474 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2475 | enforceModifyPermission(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2476 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2477 | } |
| 2478 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2479 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2480 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2481 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2482 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2483 | |
| 2484 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2485 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2486 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2487 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2488 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2489 | .setCallingPid(Binder.getCallingPid()) |
| 2490 | .setCallingUid(Binder.getCallingUid()) |
| 2491 | .setMethod("requestCellInfoUpdate") |
| 2492 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2493 | .build()); |
| 2494 | switch (locationResult) { |
| 2495 | case DENIED_HARD: |
| 2496 | throw new SecurityException("Not allowed to access cell info"); |
| 2497 | case DENIED_SOFT: |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2498 | try { |
| 2499 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2500 | } catch (RemoteException re) { |
| 2501 | // Drop without consequences |
| 2502 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2503 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2504 | } |
| 2505 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2506 | |
| 2507 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2508 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2509 | |
| 2510 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2511 | } |
| 2512 | |
| 2513 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2514 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2515 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2516 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2517 | |
| 2518 | final long identity = Binder.clearCallingIdentity(); |
| 2519 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2520 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2521 | } finally { |
| 2522 | Binder.restoreCallingIdentity(identity); |
| 2523 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2524 | } |
| 2525 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2526 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2527 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2528 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2529 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2530 | return null; |
| 2531 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2532 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2533 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2534 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2535 | return null; |
| 2536 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2537 | |
| 2538 | final long identity = Binder.clearCallingIdentity(); |
| 2539 | try { |
| 2540 | return phone.getImei(); |
| 2541 | } finally { |
| 2542 | Binder.restoreCallingIdentity(identity); |
| 2543 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2544 | } |
| 2545 | |
| 2546 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2547 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2548 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2549 | String tac = null; |
| 2550 | if (phone != null) { |
| 2551 | String imei = phone.getImei(); |
| 2552 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2553 | } |
| 2554 | return tac; |
| 2555 | } |
| 2556 | |
| 2557 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2558 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2559 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2560 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2561 | return null; |
| 2562 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2563 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2564 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2565 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2566 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2567 | return null; |
| 2568 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2569 | |
| 2570 | final long identity = Binder.clearCallingIdentity(); |
| 2571 | try { |
| 2572 | return phone.getMeid(); |
| 2573 | } finally { |
| 2574 | Binder.restoreCallingIdentity(identity); |
| 2575 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2576 | } |
| 2577 | |
| 2578 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2579 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2580 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2581 | String manufacturerCode = null; |
| 2582 | if (phone != null) { |
| 2583 | String meid = phone.getMeid(); |
| 2584 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2585 | } |
| 2586 | return manufacturerCode; |
| 2587 | } |
| 2588 | |
| 2589 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2590 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2591 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2592 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2593 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2594 | return null; |
| 2595 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2596 | int subId = phone.getSubId(); |
| 2597 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2598 | mApp, subId, callingPackage, callingFeatureId, |
| 2599 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2600 | return null; |
| 2601 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2602 | |
| 2603 | final long identity = Binder.clearCallingIdentity(); |
| 2604 | try { |
| 2605 | return phone.getDeviceSvn(); |
| 2606 | } finally { |
| 2607 | Binder.restoreCallingIdentity(identity); |
| 2608 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2609 | } |
| 2610 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2611 | @Override |
| 2612 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2613 | final long identity = Binder.clearCallingIdentity(); |
| 2614 | try { |
| 2615 | final Phone phone = getPhone(subId); |
| 2616 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2617 | } finally { |
| 2618 | Binder.restoreCallingIdentity(identity); |
| 2619 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2620 | } |
| 2621 | |
| 2622 | @Override |
| 2623 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2624 | final long identity = Binder.clearCallingIdentity(); |
| 2625 | try { |
| 2626 | final Phone phone = getPhone(subId); |
| 2627 | return phone == null ? null : phone.getCarrierName(); |
| 2628 | } finally { |
| 2629 | Binder.restoreCallingIdentity(identity); |
| 2630 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2631 | } |
| 2632 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2633 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2634 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2635 | final long identity = Binder.clearCallingIdentity(); |
| 2636 | try { |
| 2637 | final Phone phone = getPhone(subId); |
| 2638 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2639 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2640 | } finally { |
| 2641 | Binder.restoreCallingIdentity(identity); |
| 2642 | } |
| 2643 | } |
| 2644 | |
| 2645 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2646 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2647 | final long identity = Binder.clearCallingIdentity(); |
| 2648 | try { |
| 2649 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2650 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2651 | } finally { |
| 2652 | Binder.restoreCallingIdentity(identity); |
| 2653 | } |
| 2654 | } |
| 2655 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2656 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2657 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2658 | if (!isSubscriptionMccMnc) { |
| 2659 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2660 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2661 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2662 | if (phone == null) { |
| 2663 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2664 | } |
| 2665 | final long identity = Binder.clearCallingIdentity(); |
| 2666 | try { |
| 2667 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2668 | } finally { |
| 2669 | Binder.restoreCallingIdentity(identity); |
| 2670 | } |
| 2671 | } |
| 2672 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2673 | // |
| 2674 | // Internal helper methods. |
| 2675 | // |
| 2676 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2677 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2678 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2679 | * |
| 2680 | * @throws SecurityException if the caller does not have the required permission |
| 2681 | */ |
| 2682 | private void enforceModifyPermission() { |
| 2683 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2684 | } |
| 2685 | |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 2686 | /** |
| 2687 | * Make sure the caller is system. |
| 2688 | * |
| 2689 | * @throws SecurityException if the caller is not system. |
| 2690 | */ |
| 2691 | private void enforceSystemCaller() { |
| 2692 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 2693 | throw new SecurityException("Caller must be system"); |
| 2694 | } |
| 2695 | } |
| 2696 | |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 2697 | private void enforceActiveEmergencySessionPermission() { |
| 2698 | mApp.enforceCallingOrSelfPermission( |
| 2699 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 2700 | } |
| 2701 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2702 | /** |
| 2703 | * Make sure the caller has the CALL_PHONE permission. |
| 2704 | * |
| 2705 | * @throws SecurityException if the caller does not have the required permission |
| 2706 | */ |
| 2707 | private void enforceCallPermission() { |
| 2708 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2709 | } |
| 2710 | |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 2711 | private void enforceSettingsPermission() { |
| 2712 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2713 | } |
| 2714 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2715 | private String createTelUrl(String number) { |
| 2716 | if (TextUtils.isEmpty(number)) { |
| 2717 | return null; |
| 2718 | } |
| 2719 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2720 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2721 | } |
| 2722 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2723 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2724 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2725 | } |
| 2726 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2727 | private static void logv(String msg) { |
| 2728 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2729 | } |
| 2730 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2731 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2732 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2733 | } |
| 2734 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2735 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2736 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2737 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2738 | } |
| 2739 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2740 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2741 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2742 | final long identity = Binder.clearCallingIdentity(); |
| 2743 | try { |
| 2744 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2745 | if (phone == null) { |
| 2746 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2747 | } else { |
| 2748 | return phone.getPhoneType(); |
| 2749 | } |
| 2750 | } finally { |
| 2751 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2752 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2753 | } |
| 2754 | |
| 2755 | /** |
| 2756 | * Returns the CDMA ERI icon index to display |
| 2757 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2758 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2759 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 2760 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 2761 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2762 | } |
| 2763 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2764 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2765 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 2766 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2767 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2768 | mApp, subId, callingPackage, callingFeatureId, |
| 2769 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2770 | return -1; |
| 2771 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2772 | |
| 2773 | final long identity = Binder.clearCallingIdentity(); |
| 2774 | try { |
| 2775 | final Phone phone = getPhone(subId); |
| 2776 | if (phone != null) { |
| 2777 | return phone.getCdmaEriIconIndex(); |
| 2778 | } else { |
| 2779 | return -1; |
| 2780 | } |
| 2781 | } finally { |
| 2782 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2783 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2784 | } |
| 2785 | |
| 2786 | /** |
| 2787 | * Returns the CDMA ERI icon mode, |
| 2788 | * 0 - ON |
| 2789 | * 1 - FLASHING |
| 2790 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2791 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2792 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 2793 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 2794 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2795 | } |
| 2796 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2797 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2798 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 2799 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2800 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2801 | mApp, subId, callingPackage, callingFeatureId, |
| 2802 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2803 | return -1; |
| 2804 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2805 | |
| 2806 | final long identity = Binder.clearCallingIdentity(); |
| 2807 | try { |
| 2808 | final Phone phone = getPhone(subId); |
| 2809 | if (phone != null) { |
| 2810 | return phone.getCdmaEriIconMode(); |
| 2811 | } else { |
| 2812 | return -1; |
| 2813 | } |
| 2814 | } finally { |
| 2815 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2816 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2817 | } |
| 2818 | |
| 2819 | /** |
| 2820 | * Returns the CDMA ERI text, |
| 2821 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2822 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2823 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 2824 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 2825 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2826 | } |
| 2827 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2828 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2829 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 2830 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2831 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2832 | mApp, subId, callingPackage, callingFeatureId, |
| 2833 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2834 | return null; |
| 2835 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2836 | |
| 2837 | final long identity = Binder.clearCallingIdentity(); |
| 2838 | try { |
| 2839 | final Phone phone = getPhone(subId); |
| 2840 | if (phone != null) { |
| 2841 | return phone.getCdmaEriText(); |
| 2842 | } else { |
| 2843 | return null; |
| 2844 | } |
| 2845 | } finally { |
| 2846 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2847 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2848 | } |
| 2849 | |
| 2850 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2851 | * Returns the CDMA MDN. |
| 2852 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2853 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2854 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2855 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2856 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2857 | |
| 2858 | final long identity = Binder.clearCallingIdentity(); |
| 2859 | try { |
| 2860 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2861 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2862 | return phone.getLine1Number(); |
| 2863 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2864 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2865 | return null; |
| 2866 | } |
| 2867 | } finally { |
| 2868 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2869 | } |
| 2870 | } |
| 2871 | |
| 2872 | /** |
| 2873 | * Returns the CDMA MIN. |
| 2874 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2875 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2876 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2877 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2878 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2879 | |
| 2880 | final long identity = Binder.clearCallingIdentity(); |
| 2881 | try { |
| 2882 | final Phone phone = getPhone(subId); |
| 2883 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 2884 | return phone.getCdmaMin(); |
| 2885 | } else { |
| 2886 | return null; |
| 2887 | } |
| 2888 | } finally { |
| 2889 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2890 | } |
| 2891 | } |
| 2892 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2893 | @Override |
| 2894 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 2895 | INumberVerificationCallback callback, String callingPackage) { |
| 2896 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 2897 | != PERMISSION_GRANTED) { |
| 2898 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 2899 | } |
| 2900 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 2901 | |
| 2902 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 2903 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 2904 | throw new SecurityException("Calling package must be configured in the device config"); |
| 2905 | } |
| 2906 | |
| 2907 | if (range == null) { |
| 2908 | throw new NullPointerException("Range must be non-null"); |
| 2909 | } |
| 2910 | |
| 2911 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 2912 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 2913 | |
| 2914 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 2915 | } |
| 2916 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 2917 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2918 | * Returns true if CDMA provisioning needs to run. |
| 2919 | */ |
| 2920 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2921 | final long identity = Binder.clearCallingIdentity(); |
| 2922 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2923 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2924 | } finally { |
| 2925 | Binder.restoreCallingIdentity(identity); |
| 2926 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2927 | } |
| 2928 | |
| 2929 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2930 | * Sets the voice mail number of a given subId. |
| 2931 | */ |
| 2932 | @Override |
| 2933 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 2934 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 2935 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2936 | |
| 2937 | final long identity = Binder.clearCallingIdentity(); |
| 2938 | try { |
| 2939 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 2940 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 2941 | return success; |
| 2942 | } finally { |
| 2943 | Binder.restoreCallingIdentity(identity); |
| 2944 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 2945 | } |
| 2946 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2947 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2948 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 2949 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 2950 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 2951 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2952 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 2953 | throw new SecurityException("caller must be system dialer"); |
| 2954 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2955 | |
| 2956 | final long identity = Binder.clearCallingIdentity(); |
| 2957 | try { |
| 2958 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 2959 | if (phoneAccountHandle == null) { |
| 2960 | return null; |
| 2961 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2962 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2963 | } finally { |
| 2964 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2965 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 2966 | } |
| 2967 | |
| 2968 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2969 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 2970 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2971 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2972 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2973 | mApp, subId, callingPackage, callingFeatureId, |
| 2974 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2975 | return null; |
| 2976 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2977 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2978 | final long identity = Binder.clearCallingIdentity(); |
| 2979 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2980 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 2981 | } finally { |
| 2982 | Binder.restoreCallingIdentity(identity); |
| 2983 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 2984 | } |
| 2985 | |
| 2986 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 2987 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 2988 | VisualVoicemailSmsFilterSettings settings) { |
| 2989 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2990 | |
| 2991 | final long identity = Binder.clearCallingIdentity(); |
| 2992 | try { |
| 2993 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2994 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2995 | } finally { |
| 2996 | Binder.restoreCallingIdentity(identity); |
| 2997 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 2998 | } |
| 2999 | |
| 3000 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3001 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3002 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3003 | |
| 3004 | final long identity = Binder.clearCallingIdentity(); |
| 3005 | try { |
| 3006 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3007 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3008 | } finally { |
| 3009 | Binder.restoreCallingIdentity(identity); |
| 3010 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3011 | } |
| 3012 | |
| 3013 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3014 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3015 | String callingPackage, int subId) { |
| 3016 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3017 | |
| 3018 | final long identity = Binder.clearCallingIdentity(); |
| 3019 | try { |
| 3020 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3021 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3022 | } finally { |
| 3023 | Binder.restoreCallingIdentity(identity); |
| 3024 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3025 | } |
| 3026 | |
| 3027 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3028 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3029 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3030 | |
| 3031 | final long identity = Binder.clearCallingIdentity(); |
| 3032 | try { |
| 3033 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3034 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3035 | } finally { |
| 3036 | Binder.restoreCallingIdentity(identity); |
| 3037 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3038 | } |
| 3039 | |
| 3040 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3041 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3042 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3043 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3044 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3045 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3046 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3047 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3048 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3049 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3050 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3051 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3052 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3053 | * Sets the voice activation state of a given subId. |
| 3054 | */ |
| 3055 | @Override |
| 3056 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3057 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3058 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3059 | |
| 3060 | final long identity = Binder.clearCallingIdentity(); |
| 3061 | try { |
| 3062 | final Phone phone = getPhone(subId); |
| 3063 | if (phone != null) { |
| 3064 | phone.setVoiceActivationState(activationState); |
| 3065 | } else { |
| 3066 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3067 | } |
| 3068 | } finally { |
| 3069 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3070 | } |
| 3071 | } |
| 3072 | |
| 3073 | /** |
| 3074 | * Sets the data activation state of a given subId. |
| 3075 | */ |
| 3076 | @Override |
| 3077 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3078 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3079 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3080 | |
| 3081 | final long identity = Binder.clearCallingIdentity(); |
| 3082 | try { |
| 3083 | final Phone phone = getPhone(subId); |
| 3084 | if (phone != null) { |
| 3085 | phone.setDataActivationState(activationState); |
| 3086 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3087 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3088 | } |
| 3089 | } finally { |
| 3090 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3091 | } |
| 3092 | } |
| 3093 | |
| 3094 | /** |
| 3095 | * Returns the voice activation state of a given subId. |
| 3096 | */ |
| 3097 | @Override |
| 3098 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3099 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3100 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3101 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3102 | final long identity = Binder.clearCallingIdentity(); |
| 3103 | try { |
| 3104 | if (phone != null) { |
| 3105 | return phone.getVoiceActivationState(); |
| 3106 | } else { |
| 3107 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3108 | } |
| 3109 | } finally { |
| 3110 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3111 | } |
| 3112 | } |
| 3113 | |
| 3114 | /** |
| 3115 | * Returns the data activation state of a given subId. |
| 3116 | */ |
| 3117 | @Override |
| 3118 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3119 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3120 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3121 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3122 | final long identity = Binder.clearCallingIdentity(); |
| 3123 | try { |
| 3124 | if (phone != null) { |
| 3125 | return phone.getDataActivationState(); |
| 3126 | } else { |
| 3127 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3128 | } |
| 3129 | } finally { |
| 3130 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3131 | } |
| 3132 | } |
| 3133 | |
| 3134 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3135 | * Returns the unread count of voicemails for a subId |
| 3136 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3137 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3138 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3139 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3140 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3141 | mApp, subId, callingPackage, callingFeatureId, |
| 3142 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3143 | return 0; |
| 3144 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3145 | final long identity = Binder.clearCallingIdentity(); |
| 3146 | try { |
| 3147 | final Phone phone = getPhone(subId); |
| 3148 | if (phone != null) { |
| 3149 | return phone.getVoiceMessageCount(); |
| 3150 | } else { |
| 3151 | return 0; |
| 3152 | } |
| 3153 | } finally { |
| 3154 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3155 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3156 | } |
| 3157 | |
| 3158 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3159 | * returns true, if the device is in a state where both voice and data |
| 3160 | * are supported simultaneously. This can change based on location or network condition. |
| 3161 | */ |
| 3162 | @Override |
| 3163 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3164 | final long identity = Binder.clearCallingIdentity(); |
| 3165 | try { |
| 3166 | final Phone phone = getPhone(subId); |
| 3167 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3168 | } finally { |
| 3169 | Binder.restoreCallingIdentity(identity); |
| 3170 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3171 | } |
| 3172 | |
| 3173 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3174 | * Send the dialer code if called from the current default dialer or the caller has |
| 3175 | * carrier privilege. |
| 3176 | * @param inputCode The dialer code to send |
| 3177 | */ |
| 3178 | @Override |
| 3179 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3180 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3181 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3182 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3183 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3184 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3185 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3186 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3187 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3188 | |
| 3189 | final long identity = Binder.clearCallingIdentity(); |
| 3190 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3191 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3192 | } finally { |
| 3193 | Binder.restoreCallingIdentity(identity); |
| 3194 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3195 | } |
| 3196 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3197 | @Override |
| 3198 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3199 | TelephonyPermissions |
| 3200 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3201 | mApp, subId, "getNetworkSelectionMode"); |
| 3202 | final long identity = Binder.clearCallingIdentity(); |
| 3203 | try { |
| 3204 | if (!isActiveSubscription(subId)) { |
| 3205 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3206 | } |
| 3207 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3208 | } finally { |
| 3209 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3210 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3211 | } |
| 3212 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3213 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3214 | public boolean isInEmergencySmsMode() { |
| 3215 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3216 | final long identity = Binder.clearCallingIdentity(); |
| 3217 | try { |
| 3218 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3219 | if (phone.isInEmergencySmsMode()) { |
| 3220 | return true; |
| 3221 | } |
| 3222 | } |
| 3223 | } finally { |
| 3224 | Binder.restoreCallingIdentity(identity); |
| 3225 | } |
| 3226 | return false; |
| 3227 | } |
| 3228 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3229 | /** |
| 3230 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3231 | * @param subId The subscription to use to check the configuration. |
| 3232 | * @param c The callback that will be used to send the result. |
| 3233 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3234 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3235 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3236 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3237 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3238 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3239 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3240 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3241 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3242 | "IMS not available on device."); |
| 3243 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3244 | final long token = Binder.clearCallingIdentity(); |
| 3245 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3246 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3247 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3248 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3249 | } catch (ImsException e) { |
| 3250 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3251 | } finally { |
| 3252 | Binder.restoreCallingIdentity(token); |
| 3253 | } |
| 3254 | } |
| 3255 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3256 | /** |
| 3257 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3258 | * @param subId The subscription to use to check the configuration. |
| 3259 | * @param c The callback that will be used to send the result. |
| 3260 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3261 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3262 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3263 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3264 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3265 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3266 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3267 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3268 | final long token = Binder.clearCallingIdentity(); |
| 3269 | try { |
| 3270 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3271 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3272 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3273 | } catch (ImsException e) { |
| 3274 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3275 | + "is inactive, ignoring unregister."); |
| 3276 | // If the subscription is no longer active, just return, since the callback |
| 3277 | // will already have been removed internally. |
| 3278 | } finally { |
| 3279 | Binder.restoreCallingIdentity(token); |
| 3280 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3281 | } |
| 3282 | |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3283 | /** |
| 3284 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3285 | */ |
| 3286 | @Override |
| 3287 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3288 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3289 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3290 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3291 | "IMS not available on device."); |
| 3292 | } |
| 3293 | final long token = Binder.clearCallingIdentity(); |
| 3294 | try { |
| 3295 | Phone phone = getPhone(subId); |
| 3296 | if (phone == null) { |
| 3297 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3298 | + subId + "'"); |
| 3299 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3300 | } |
| 3301 | phone.getImsRegistrationState(regState -> { |
| 3302 | try { |
| 3303 | consumer.accept((regState == null) |
| 3304 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3305 | } catch (RemoteException e) { |
| 3306 | // Ignore if the remote process is no longer available to call back. |
| 3307 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3308 | } |
| 3309 | }); |
| 3310 | } finally { |
| 3311 | Binder.restoreCallingIdentity(token); |
| 3312 | } |
| 3313 | } |
| 3314 | |
| 3315 | /** |
| 3316 | * Get the transport type for the IMS service registration state. |
| 3317 | */ |
| 3318 | @Override |
| 3319 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3320 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3321 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3322 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3323 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3324 | "IMS not available on device."); |
| 3325 | } |
| 3326 | final long token = Binder.clearCallingIdentity(); |
| 3327 | try { |
| 3328 | Phone phone = getPhone(subId); |
| 3329 | if (phone == null) { |
| 3330 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3331 | + subId + "'"); |
| 3332 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3333 | } |
| 3334 | phone.getImsRegistrationTech(regTech -> { |
| 3335 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3336 | int regTechConverted = (regTech == null) |
| 3337 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3338 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3339 | regTechConverted); |
| 3340 | try { |
| 3341 | consumer.accept(regTechConverted); |
| 3342 | } catch (RemoteException e) { |
| 3343 | // Ignore if the remote process is no longer available to call back. |
| 3344 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3345 | } |
| 3346 | }); |
| 3347 | } finally { |
| 3348 | Binder.restoreCallingIdentity(token); |
| 3349 | } |
| 3350 | } |
| 3351 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3352 | /** |
| 3353 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3354 | * @param subId The subscription to use to check the configuration. |
| 3355 | * @param c The callback that will be used to send the result. |
| 3356 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3357 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3358 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3359 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3360 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3361 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3362 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3363 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3364 | "IMS not available on device."); |
| 3365 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3366 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3367 | final long token = Binder.clearCallingIdentity(); |
| 3368 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3369 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3370 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3371 | } catch (ImsException e) { |
| 3372 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3373 | } finally { |
| 3374 | Binder.restoreCallingIdentity(token); |
| 3375 | } |
| 3376 | } |
| 3377 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3378 | /** |
| 3379 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3380 | * @param subId The subscription to use to check the configuration. |
| 3381 | * @param c The callback that will be used to send the result. |
| 3382 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3383 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3384 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3385 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3386 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3387 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3388 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3389 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3390 | |
| 3391 | final long token = Binder.clearCallingIdentity(); |
| 3392 | try { |
| 3393 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3394 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3395 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3396 | } catch (ImsException e) { |
| 3397 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3398 | + "is inactive, ignoring unregister."); |
| 3399 | // If the subscription is no longer active, just return, since the callback |
| 3400 | // will already have been removed internally. |
| 3401 | } finally { |
| 3402 | Binder.restoreCallingIdentity(token); |
| 3403 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3404 | } |
| 3405 | |
| 3406 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3407 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3408 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3409 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3410 | final long token = Binder.clearCallingIdentity(); |
| 3411 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3412 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3413 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3414 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3415 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3416 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3417 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3418 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3419 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3420 | } finally { |
| 3421 | Binder.restoreCallingIdentity(token); |
| 3422 | } |
| 3423 | } |
| 3424 | |
| 3425 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3426 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3427 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3428 | final long token = Binder.clearCallingIdentity(); |
| 3429 | try { |
| 3430 | Phone phone = getPhone(subId); |
| 3431 | if (phone == null) return false; |
| 3432 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 32706d9 | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3433 | } catch (com.android.ims.ImsException e) { |
| 3434 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3435 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3436 | } finally { |
| 3437 | Binder.restoreCallingIdentity(token); |
| 3438 | } |
| 3439 | } |
| 3440 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3441 | /** |
| 3442 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3443 | * subscription. |
| 3444 | * @param subId The subscription to use to check the configuration. |
| 3445 | * @param callback The callback that will be used to send the result. |
| 3446 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3447 | * @param transportType The transport type of the MmTelFeature capability. |
| 3448 | */ |
| 3449 | @Override |
| 3450 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3451 | int transportType) { |
| 3452 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3453 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3454 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3455 | "IMS not available on device."); |
| 3456 | } |
| 3457 | final long token = Binder.clearCallingIdentity(); |
| 3458 | try { |
| 3459 | int slotId = getSlotIndex(subId); |
| 3460 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3461 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3462 | + subId + "'"); |
| 3463 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3464 | } |
| 3465 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3466 | transportType, aBoolean -> { |
| 3467 | try { |
| 3468 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3469 | } catch (RemoteException e) { |
| 3470 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3471 | + "running. Ignore"); |
| 3472 | } |
| 3473 | }); |
| 3474 | } finally { |
| 3475 | Binder.restoreCallingIdentity(token); |
| 3476 | } |
| 3477 | } |
| 3478 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3479 | /** |
| 3480 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3481 | * @param subId The subscription to use to check the configuration. |
| 3482 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3483 | @Override |
| 3484 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3485 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3486 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3487 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3488 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3489 | final long token = Binder.clearCallingIdentity(); |
| 3490 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3491 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3492 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3493 | } catch (ImsException e) { |
| 3494 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3495 | } finally { |
| 3496 | Binder.restoreCallingIdentity(token); |
| 3497 | } |
| 3498 | } |
| 3499 | |
| 3500 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3501 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3502 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3503 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3504 | final long identity = Binder.clearCallingIdentity(); |
| 3505 | try { |
| 3506 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3507 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3508 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
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(identity); |
| 3513 | } |
| 3514 | } |
| 3515 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3516 | /** |
| 3517 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3518 | * @param subId The subscription to use to check the configuration. |
| 3519 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3520 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3521 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3522 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3523 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3524 | final long identity = Binder.clearCallingIdentity(); |
| 3525 | try { |
| 3526 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3527 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3528 | } catch (ImsException e) { |
| 3529 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3530 | } finally { |
| 3531 | Binder.restoreCallingIdentity(identity); |
| 3532 | } |
| 3533 | } |
| 3534 | |
| 3535 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3536 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3537 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3538 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3539 | final long identity = Binder.clearCallingIdentity(); |
| 3540 | try { |
| 3541 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3542 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3543 | } catch (ImsException e) { |
| 3544 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3545 | } finally { |
| 3546 | Binder.restoreCallingIdentity(identity); |
| 3547 | } |
| 3548 | } |
| 3549 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3550 | /** |
| 3551 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3552 | * @param subId The subscription to use to check the configuration. |
| 3553 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3554 | @Override |
| 3555 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3556 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3557 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3558 | final long identity = Binder.clearCallingIdentity(); |
| 3559 | try { |
| 3560 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3561 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3562 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3563 | } catch (ImsException e) { |
| 3564 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3565 | } finally { |
| 3566 | Binder.restoreCallingIdentity(identity); |
| 3567 | } |
| 3568 | } |
| 3569 | |
| 3570 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3571 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3572 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3573 | "setVoWiFiSettingEnabled"); |
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 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3578 | } catch (ImsException e) { |
| 3579 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3580 | } finally { |
| 3581 | Binder.restoreCallingIdentity(identity); |
| 3582 | } |
| 3583 | } |
| 3584 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3585 | /** |
| 3586 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3587 | * @param subId The subscription to use to check the configuration. |
| 3588 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3589 | @Override |
| 3590 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3591 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3592 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3593 | final long identity = Binder.clearCallingIdentity(); |
| 3594 | try { |
| 3595 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3596 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3597 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3598 | } catch (ImsException e) { |
| 3599 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3600 | } finally { |
| 3601 | Binder.restoreCallingIdentity(identity); |
| 3602 | } |
| 3603 | } |
| 3604 | |
| 3605 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3606 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3607 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3608 | "setVoWiFiRoamingSettingEnabled"); |
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 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3613 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
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 |
| 3622 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3623 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3624 | "setVoWiFiNonPersistent"); |
| 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 | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3629 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
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 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3637 | /** |
| 3638 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3639 | * @param subId The subscription to use to check the configuration. |
| 3640 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3641 | @Override |
| 3642 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3643 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3644 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3645 | final long identity = Binder.clearCallingIdentity(); |
| 3646 | try { |
| 3647 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3648 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3649 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3650 | } catch (ImsException e) { |
| 3651 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3652 | } finally { |
| 3653 | Binder.restoreCallingIdentity(identity); |
| 3654 | } |
| 3655 | } |
| 3656 | |
| 3657 | @Override |
| 3658 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3659 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3660 | "setVoWiFiModeSetting"); |
| 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 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3665 | getSlotIndexOrException(subId)).setWfcMode(mode, 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 int getVoWiFiRoamingModeSetting(int subId) { |
| 3675 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3676 | final long identity = Binder.clearCallingIdentity(); |
| 3677 | try { |
| 3678 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3679 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3680 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3681 | } catch (ImsException e) { |
| 3682 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3683 | } finally { |
| 3684 | Binder.restoreCallingIdentity(identity); |
| 3685 | } |
| 3686 | } |
| 3687 | |
| 3688 | @Override |
| 3689 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3690 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3691 | "setVoWiFiRoamingModeSetting"); |
| 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 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3696 | getSlotIndexOrException(subId)).setWfcMode(mode, 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 setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3706 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3707 | "setRttCapabilityEnabled"); |
| 3708 | final long identity = Binder.clearCallingIdentity(); |
| 3709 | try { |
| 3710 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3711 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3712 | } catch (ImsException e) { |
| 3713 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3714 | } finally { |
| 3715 | Binder.restoreCallingIdentity(identity); |
| 3716 | } |
| 3717 | } |
| 3718 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3719 | /** |
| 3720 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3721 | * @param subId The subscription to use to check the configuration. |
| 3722 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3723 | @Override |
| 3724 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3725 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3726 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3727 | final long identity = Binder.clearCallingIdentity(); |
| 3728 | try { |
| 3729 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3730 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3731 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3732 | } catch (ImsException e) { |
| 3733 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3734 | } finally { |
| 3735 | Binder.restoreCallingIdentity(identity); |
| 3736 | } |
| 3737 | } |
| 3738 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3739 | @Override |
| 3740 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3741 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3742 | final long identity = Binder.clearCallingIdentity(); |
| 3743 | try { |
Brad Ebinger | 6cf0f65 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 3744 | if (!isImsAvailableOnDevice()) { |
| 3745 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3746 | "IMS not available on device."); |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 3747 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3748 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3749 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3750 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3751 | } catch (ImsException e) { |
| 3752 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3753 | } finally { |
| 3754 | Binder.restoreCallingIdentity(identity); |
| 3755 | } |
| 3756 | } |
| 3757 | |
| 3758 | @Override |
| 3759 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3760 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3761 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3762 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3763 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3764 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3765 | try { |
| 3766 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3767 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3768 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3769 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3770 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 3771 | + "is inactive, ignoring unregister."); |
| 3772 | // If the subscription is no longer active, just return, since the callback will already |
| 3773 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3774 | } finally { |
| 3775 | Binder.restoreCallingIdentity(identity); |
| 3776 | } |
| 3777 | } |
| 3778 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3779 | |
| 3780 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 3781 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3782 | message); |
| 3783 | } |
| 3784 | |
| 3785 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 3786 | boolean isMmtelCapability) { |
| 3787 | Phone phone = getPhone(subId); |
| 3788 | if (phone == null) { |
| 3789 | loge("phone instance null for subid " + subId); |
| 3790 | return false; |
| 3791 | } |
| 3792 | if (isMmtelCapability) { |
| 3793 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3794 | return false; |
| 3795 | } |
| 3796 | } else { |
| 3797 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 3798 | return false; |
| 3799 | } |
| 3800 | } |
| 3801 | return true; |
| 3802 | } |
| 3803 | |
| 3804 | @Override |
| 3805 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 3806 | boolean isProvisioned) { |
| 3807 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 3808 | |
| 3809 | final long identity = Binder.clearCallingIdentity(); |
| 3810 | try { |
| 3811 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3812 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3813 | return; |
| 3814 | } |
| 3815 | |
| 3816 | // this capability requires provisioning, route to the correct API. |
| 3817 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3818 | switch (capability) { |
| 3819 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3820 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3821 | ims.setEabProvisioned(isProvisioned); |
| 3822 | break; |
| 3823 | default: { |
| 3824 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3825 | + "rcs capability '" + capability + "', which does not require " |
| 3826 | + "provisioning."); |
| 3827 | } |
| 3828 | } |
| 3829 | } finally { |
| 3830 | Binder.restoreCallingIdentity(identity); |
| 3831 | } |
| 3832 | |
| 3833 | } |
| 3834 | |
| 3835 | |
| 3836 | @Override |
| 3837 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 3838 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 3839 | final long identity = Binder.clearCallingIdentity(); |
| 3840 | try { |
| 3841 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3842 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 3843 | return true; |
| 3844 | } |
| 3845 | |
| 3846 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3847 | switch (capability) { |
| 3848 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 3849 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 3850 | return ims.isEabProvisionedOnDevice(); |
| 3851 | |
| 3852 | default: { |
| 3853 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 3854 | + "capability '" + capability + "', which does not require " |
| 3855 | + "provisioning."); |
| 3856 | } |
| 3857 | } |
| 3858 | |
| 3859 | } finally { |
| 3860 | Binder.restoreCallingIdentity(identity); |
| 3861 | } |
| 3862 | } |
| 3863 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3864 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3865 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 3866 | boolean isProvisioned) { |
| 3867 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3868 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3869 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3870 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3871 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3872 | final long identity = Binder.clearCallingIdentity(); |
| 3873 | try { |
| 3874 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3875 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3876 | return; |
| 3877 | } |
| 3878 | |
| 3879 | // this capability requires provisioning, route to the correct API. |
| 3880 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3881 | switch (capability) { |
| 3882 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3883 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3884 | ims.setVolteProvisioned(isProvisioned); |
| 3885 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3886 | ims.setWfcProvisioned(isProvisioned); |
| 3887 | } |
| 3888 | break; |
| 3889 | } |
| 3890 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3891 | // There is currently no difference in VT provisioning type. |
| 3892 | ims.setVtProvisioned(isProvisioned); |
| 3893 | break; |
| 3894 | } |
| 3895 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3896 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 3897 | // change the capability of the feature instead if needed. |
| 3898 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 3899 | == isProvisioned) { |
| 3900 | // No change in provisioning. |
| 3901 | return; |
| 3902 | } |
| 3903 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 3904 | try { |
| 3905 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3906 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3907 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 3908 | + ", Exception" + e.getMessage()); |
| 3909 | } |
| 3910 | break; |
| 3911 | } |
| 3912 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3913 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 3914 | + "MmTel capability '" + capability + "', which does not require " |
| 3915 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3916 | } |
| 3917 | } |
| 3918 | |
| 3919 | } finally { |
| 3920 | Binder.restoreCallingIdentity(identity); |
| 3921 | } |
| 3922 | } |
| 3923 | |
| 3924 | @Override |
| 3925 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 3926 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3927 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3928 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3929 | } |
| 3930 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 3931 | final long identity = Binder.clearCallingIdentity(); |
| 3932 | try { |
| 3933 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3934 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3935 | return true; |
| 3936 | } |
| 3937 | |
| 3938 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 3939 | switch (capability) { |
| 3940 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 3941 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3942 | return ims.isVolteProvisionedOnDevice(); |
| 3943 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 3944 | return ims.isWfcProvisionedOnDevice(); |
| 3945 | } |
| 3946 | // This should never happen, since we are checking tech above to make sure it |
| 3947 | // is either LTE or IWLAN. |
| 3948 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 3949 | + "capability."); |
| 3950 | } |
| 3951 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 3952 | // There is currently no difference in VT provisioning type. |
| 3953 | return ims.isVtProvisionedOnDevice(); |
| 3954 | } |
| 3955 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 3956 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 3957 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 3958 | } |
| 3959 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 3960 | throw new IllegalArgumentException( |
| 3961 | "Tried to get provisioning for MmTel capability '" + capability |
| 3962 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 3963 | } |
| 3964 | } |
| 3965 | |
| 3966 | } finally { |
| 3967 | Binder.restoreCallingIdentity(identity); |
| 3968 | } |
| 3969 | } |
| 3970 | |
| 3971 | @Override |
| 3972 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 3973 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3974 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3975 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3976 | } |
| 3977 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 3978 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3979 | return (provisionedBits & capability) > 0; |
| 3980 | } |
| 3981 | |
| 3982 | @Override |
| 3983 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 3984 | boolean isProvisioned) { |
| 3985 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 3986 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 3987 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 3988 | } |
| 3989 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3990 | "setProvisioningStatusForCapability"); |
| 3991 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 3992 | // If the current provisioning status for capability already matches isProvisioned, |
| 3993 | // do nothing. |
| 3994 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 3995 | return; |
| 3996 | } |
| 3997 | if (isProvisioned) { |
| 3998 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 3999 | } else { |
| 4000 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4001 | } |
| 4002 | } |
| 4003 | |
| 4004 | /** |
| 4005 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4006 | * technology. The bitfield should mirror the bitfield defined by |
| 4007 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4008 | */ |
| 4009 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4010 | String key = getMmTelProvisioningKey(subId, tech); |
| 4011 | // Default is no capabilities are provisioned. |
| 4012 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4013 | } |
| 4014 | |
| 4015 | /** |
| 4016 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4017 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4018 | * technology specified. |
| 4019 | * |
| 4020 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4021 | */ |
| 4022 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4023 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4024 | String key = getMmTelProvisioningKey(subId, tech); |
| 4025 | editor.putInt(key, newField); |
| 4026 | editor.commit(); |
| 4027 | } |
| 4028 | |
| 4029 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4030 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4031 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4032 | } |
| 4033 | |
| 4034 | /** |
| 4035 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4036 | * carrier associated with the subscription id. |
| 4037 | */ |
| 4038 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4039 | int capability) { |
| 4040 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4041 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4042 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4043 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4044 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4045 | false); |
| 4046 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4047 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4048 | |
| 4049 | // First check to make sure that the capability requires provisioning. |
| 4050 | switch (capability) { |
| 4051 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4052 | // intentional fallthrough |
| 4053 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4054 | if (requireVoiceVtProvisioning) { |
| 4055 | // Voice and Video requires provisioning |
| 4056 | return true; |
| 4057 | } |
| 4058 | break; |
| 4059 | } |
| 4060 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4061 | if (requireUtProvisioning) { |
| 4062 | // UT requires provisioning |
| 4063 | return true; |
| 4064 | } |
| 4065 | break; |
| 4066 | } |
| 4067 | } |
| 4068 | return false; |
| 4069 | } |
| 4070 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4071 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4072 | int capability) { |
| 4073 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4074 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4075 | |
| 4076 | boolean requireRcsProvisioning = c.getBoolean( |
| 4077 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4078 | |
| 4079 | // First check to make sure that the capability requires provisioning. |
| 4080 | switch (capability) { |
| 4081 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4082 | // intentional fallthrough |
| 4083 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4084 | if (requireRcsProvisioning) { |
| 4085 | // OPTION or PRESENCE requires provisioning |
| 4086 | return true; |
| 4087 | } |
| 4088 | break; |
| 4089 | } |
| 4090 | } |
| 4091 | return false; |
| 4092 | } |
| 4093 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4094 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4095 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4096 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4097 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4098 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4099 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4100 | final long identity = Binder.clearCallingIdentity(); |
| 4101 | try { |
| 4102 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4103 | int slotId = getSlotIndex(subId); |
| 4104 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4105 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4106 | + subId + "' for key:" + key); |
| 4107 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4108 | } |
| 4109 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4110 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4111 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4112 | + subId + "' for key:" + key); |
| 4113 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4114 | } finally { |
| 4115 | Binder.restoreCallingIdentity(identity); |
| 4116 | } |
| 4117 | } |
| 4118 | |
| 4119 | @Override |
| 4120 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4121 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4122 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4123 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4124 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4125 | final long identity = Binder.clearCallingIdentity(); |
| 4126 | try { |
| 4127 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4128 | int slotId = getSlotIndex(subId); |
| 4129 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4130 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4131 | + subId + "' for key:" + key); |
| 4132 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4133 | } |
| 4134 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4135 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4136 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4137 | + subId + "' for key:" + key); |
| 4138 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4139 | } finally { |
| 4140 | Binder.restoreCallingIdentity(identity); |
| 4141 | } |
| 4142 | } |
| 4143 | |
| 4144 | @Override |
| 4145 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4146 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4147 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4148 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4149 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4150 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4151 | final long identity = Binder.clearCallingIdentity(); |
| 4152 | try { |
| 4153 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4154 | int slotId = getSlotIndex(subId); |
| 4155 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4156 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4157 | + subId + "' for key:" + key); |
| 4158 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4159 | } |
| 4160 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4161 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4162 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4163 | + "' for key:" + key); |
| 4164 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4165 | } finally { |
| 4166 | Binder.restoreCallingIdentity(identity); |
| 4167 | } |
| 4168 | } |
| 4169 | |
| 4170 | @Override |
| 4171 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4172 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4173 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4174 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4175 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4176 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4177 | final long identity = Binder.clearCallingIdentity(); |
| 4178 | try { |
| 4179 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4180 | int slotId = getSlotIndex(subId); |
| 4181 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4182 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4183 | + subId + "' for key:" + key); |
| 4184 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4185 | } |
| 4186 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4187 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4188 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4189 | + "' for key:" + key); |
| 4190 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4191 | } finally { |
| 4192 | Binder.restoreCallingIdentity(identity); |
| 4193 | } |
| 4194 | } |
| 4195 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4196 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4197 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4198 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4199 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4200 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4201 | } |
| 4202 | return slotId; |
| 4203 | } |
| 4204 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4205 | private int getSlotIndex(int subId) { |
| 4206 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4207 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4208 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4209 | } |
| 4210 | return slotId; |
| 4211 | } |
| 4212 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4213 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4214 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4215 | */ |
| 4216 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4217 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4218 | String callingFeatureId) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4219 | final int targetSdk = getTargetSdk(callingPackage); |
| 4220 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4221 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4222 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4223 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4224 | mApp, subId, callingPackage, callingFeatureId, |
| 4225 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4226 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4227 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4228 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4229 | final long identity = Binder.clearCallingIdentity(); |
| 4230 | try { |
| 4231 | final Phone phone = getPhone(subId); |
| 4232 | if (phone != null) { |
| 4233 | return phone.getServiceState().getDataNetworkType(); |
| 4234 | } else { |
| 4235 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4236 | } |
| 4237 | } finally { |
| 4238 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4239 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4240 | } |
| 4241 | |
| 4242 | /** |
| 4243 | * Returns the data network type |
| 4244 | */ |
| 4245 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4246 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4247 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4248 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4249 | } |
| 4250 | |
| 4251 | /** |
| 4252 | * Returns the data network type for a subId |
| 4253 | */ |
| 4254 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4255 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4256 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4257 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4258 | mApp, subId, callingPackage, callingFeatureId, |
| 4259 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4260 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4261 | } |
| 4262 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4263 | final long identity = Binder.clearCallingIdentity(); |
| 4264 | try { |
| 4265 | final Phone phone = getPhone(subId); |
| 4266 | if (phone != null) { |
| 4267 | return phone.getServiceState().getDataNetworkType(); |
| 4268 | } else { |
| 4269 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4270 | } |
| 4271 | } finally { |
| 4272 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4273 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4274 | } |
| 4275 | |
| 4276 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4277 | * Returns the Voice network type for a subId |
| 4278 | */ |
| 4279 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4280 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4281 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4282 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4283 | mApp, subId, callingPackage, callingFeatureId, |
| 4284 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4285 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4286 | } |
| 4287 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4288 | final long identity = Binder.clearCallingIdentity(); |
| 4289 | try { |
| 4290 | final Phone phone = getPhone(subId); |
| 4291 | if (phone != null) { |
| 4292 | return phone.getServiceState().getVoiceNetworkType(); |
| 4293 | } else { |
| 4294 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4295 | } |
| 4296 | } finally { |
| 4297 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4298 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4299 | } |
| 4300 | |
| 4301 | /** |
| 4302 | * @return true if a ICC card is present |
| 4303 | */ |
| 4304 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4305 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4306 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4307 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4308 | } |
| 4309 | |
| 4310 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4311 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4312 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4313 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4314 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4315 | final long identity = Binder.clearCallingIdentity(); |
| 4316 | try { |
| 4317 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4318 | if (phone != null) { |
| 4319 | return phone.getIccCard().hasIccCard(); |
| 4320 | } else { |
| 4321 | return false; |
| 4322 | } |
| 4323 | } finally { |
| 4324 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4325 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4326 | } |
| 4327 | |
| 4328 | /** |
| 4329 | * Return if the current radio is LTE on CDMA. This |
| 4330 | * is a tri-state return value as for a period of time |
| 4331 | * the mode may be unknown. |
| 4332 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4333 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4334 | * @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] | 4335 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4336 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4337 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4338 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4339 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4340 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4341 | } |
| 4342 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4343 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4344 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4345 | String callingFeatureId) { |
Sarah Chin | f6656a6 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4346 | try { |
| 4347 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4348 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4349 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4350 | } |
| 4351 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4352 | final long identity = Binder.clearCallingIdentity(); |
| 4353 | try { |
| 4354 | final Phone phone = getPhone(subId); |
| 4355 | if (phone == null) { |
| 4356 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4357 | } else { |
| 4358 | return phone.getLteOnCdmaMode(); |
| 4359 | } |
| 4360 | } finally { |
| 4361 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4362 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4363 | } |
| 4364 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4365 | /** |
| 4366 | * {@hide} |
| 4367 | * Returns Default subId, 0 in the case of single standby. |
| 4368 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4369 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4370 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4371 | } |
| 4372 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4373 | private int getSlotForDefaultSubscription() { |
| 4374 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4375 | } |
| 4376 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4377 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4378 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4379 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4380 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4381 | private boolean isActiveSubscription(int subId) { |
| 4382 | return mSubscriptionController.isActiveSubId(subId); |
| 4383 | } |
| 4384 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4385 | /** |
| 4386 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4387 | */ |
| 4388 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4389 | final long identity = Binder.clearCallingIdentity(); |
| 4390 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4391 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4392 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4393 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4394 | } finally { |
| 4395 | Binder.restoreCallingIdentity(identity); |
| 4396 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4397 | } |
| 4398 | |
| 4399 | /** |
| 4400 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4401 | */ |
| 4402 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4403 | final long identity = Binder.clearCallingIdentity(); |
| 4404 | try { |
| 4405 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4406 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4407 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4408 | } finally { |
| 4409 | Binder.restoreCallingIdentity(identity); |
| 4410 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4411 | } |
| 4412 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4413 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4414 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4415 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4416 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4417 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4418 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4419 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4420 | if (phoneId == -1) { |
| 4421 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4422 | + " does not correspond to an active phone"); |
| 4423 | } |
| 4424 | return PhoneFactory.getPhone(phoneId); |
| 4425 | } |
| 4426 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4427 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4428 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4429 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4430 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4431 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4432 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4433 | if (DBG) { |
| 4434 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4435 | } |
| 4436 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4437 | p2); |
| 4438 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4439 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4440 | |
| 4441 | @Override |
| 4442 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4443 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4444 | enforceModifyPermission(); |
| 4445 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4446 | if (DBG) { |
| 4447 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4448 | } |
| 4449 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4450 | callingPackage, aid, p2); |
| 4451 | } |
| 4452 | |
| 4453 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4454 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4455 | final long identity = Binder.clearCallingIdentity(); |
| 4456 | try { |
| 4457 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4458 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4459 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4460 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4461 | if (bestComponent == null |
| 4462 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4463 | loge("The calling package is not allowed to access ISD-R."); |
| 4464 | throw new SecurityException( |
| 4465 | "The calling package is not allowed to access ISD-R."); |
| 4466 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4467 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4468 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4469 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4470 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4471 | null /* workSource */); |
| 4472 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4473 | return response; |
| 4474 | } finally { |
| 4475 | Binder.restoreCallingIdentity(identity); |
| 4476 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4477 | } |
| 4478 | |
| 4479 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4480 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4481 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4482 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4483 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4484 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4485 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4486 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4487 | @Override |
| 4488 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4489 | enforceModifyPermission(); |
| 4490 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4491 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4492 | channel); |
| 4493 | } |
| 4494 | |
| 4495 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4496 | final long identity = Binder.clearCallingIdentity(); |
| 4497 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4498 | if (channel < 0) { |
| 4499 | return false; |
| 4500 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4501 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4502 | null /* workSource */); |
| 4503 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4504 | return success; |
| 4505 | } finally { |
| 4506 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4507 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4508 | } |
| 4509 | |
| 4510 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4511 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4512 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4513 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4514 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4515 | if (DBG) { |
| 4516 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4517 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4518 | + p3 + " data=" + data); |
| 4519 | } |
| 4520 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4521 | command, p1, p2, p3, data); |
| 4522 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4523 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4524 | @Override |
| 4525 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4526 | int command, int p1, int p2, int p3, String data) { |
| 4527 | enforceModifyPermission(); |
| 4528 | if (DBG) { |
| 4529 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4530 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4531 | + p3 + " data=" + data); |
| 4532 | } |
| 4533 | return iccTransmitApduLogicalChannelWithPermission( |
| 4534 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4535 | data); |
| 4536 | } |
| 4537 | |
| 4538 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4539 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4540 | final long identity = Binder.clearCallingIdentity(); |
| 4541 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4542 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4543 | return ""; |
| 4544 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4545 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4546 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4547 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4548 | null /* workSource */); |
| 4549 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4550 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4551 | // Append the returned status code to the end of the response payload. |
| 4552 | String s = Integer.toHexString( |
| 4553 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4554 | if (response.payload != null) { |
| 4555 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4556 | } |
| 4557 | return s; |
| 4558 | } finally { |
| 4559 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4560 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4561 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4562 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4563 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4564 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4565 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4566 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4567 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4568 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4569 | if (DBG) { |
| 4570 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4571 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4572 | } |
| 4573 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4574 | cla, command, p1, p2, p3, data); |
| 4575 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4576 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4577 | @Override |
| 4578 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4579 | int command, int p1, int p2, int p3, String data) { |
| 4580 | enforceModifyPermission(); |
| 4581 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4582 | if (DBG) { |
| 4583 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4584 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4585 | + " data=" + data); |
| 4586 | } |
| 4587 | |
| 4588 | return iccTransmitApduBasicChannelWithPermission( |
| 4589 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4590 | p2, p3, data); |
| 4591 | } |
| 4592 | |
| 4593 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4594 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4595 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4596 | final long identity = Binder.clearCallingIdentity(); |
| 4597 | try { |
| 4598 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4599 | && TextUtils.equals(ISDR_AID, data)) { |
| 4600 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4601 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4602 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4603 | if (bestComponent == null |
| 4604 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4605 | loge("The calling package is not allowed to select ISD-R."); |
| 4606 | throw new SecurityException( |
| 4607 | "The calling package is not allowed to select ISD-R."); |
| 4608 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4609 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4610 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4611 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4612 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4613 | null /* workSource */); |
| 4614 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4615 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4616 | // Append the returned status code to the end of the response payload. |
| 4617 | String s = Integer.toHexString( |
| 4618 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4619 | if (response.payload != null) { |
| 4620 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4621 | } |
| 4622 | return s; |
| 4623 | } finally { |
| 4624 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4625 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4626 | } |
| 4627 | |
| 4628 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4629 | 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] | 4630 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4631 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4632 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4633 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4634 | final long identity = Binder.clearCallingIdentity(); |
| 4635 | try { |
| 4636 | if (DBG) { |
| 4637 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4638 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4639 | } |
| 4640 | |
| 4641 | IccIoResult response = |
| 4642 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4643 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4644 | subId); |
| 4645 | |
| 4646 | if (DBG) { |
| 4647 | log("Exchange SIM_IO [R]" + response); |
| 4648 | } |
| 4649 | |
| 4650 | byte[] result = null; |
| 4651 | int length = 2; |
| 4652 | if (response.payload != null) { |
| 4653 | length = 2 + response.payload.length; |
| 4654 | result = new byte[length]; |
| 4655 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4656 | } else { |
| 4657 | result = new byte[length]; |
| 4658 | } |
| 4659 | |
| 4660 | result[length - 1] = (byte) response.sw2; |
| 4661 | result[length - 2] = (byte) response.sw1; |
| 4662 | return result; |
| 4663 | } finally { |
| 4664 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4665 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4666 | } |
| 4667 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4668 | /** |
| 4669 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4670 | * on a particular subscription |
| 4671 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4672 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 4673 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4674 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4675 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4676 | return null; |
| 4677 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4678 | |
| 4679 | final long identity = Binder.clearCallingIdentity(); |
| 4680 | try { |
| 4681 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4682 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4683 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4684 | return null; |
| 4685 | } |
| 4686 | Object response = sendRequest( |
| 4687 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4688 | if (response instanceof String[]) { |
| 4689 | return (String[]) response; |
| 4690 | } |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4691 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4692 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4693 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4694 | } finally { |
| 4695 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4696 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4697 | } |
| 4698 | |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4699 | /** |
| 4700 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 4701 | * subscription. |
| 4702 | * |
| 4703 | * @param subId the id of the subscription. |
| 4704 | * @param appType the uicc app type, must be USIM or SIM. |
| 4705 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 4706 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4707 | * @param callingFeatureId the feature in the package. |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4708 | * @return number of fplmns that is successfully written to the SIM. |
| 4709 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4710 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 4711 | String callingFeatureId) { |
| 4712 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 4713 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4714 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 4715 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 4716 | } |
| 4717 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 4718 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4719 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 4720 | } |
| 4721 | if (fplmns == null) { |
| 4722 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 4723 | } |
| 4724 | for (String fplmn : fplmns) { |
| 4725 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 4726 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 4727 | } |
| 4728 | } |
| 4729 | final long identity = Binder.clearCallingIdentity(); |
| 4730 | try { |
| 4731 | Object response = sendRequest( |
| 4732 | CMD_SET_FORBIDDEN_PLMNS, |
| 4733 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 4734 | subId); |
| 4735 | return (int) response; |
| 4736 | } finally { |
| 4737 | Binder.restoreCallingIdentity(identity); |
| 4738 | } |
| 4739 | } |
| 4740 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4741 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4742 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4743 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4744 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4745 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4746 | final long identity = Binder.clearCallingIdentity(); |
| 4747 | try { |
| 4748 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4749 | if (response.payload == null) { |
| 4750 | return ""; |
| 4751 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4752 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4753 | // Append the returned status code to the end of the response payload. |
| 4754 | String s = Integer.toHexString( |
| 4755 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4756 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4757 | return s; |
| 4758 | } finally { |
| 4759 | Binder.restoreCallingIdentity(identity); |
| 4760 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4761 | } |
| 4762 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4763 | /** |
| 4764 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4765 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4766 | * |
| 4767 | * @param itemID the ID of the item to read |
| 4768 | * @return the NV item as a String, or null on error. |
| 4769 | */ |
| 4770 | @Override |
| 4771 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4772 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4773 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4774 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4775 | |
| 4776 | final long identity = Binder.clearCallingIdentity(); |
| 4777 | try { |
| 4778 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4779 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4780 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 4781 | return value; |
| 4782 | } finally { |
| 4783 | Binder.restoreCallingIdentity(identity); |
| 4784 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4785 | } |
| 4786 | |
| 4787 | /** |
| 4788 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4789 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4790 | * |
| 4791 | * @param itemID the ID of the item to read |
| 4792 | * @param itemValue the value to write, as a String |
| 4793 | * @return true on success; false on any failure |
| 4794 | */ |
| 4795 | @Override |
| 4796 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4797 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4798 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4799 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4800 | |
| 4801 | final long identity = Binder.clearCallingIdentity(); |
| 4802 | try { |
| 4803 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 4804 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 4805 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4806 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 4807 | return success; |
| 4808 | } finally { |
| 4809 | Binder.restoreCallingIdentity(identity); |
| 4810 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4811 | } |
| 4812 | |
| 4813 | /** |
| 4814 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 4815 | * Used for device configuration by some CDMA operators. |
| 4816 | * |
| 4817 | * @param preferredRoamingList byte array containing the new PRL |
| 4818 | * @return true on success; false on any failure |
| 4819 | */ |
| 4820 | @Override |
| 4821 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4822 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4823 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4824 | |
| 4825 | final long identity = Binder.clearCallingIdentity(); |
| 4826 | try { |
| 4827 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 4828 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 4829 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 4830 | return success; |
| 4831 | } finally { |
| 4832 | Binder.restoreCallingIdentity(identity); |
| 4833 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4834 | } |
| 4835 | |
| 4836 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4837 | * 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] | 4838 | * Used for device configuration by some CDMA operators. |
| 4839 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4840 | * @param slotIndex - device slot. |
| 4841 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4842 | * @return true on success; false on any failure |
| 4843 | */ |
| 4844 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4845 | public boolean resetModemConfig(int slotIndex) { |
| 4846 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4847 | if (phone != null) { |
| 4848 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4849 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4850 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4851 | final long identity = Binder.clearCallingIdentity(); |
| 4852 | try { |
| 4853 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 4854 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 4855 | return success; |
| 4856 | } finally { |
| 4857 | Binder.restoreCallingIdentity(identity); |
| 4858 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4859 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 4860 | return false; |
| 4861 | } |
| 4862 | |
| 4863 | /** |
| 4864 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 4865 | * |
| 4866 | * @param slotIndex - device slot. |
| 4867 | * |
| 4868 | * @return true on success; false on any failure |
| 4869 | */ |
| 4870 | @Override |
| 4871 | public boolean rebootModem(int slotIndex) { |
| 4872 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4873 | if (phone != null) { |
| 4874 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4875 | mApp, phone.getSubId(), "rebootModem"); |
| 4876 | |
| 4877 | final long identity = Binder.clearCallingIdentity(); |
| 4878 | try { |
| 4879 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 4880 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 4881 | return success; |
| 4882 | } finally { |
| 4883 | Binder.restoreCallingIdentity(identity); |
| 4884 | } |
| 4885 | } |
| 4886 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4887 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 4888 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4889 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 4890 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4891 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4892 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 4893 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 4894 | return new String[0]; |
| 4895 | } |
| 4896 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4897 | final long identity = Binder.clearCallingIdentity(); |
| 4898 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4899 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4900 | } finally { |
| 4901 | Binder.restoreCallingIdentity(identity); |
| 4902 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4903 | } |
| 4904 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4905 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 4906 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 4907 | * {@link #disableIms(int)}. |
| 4908 | * @param slotIndex device slot. |
| 4909 | */ |
| 4910 | public void resetIms(int slotIndex) { |
| 4911 | enforceModifyPermission(); |
| 4912 | |
| 4913 | final long identity = Binder.clearCallingIdentity(); |
| 4914 | try { |
| 4915 | if (mImsResolver == null) { |
| 4916 | // may happen if the does not support IMS. |
| 4917 | return; |
| 4918 | } |
| 4919 | mImsResolver.disableIms(slotIndex); |
| 4920 | mImsResolver.enableIms(slotIndex); |
| 4921 | } finally { |
| 4922 | Binder.restoreCallingIdentity(identity); |
| 4923 | } |
| 4924 | } |
| 4925 | |
| 4926 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4927 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 4928 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4929 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4930 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 4931 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4932 | |
| 4933 | final long identity = Binder.clearCallingIdentity(); |
| 4934 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4935 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4936 | // may happen if the device does not support IMS. |
| 4937 | return; |
| 4938 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4939 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4940 | } finally { |
| 4941 | Binder.restoreCallingIdentity(identity); |
| 4942 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4943 | } |
| 4944 | |
| 4945 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4946 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 4947 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4948 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4949 | public void disableIms(int slotId) { |
| 4950 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4951 | |
| 4952 | final long identity = Binder.clearCallingIdentity(); |
| 4953 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4954 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4955 | // may happen if the device does not support IMS. |
| 4956 | return; |
| 4957 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4958 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4959 | } finally { |
| 4960 | Binder.restoreCallingIdentity(identity); |
| 4961 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 4962 | } |
| 4963 | |
| 4964 | /** |
| 4965 | * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel |
| 4966 | * feature or {@link null} if the service is not available. If the feature is available, the |
| 4967 | * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates. |
| 4968 | */ |
| 4969 | public IImsMmTelFeature getMmTelFeatureAndListen(int slotId, |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4970 | IImsServiceFeatureCallback callback) { |
| 4971 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4972 | |
| 4973 | final long identity = Binder.clearCallingIdentity(); |
| 4974 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4975 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4976 | // may happen if the device does not support IMS. |
| 4977 | return null; |
| 4978 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4979 | return mImsResolver.getMmTelFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4980 | } finally { |
| 4981 | Binder.restoreCallingIdentity(identity); |
| 4982 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 4983 | } |
| 4984 | |
| 4985 | /** |
| 4986 | * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS |
| 4987 | * feature during emergency calling or {@link null} if the service is not available. If the |
| 4988 | * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a |
| 4989 | * listener for feature updates. |
| 4990 | */ |
| 4991 | public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) { |
| 4992 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4993 | |
| 4994 | final long identity = Binder.clearCallingIdentity(); |
| 4995 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 4996 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 4997 | // may happen if the device does not support IMS. |
| 4998 | return null; |
| 4999 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5000 | return mImsResolver.getRcsFeatureAndListen(slotId, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5001 | } finally { |
| 5002 | Binder.restoreCallingIdentity(identity); |
| 5003 | } |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5004 | } |
| 5005 | |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5006 | /** |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5007 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5008 | */ |
| 5009 | public void unregisterImsFeatureCallback(int slotId, int featureType, |
| 5010 | IImsServiceFeatureCallback callback) { |
| 5011 | enforceModifyPermission(); |
| 5012 | |
| 5013 | final long identity = Binder.clearCallingIdentity(); |
| 5014 | try { |
| 5015 | if (mImsResolver == null) return; |
| 5016 | mImsResolver.unregisterImsFeatureCallback(slotId, featureType, callback); |
| 5017 | } finally { |
| 5018 | Binder.restoreCallingIdentity(identity); |
| 5019 | } |
| 5020 | } |
| 5021 | |
| 5022 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5023 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5024 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5025 | */ |
| 5026 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5027 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5028 | |
| 5029 | final long identity = Binder.clearCallingIdentity(); |
| 5030 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5031 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5032 | // may happen if the device does not support IMS. |
| 5033 | return null; |
| 5034 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5035 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5036 | } finally { |
| 5037 | Binder.restoreCallingIdentity(identity); |
| 5038 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5039 | } |
| 5040 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5041 | /** |
| 5042 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5043 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5044 | */ |
| 5045 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5046 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5047 | |
| 5048 | final long identity = Binder.clearCallingIdentity(); |
| 5049 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5050 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5051 | // may happen if the device does not support IMS. |
| 5052 | return null; |
| 5053 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5054 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5055 | } finally { |
| 5056 | Binder.restoreCallingIdentity(identity); |
| 5057 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5058 | } |
| 5059 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5060 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5061 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5062 | * |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5063 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5064 | * @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] | 5065 | * ImsService is the device default ImsService. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5066 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5067 | * @param packageName The name of the package that the current configuration will be replaced |
| 5068 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5069 | * @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] | 5070 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5071 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5072 | int[] featureTypes, String packageName) { |
| 5073 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5074 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5075 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5076 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5077 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5078 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5079 | final long identity = Binder.clearCallingIdentity(); |
| 5080 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5081 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5082 | // may happen if the device does not support IMS. |
| 5083 | return false; |
| 5084 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5085 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5086 | for (int featureType : featureTypes) { |
| 5087 | featureConfig.put(featureType, packageName); |
| 5088 | } |
| 5089 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5090 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5091 | } finally { |
| 5092 | Binder.restoreCallingIdentity(identity); |
| 5093 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5094 | } |
| 5095 | |
| 5096 | /** |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5097 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5098 | * |
| 5099 | * @param slotId The slot that the ImsService is associated with. |
| 5100 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5101 | * the device default. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5102 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5103 | * @return the package name of the ImsService configuration. |
| 5104 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5105 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5106 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5107 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5108 | TelephonyPermissions |
| 5109 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5110 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5111 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5112 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5113 | final long identity = Binder.clearCallingIdentity(); |
| 5114 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5115 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5116 | // may happen if the device does not support IMS. |
| 5117 | return ""; |
| 5118 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5119 | // TODO: change API to query RCS separately. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5120 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5121 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5122 | } finally { |
| 5123 | Binder.restoreCallingIdentity(identity); |
| 5124 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5125 | } |
| 5126 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5127 | /** |
| 5128 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5129 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5130 | * @param callback A callback with an integer containing the |
| 5131 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5132 | */ |
| 5133 | @Override |
| 5134 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5135 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5136 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5137 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5138 | "IMS not available on device."); |
| 5139 | } |
| 5140 | final long token = Binder.clearCallingIdentity(); |
| 5141 | try { |
| 5142 | int slotId = getSlotIndex(subId); |
| 5143 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5144 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5145 | + subId + "'"); |
| 5146 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5147 | } |
| 5148 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5149 | try { |
| 5150 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5151 | } catch (RemoteException e) { |
| 5152 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5153 | + "Ignore"); |
| 5154 | } |
| 5155 | }); |
| 5156 | } finally { |
| 5157 | Binder.restoreCallingIdentity(token); |
| 5158 | } |
| 5159 | } |
| 5160 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5161 | public void setImsRegistrationState(boolean registered) { |
| 5162 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5163 | |
| 5164 | final long identity = Binder.clearCallingIdentity(); |
| 5165 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5166 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5167 | } finally { |
| 5168 | Binder.restoreCallingIdentity(identity); |
| 5169 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5170 | } |
| 5171 | |
| 5172 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5173 | * Set the network selection mode to automatic. |
| 5174 | * |
| 5175 | */ |
| 5176 | @Override |
| 5177 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5178 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5179 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5180 | |
| 5181 | final long identity = Binder.clearCallingIdentity(); |
| 5182 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5183 | if (!isActiveSubscription(subId)) { |
| 5184 | return; |
| 5185 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5186 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 5187 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 5188 | } finally { |
| 5189 | Binder.restoreCallingIdentity(identity); |
| 5190 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5191 | } |
| 5192 | |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5193 | /** |
| 5194 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5195 | * |
| 5196 | * @param subId the id of the subscription. |
| 5197 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5198 | * the operator to attach to. |
| 5199 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5200 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5201 | * normal network selection next time. |
| 5202 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5203 | */ |
| 5204 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5205 | public boolean setNetworkSelectionModeManual( |
| 5206 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5207 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5208 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5209 | |
| 5210 | if (!isActiveSubscription(subId)) { |
| 5211 | return false; |
| 5212 | } |
| 5213 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5214 | final long identity = Binder.clearCallingIdentity(); |
| 5215 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5216 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5217 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5218 | if (DBG) { |
| 5219 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5220 | + " operator: " + operatorInfo); |
| 5221 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5222 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5223 | } finally { |
| 5224 | Binder.restoreCallingIdentity(identity); |
| 5225 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5226 | } |
| 5227 | |
| 5228 | /** |
| 5229 | * Scans for available networks. |
| 5230 | */ |
| 5231 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5232 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5233 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5234 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5235 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5236 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5237 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5238 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5239 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5240 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5241 | .setCallingPid(Binder.getCallingPid()) |
| 5242 | .setCallingUid(Binder.getCallingUid()) |
| 5243 | .setMethod("getCellNetworkScanResults") |
| 5244 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5245 | .build()); |
| 5246 | switch (locationResult) { |
| 5247 | case DENIED_HARD: |
| 5248 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5249 | case DENIED_SOFT: |
| 5250 | return null; |
| 5251 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5252 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5253 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5254 | try { |
| 5255 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5256 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5257 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5258 | } finally { |
| 5259 | Binder.restoreCallingIdentity(identity); |
| 5260 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5261 | } |
| 5262 | |
| 5263 | /** |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5264 | * Get the call forwarding info, given the call forwarding reason. |
| 5265 | */ |
| 5266 | @Override |
| 5267 | public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) { |
| 5268 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5269 | long identity = Binder.clearCallingIdentity(); |
| 5270 | try { |
| 5271 | if (DBG) { |
| 5272 | log("getCallForwarding: subId " + subId |
| 5273 | + " callForwardingReason" + callForwardingReason); |
| 5274 | } |
| 5275 | return (CallForwardingInfo) sendRequest( |
| 5276 | CMD_GET_CALL_FORWARDING, callForwardingReason, subId); |
| 5277 | } finally { |
| 5278 | Binder.restoreCallingIdentity(identity); |
| 5279 | } |
| 5280 | } |
| 5281 | |
| 5282 | /** |
| 5283 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5284 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5285 | */ |
| 5286 | @Override |
| 5287 | public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) { |
| 5288 | enforceModifyPermission(); |
| 5289 | long identity = Binder.clearCallingIdentity(); |
| 5290 | try { |
| 5291 | if (DBG) { |
| 5292 | log("setCallForwarding: subId " + subId |
| 5293 | + " callForwardingInfo" + callForwardingInfo); |
| 5294 | } |
| 5295 | return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId); |
| 5296 | } finally { |
| 5297 | Binder.restoreCallingIdentity(identity); |
| 5298 | } |
| 5299 | } |
| 5300 | |
| 5301 | /** |
| 5302 | * Get the call forwarding info, given the call forwarding reason. |
| 5303 | */ |
| 5304 | @Override |
| 5305 | public int getCallWaitingStatus(int subId) { |
| 5306 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5307 | long identity = Binder.clearCallingIdentity(); |
| 5308 | try { |
| 5309 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
| 5310 | return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId); |
| 5311 | } finally { |
| 5312 | Binder.restoreCallingIdentity(identity); |
| 5313 | } |
| 5314 | } |
| 5315 | |
| 5316 | /** |
| 5317 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5318 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5319 | */ |
| 5320 | @Override |
| 5321 | public boolean setCallWaitingStatus(int subId, boolean isEnable) { |
| 5322 | enforceModifyPermission(); |
| 5323 | long identity = Binder.clearCallingIdentity(); |
| 5324 | try { |
| 5325 | if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable); |
| 5326 | return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId); |
| 5327 | } finally { |
| 5328 | Binder.restoreCallingIdentity(identity); |
| 5329 | } |
| 5330 | } |
| 5331 | |
| 5332 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5333 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5334 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5335 | * @param subId id of the subscription |
| 5336 | * @param request contains the radio access networks with bands/channels to scan |
| 5337 | * @param messenger callback messenger for scan results or errors |
| 5338 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5339 | * @return the id of the requested scan which can be used to stop the scan. |
| 5340 | */ |
| 5341 | @Override |
| 5342 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5343 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5344 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5345 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5346 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5347 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5348 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5349 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5350 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5351 | .setCallingPid(Binder.getCallingPid()) |
| 5352 | .setCallingUid(Binder.getCallingUid()) |
| 5353 | .setMethod("requestNetworkScan") |
| 5354 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5355 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5356 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5357 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5358 | if (e != null) { |
| 5359 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5360 | throw e; |
| 5361 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5362 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5363 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5364 | } |
| 5365 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5366 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5367 | int callingUid = Binder.getCallingUid(); |
| 5368 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5369 | final long identity = Binder.clearCallingIdentity(); |
| 5370 | try { |
| 5371 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5372 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5373 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5374 | } finally { |
| 5375 | Binder.restoreCallingIdentity(identity); |
| 5376 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5377 | } |
| 5378 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5379 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5380 | NetworkScanRequest request, int subId) { |
| 5381 | boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid()) |
| 5382 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5383 | boolean hasNetworkScanPermission = |
| 5384 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5385 | == PERMISSION_GRANTED; |
| 5386 | |
| 5387 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5388 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5389 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5390 | } |
| 5391 | |
| 5392 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5393 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5394 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5395 | return new SecurityException("Specific channels must not be" |
| 5396 | + " scanned without location access."); |
| 5397 | } |
| 5398 | } |
| 5399 | } |
| 5400 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5401 | return null; |
| 5402 | } |
| 5403 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5404 | /** |
| 5405 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5406 | * |
| 5407 | * @param subId id of the subscription |
| 5408 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5409 | */ |
| 5410 | @Override |
| 5411 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5412 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5413 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5414 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5415 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5416 | final long identity = Binder.clearCallingIdentity(); |
| 5417 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5418 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5419 | } finally { |
| 5420 | Binder.restoreCallingIdentity(identity); |
| 5421 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5422 | } |
| 5423 | |
| 5424 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5425 | * Get the calculated preferred network type. |
| 5426 | * Used for debugging incorrect network type. |
| 5427 | * |
| 5428 | * @return the preferred network type, defined in RILConstants.java. |
| 5429 | */ |
| 5430 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5431 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5432 | final Phone defaultPhone = getDefaultPhone(); |
| 5433 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5434 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5435 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5436 | } |
| 5437 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5438 | final long identity = Binder.clearCallingIdentity(); |
| 5439 | try { |
| 5440 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5441 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5442 | } finally { |
| 5443 | Binder.restoreCallingIdentity(identity); |
| 5444 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5445 | } |
| 5446 | |
| 5447 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5448 | * Get the preferred network type. |
| 5449 | * Used for device configuration by some CDMA operators. |
| 5450 | * |
| 5451 | * @return the preferred network type, defined in RILConstants.java. |
| 5452 | */ |
| 5453 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5454 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5455 | TelephonyPermissions |
| 5456 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5457 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5458 | |
| 5459 | final long identity = Binder.clearCallingIdentity(); |
| 5460 | try { |
| 5461 | if (DBG) log("getPreferredNetworkType"); |
| 5462 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5463 | int networkType = (result != null ? result[0] : -1); |
| 5464 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5465 | return networkType; |
| 5466 | } finally { |
| 5467 | Binder.restoreCallingIdentity(identity); |
| 5468 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5469 | } |
| 5470 | |
| 5471 | /** |
| 5472 | * Set the preferred network type. |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5473 | * |
| 5474 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5475 | * @return true on success; false on any failure. |
| 5476 | */ |
| 5477 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5478 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5479 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5480 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5481 | |
| 5482 | final long identity = Binder.clearCallingIdentity(); |
| 5483 | try { |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5484 | Settings.Global.putInt(mApp.getContentResolver(), |
| 5485 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5486 | |
| 5487 | Boolean success = (Boolean) sendRequest( |
| 5488 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 5489 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 5490 | return success; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5491 | } finally { |
| 5492 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5493 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5494 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5495 | |
| 5496 | /** |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5497 | * Get the allowed network types that store in the telephony provider. |
| 5498 | * |
| 5499 | * @param subId the id of the subscription. |
| 5500 | * @return allowedNetworkTypes the allowed network types. |
| 5501 | */ |
| 5502 | @Override |
| 5503 | public long getAllowedNetworkTypes(int subId) { |
| 5504 | TelephonyPermissions |
| 5505 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5506 | mApp, subId, "getAllowedNetworkTypes"); |
| 5507 | |
| 5508 | final long identity = Binder.clearCallingIdentity(); |
| 5509 | try { |
| 5510 | return SubscriptionManager.getLongSubscriptionProperty( |
| 5511 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5512 | } finally { |
| 5513 | Binder.restoreCallingIdentity(identity); |
| 5514 | } |
| 5515 | } |
| 5516 | |
| 5517 | /** |
| 5518 | * Set the allowed network types. |
| 5519 | * |
| 5520 | * @param subId the id of the subscription. |
| 5521 | * @param allowedNetworkTypes the allowed network types. |
| 5522 | * @return true on success; false on any failure. |
| 5523 | */ |
| 5524 | @Override |
| 5525 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 5526 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5527 | mApp, subId, "setAllowedNetworkTypes"); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5528 | |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5529 | SubscriptionManager.setSubscriptionProperty(subId, |
| 5530 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 5531 | String.valueOf(allowedNetworkTypes)); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5532 | |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5533 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 5534 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5535 | RILConstants.PREFERRED_NETWORK_MODE); |
| 5536 | return setPreferredNetworkType(subId, preferredNetworkMode); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5537 | } |
| 5538 | |
| 5539 | /** |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame^] | 5540 | * Get the allowed network types for certain reason. |
| 5541 | * |
| 5542 | * @param subId the id of the subscription. |
| 5543 | * @param reason the reason the allowed network type change is taking place |
| 5544 | * @return the allowed network types. |
| 5545 | */ |
| 5546 | @Override |
| 5547 | public long getAllowedNetworkTypesForReason(int subId, |
| 5548 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
| 5549 | TelephonyPermissions |
| 5550 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5551 | mApp, subId, "getAllowedNetworkTypesForReason"); |
| 5552 | final long identity = Binder.clearCallingIdentity(); |
| 5553 | try { |
| 5554 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 5555 | } finally { |
| 5556 | Binder.restoreCallingIdentity(identity); |
| 5557 | } |
| 5558 | } |
| 5559 | |
| 5560 | /** |
| 5561 | * Get the effective allowed network types on the device. |
| 5562 | * This API will return an intersection of allowed network types for all reasons, |
| 5563 | * including the configuration done through setAllowedNetworkTypes |
| 5564 | * |
| 5565 | * @param subId the id of the subscription. |
| 5566 | * @return the allowed network types |
| 5567 | */ |
| 5568 | @Override |
| 5569 | public long getEffectiveAllowedNetworkTypes(int subId) { |
| 5570 | TelephonyPermissions |
| 5571 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5572 | mApp, subId, "getEffectiveAllowedNetworkTypes"); |
| 5573 | final long identity = Binder.clearCallingIdentity(); |
| 5574 | try { |
| 5575 | return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes(); |
| 5576 | } finally { |
| 5577 | Binder.restoreCallingIdentity(identity); |
| 5578 | } |
| 5579 | } |
| 5580 | |
| 5581 | /** |
| 5582 | * Set the allowed network types of the device and |
| 5583 | * provide the reason triggering the allowed network change. |
| 5584 | * |
| 5585 | * @param subId the id of the subscription. |
| 5586 | * @param reason the reason the allowed network type change is taking place |
| 5587 | * @param allowedNetworkTypes the allowed network types. |
| 5588 | * @return true on success; false on any failure. |
| 5589 | */ |
| 5590 | @Override |
| 5591 | public boolean setAllowedNetworkTypesForReason(int subId, |
| 5592 | @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) { |
| 5593 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5594 | mApp, subId, "setAllowedNetworkTypesForReason"); |
| 5595 | final long identity = Binder.clearCallingIdentity(); |
| 5596 | try { |
| 5597 | getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes); |
| 5598 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 5599 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5600 | RILConstants.PREFERRED_NETWORK_MODE); |
| 5601 | return setPreferredNetworkType(subId, preferredNetworkMode); |
| 5602 | } finally { |
| 5603 | Binder.restoreCallingIdentity(identity); |
| 5604 | } |
| 5605 | } |
| 5606 | |
| 5607 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5608 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5609 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5610 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 5611 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5612 | * @hide |
| 5613 | */ |
| 5614 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 5615 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5616 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5617 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5618 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5619 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 5620 | if (phone != null) { |
| 5621 | return phone.hasMatchedTetherApnSetting(); |
| 5622 | } else { |
| 5623 | return false; |
| 5624 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5625 | } finally { |
| 5626 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5627 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 5628 | } |
| 5629 | |
| 5630 | /** |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5631 | * Set mobile data enabled |
| 5632 | * Used by the user through settings etc to turn on/off mobile data |
| 5633 | * |
| 5634 | * @param enable {@code true} turn turn data on, else {@code false} |
| 5635 | */ |
| 5636 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5637 | public void setUserDataEnabled(int subId, boolean enable) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5638 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5639 | mApp, subId, "setUserDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5640 | |
| 5641 | final long identity = Binder.clearCallingIdentity(); |
| 5642 | try { |
| 5643 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5644 | if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5645 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5646 | if (phone != null) { |
| 5647 | if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable); |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5648 | phone.getDataEnabledSettings().setUserDataEnabled(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5649 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5650 | loge("setUserDataEnabled: no phone found. Invalid subId=" + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5651 | } |
| 5652 | } finally { |
| 5653 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5654 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5655 | } |
| 5656 | |
| 5657 | /** |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 5658 | * Enable or disable always reporting signal strength changes from radio. |
| 5659 | * |
| 5660 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 5661 | */ |
| 5662 | @Override |
| 5663 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 5664 | enforceModifyPermission(); |
| 5665 | enforceSystemCaller(); |
| 5666 | |
| 5667 | final long identity = Binder.clearCallingIdentity(); |
| 5668 | final Phone phone = getPhone(subId); |
| 5669 | try { |
| 5670 | if (phone != null) { |
| 5671 | if (DBG) { |
| 5672 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 5673 | + " isEnable=" + isEnable); |
| 5674 | } |
| 5675 | phone.setAlwaysReportSignalStrength(isEnable); |
| 5676 | } else { |
| 5677 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 5678 | + subId); |
| 5679 | } |
| 5680 | } finally { |
| 5681 | Binder.restoreCallingIdentity(identity); |
| 5682 | } |
| 5683 | } |
| 5684 | |
| 5685 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5686 | * Get the user enabled state of Mobile Data. |
| 5687 | * |
| 5688 | * TODO: remove and use isUserDataEnabled. |
| 5689 | * This can't be removed now because some vendor codes |
| 5690 | * calls through ITelephony directly while they should |
| 5691 | * use TelephonyManager. |
| 5692 | * |
| 5693 | * @return true on enabled |
| 5694 | */ |
| 5695 | @Override |
| 5696 | public boolean getDataEnabled(int subId) { |
| 5697 | return isUserDataEnabled(subId); |
| 5698 | } |
| 5699 | |
| 5700 | /** |
| 5701 | * Get whether mobile data is enabled per user setting. |
| 5702 | * |
| 5703 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 5704 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5705 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 5706 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5707 | * |
| 5708 | * @return {@code true} if data is enabled else {@code false} |
| 5709 | */ |
| 5710 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5711 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5712 | try { |
| 5713 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 5714 | null); |
| 5715 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5716 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5717 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 5718 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5719 | |
| 5720 | final long identity = Binder.clearCallingIdentity(); |
| 5721 | try { |
| 5722 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5723 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5724 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5725 | if (phone != null) { |
| 5726 | boolean retVal = phone.isUserDataEnabled(); |
| 5727 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5728 | return retVal; |
| 5729 | } else { |
| 5730 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5731 | return false; |
| 5732 | } |
| 5733 | } finally { |
| 5734 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5735 | } |
| 5736 | } |
| 5737 | |
| 5738 | /** |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5739 | * Checks if the device is capable of mobile data by considering whether whether the |
| 5740 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 5741 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 5742 | * |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5743 | * @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] | 5744 | */ |
| 5745 | @Override |
| 5746 | public boolean isDataEnabled(int subId) { |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 5747 | enforceReadPrivilegedPermission("isDataEnabled"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5748 | |
| 5749 | final long identity = Binder.clearCallingIdentity(); |
| 5750 | try { |
| 5751 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 5752 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 5753 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 5754 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 5755 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5756 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 5757 | return retVal; |
| 5758 | } else { |
| 5759 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 5760 | return false; |
| 5761 | } |
| 5762 | } finally { |
| 5763 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 5764 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5765 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5766 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 5767 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5768 | Phone phone) { |
| 5769 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5770 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5771 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5772 | || subController == null) return privilegeFromSim; |
| 5773 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5774 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 5775 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 5776 | |
| 5777 | final long identity = Binder.clearCallingIdentity(); |
| 5778 | try { |
| 5779 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5780 | SubscriptionManager subManager = (SubscriptionManager) |
| 5781 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5782 | for (String pkg : packages) { |
| 5783 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 5784 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5785 | } |
| 5786 | } |
| 5787 | return privilegeFromSim; |
| 5788 | } finally { |
| 5789 | Binder.restoreCallingIdentity(identity); |
| 5790 | } |
| 5791 | } |
| 5792 | |
| 5793 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 5794 | String pkgName) { |
| 5795 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 5796 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 5797 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 5798 | || subController == null) return privilegeFromSim; |
| 5799 | |
| 5800 | final long identity = Binder.clearCallingIdentity(); |
| 5801 | try { |
| 5802 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId()); |
| 5803 | SubscriptionManager subManager = (SubscriptionManager) |
| 5804 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 5805 | return subManager.canManageSubscription(subInfo, pkgName) |
| 5806 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 5807 | } finally { |
| 5808 | Binder.restoreCallingIdentity(identity); |
| 5809 | } |
| 5810 | } |
| 5811 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5812 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5813 | public int getCarrierPrivilegeStatus(int subId) { |
| 5814 | final Phone phone = getPhone(subId); |
| 5815 | if (phone == null) { |
| 5816 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 5817 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5818 | } |
| 5819 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5820 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 5821 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5822 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5823 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5824 | |
| 5825 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5826 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 5827 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 5828 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5829 | |
| 5830 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5831 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5832 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5833 | final Phone phone = getPhone(subId); |
| 5834 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5835 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5836 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 5837 | } |
| 5838 | UiccProfile profile = |
| 5839 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 5840 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5841 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5842 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5843 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5844 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5845 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 5846 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5847 | } |
| 5848 | |
| 5849 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5850 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 5851 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5852 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5853 | } |
| 5854 | |
| 5855 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 5856 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5857 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5858 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 5859 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5860 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5861 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5862 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5863 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5864 | } |
| 5865 | |
| 5866 | @Override |
| 5867 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 5868 | if (TextUtils.isEmpty(pkgName)) |
| 5869 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5870 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 5871 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5872 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 5873 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 5874 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5875 | continue; |
| 5876 | } |
| 5877 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5878 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 5879 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 5880 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 5881 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 5882 | break; |
| 5883 | } |
| 5884 | } |
| 5885 | |
| 5886 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 5887 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 5888 | |
| 5889 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 5890 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 5891 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 5892 | loge("phoneId " + phoneId + " is not valid."); |
| 5893 | return null; |
| 5894 | } |
| 5895 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5896 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 5897 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5898 | return null ; |
| 5899 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5900 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5901 | } |
| 5902 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5903 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5904 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5905 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5906 | List<String> privilegedPackages = new ArrayList<>(); |
| 5907 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5908 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 5909 | // has UICC in that slot. |
| 5910 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5911 | if (card.hasCarrierPrivilegeRules()) { |
| 5912 | if (packages == null) { |
| 5913 | // Only check packages in user 0 for now |
| 5914 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 5915 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 5916 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 5917 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 5918 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5919 | } |
| 5920 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 5921 | PackageInfo pkgInfo = packages.get(p); |
| 5922 | if (pkgInfo != null && pkgInfo.packageName != null |
| 5923 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5924 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 5925 | privilegedPackages.add(pkgInfo.packageName); |
| 5926 | } |
| 5927 | } |
| 5928 | } |
| 5929 | } |
| 5930 | return privilegedPackages; |
| 5931 | } |
| 5932 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5933 | @Override |
| 5934 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5935 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 5936 | |
| 5937 | final long identity = Binder.clearCallingIdentity(); |
| 5938 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5939 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 5940 | try { |
| 5941 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 5942 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 5943 | } |
| 5944 | } finally { |
| 5945 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 5946 | } |
| 5947 | return privilegedPackages; |
| 5948 | } |
| 5949 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 5950 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 5951 | final Phone phone = getPhone(subId); |
| 5952 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5953 | if (card == null) { |
| 5954 | loge("getIccId: No UICC"); |
| 5955 | return null; |
| 5956 | } |
| 5957 | String iccId = card.getIccId(); |
| 5958 | if (TextUtils.isEmpty(iccId)) { |
| 5959 | loge("getIccId: ICC ID is null or empty."); |
| 5960 | return null; |
| 5961 | } |
| 5962 | return iccId; |
| 5963 | } |
| 5964 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 5965 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 5966 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 5967 | String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 5968 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5969 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 5970 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5971 | final long identity = Binder.clearCallingIdentity(); |
| 5972 | try { |
| 5973 | final String iccId = getIccId(subId); |
| 5974 | final Phone phone = getPhone(subId); |
| 5975 | if (phone == null) { |
| 5976 | return false; |
| 5977 | } |
| 5978 | final String subscriberId = phone.getSubscriberId(); |
| 5979 | |
| 5980 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 5981 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5982 | + subscriberId + " to " + number); |
| 5983 | } |
| 5984 | |
| 5985 | if (TextUtils.isEmpty(iccId)) { |
| 5986 | return false; |
| 5987 | } |
| 5988 | |
| 5989 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 5990 | |
| 5991 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 5992 | if (alphaTag == null) { |
| 5993 | editor.remove(alphaTagPrefKey); |
| 5994 | } else { |
| 5995 | editor.putString(alphaTagPrefKey, alphaTag); |
| 5996 | } |
| 5997 | |
| 5998 | // Record both the line number and IMSI for this ICCID, since we need to |
| 5999 | // track all merged IMSIs based on line number |
| 6000 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6001 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6002 | if (number == null) { |
| 6003 | editor.remove(numberPrefKey); |
| 6004 | editor.remove(subscriberPrefKey); |
| 6005 | } else { |
| 6006 | editor.putString(numberPrefKey, number); |
| 6007 | editor.putString(subscriberPrefKey, subscriberId); |
| 6008 | } |
| 6009 | |
| 6010 | editor.commit(); |
| 6011 | return true; |
| 6012 | } finally { |
| 6013 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6014 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6015 | } |
| 6016 | |
| 6017 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6018 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6019 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6020 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6021 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6022 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6023 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6024 | return null; |
| 6025 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6026 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6027 | final long identity = Binder.clearCallingIdentity(); |
| 6028 | try { |
| 6029 | String iccId = getIccId(subId); |
| 6030 | if (iccId != null) { |
| 6031 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6032 | if (DBG_MERGE) { |
| 6033 | log("getLine1NumberForDisplay returning " |
| 6034 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6035 | } |
| 6036 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6037 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6038 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6039 | return null; |
| 6040 | } finally { |
| 6041 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6042 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6043 | } |
| 6044 | |
| 6045 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6046 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6047 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6048 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6049 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6050 | return null; |
| 6051 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6052 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6053 | final long identity = Binder.clearCallingIdentity(); |
| 6054 | try { |
| 6055 | String iccId = getIccId(subId); |
| 6056 | if (iccId != null) { |
| 6057 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6058 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6059 | } |
| 6060 | return null; |
| 6061 | } finally { |
| 6062 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6063 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6064 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6065 | |
| 6066 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6067 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6068 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6069 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6070 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6071 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6072 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6073 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6074 | return null; |
| 6075 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6076 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6077 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6078 | // the process, where TelephonyManager was instantiated. |
| 6079 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6080 | final long identity = Binder.clearCallingIdentity(); |
| 6081 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6082 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6083 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6084 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6085 | |
| 6086 | // Figure out what subscribers are currently active |
| 6087 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6088 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6089 | // Only consider subs which match the current subId |
| 6090 | // This logic can be simplified. See b/131189269 for progress. |
| 6091 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6092 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6093 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6094 | |
| 6095 | // First pass, find a number override for an active subscriber |
| 6096 | String mergeNumber = null; |
| 6097 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6098 | for (String key : prefs.keySet()) { |
| 6099 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6100 | final String subscriberId = (String) prefs.get(key); |
| 6101 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6102 | final String iccId = key.substring( |
| 6103 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6104 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6105 | mergeNumber = (String) prefs.get(numberKey); |
| 6106 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6107 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6108 | + " for active subscriber " + subscriberId); |
| 6109 | } |
| 6110 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6111 | break; |
| 6112 | } |
| 6113 | } |
| 6114 | } |
| 6115 | } |
| 6116 | |
| 6117 | // Shortcut when no active merged subscribers |
| 6118 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6119 | return null; |
| 6120 | } |
| 6121 | |
| 6122 | // Second pass, find all subscribers under that line override |
| 6123 | final ArraySet<String> result = new ArraySet<>(); |
| 6124 | for (String key : prefs.keySet()) { |
| 6125 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6126 | final String number = (String) prefs.get(key); |
| 6127 | if (mergeNumber.equals(number)) { |
| 6128 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6129 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6130 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6131 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6132 | result.add(subscriberId); |
| 6133 | } |
| 6134 | } |
| 6135 | } |
| 6136 | } |
| 6137 | |
| 6138 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6139 | Arrays.sort(resultArray); |
| 6140 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6141 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6142 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6143 | } |
| 6144 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6145 | } finally { |
| 6146 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6147 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6148 | } |
| 6149 | |
| 6150 | @Override |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6151 | public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) { |
| 6152 | enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup"); |
| 6153 | |
| 6154 | final long identity = Binder.clearCallingIdentity(); |
| 6155 | try { |
| 6156 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6157 | TelephonyManager.class); |
| 6158 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6159 | if (subscriberId == null) { |
| 6160 | if (DBG) { |
| 6161 | log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId " |
| 6162 | + subId); |
| 6163 | } |
| 6164 | return null; |
| 6165 | } |
| 6166 | |
| 6167 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6168 | .getSubscriptionInfo(subId); |
| 6169 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6170 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6171 | if (groupUuid == null) { |
| 6172 | return new String[]{subscriberId}; |
| 6173 | } |
| 6174 | |
| 6175 | // Get all subscriberIds from the group. |
| 6176 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6177 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6178 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
| 6179 | null); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6180 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6181 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6182 | if (subscriberId != null) { |
| 6183 | mergedSubscriberIds.add(subscriberId); |
| 6184 | } |
| 6185 | } |
| 6186 | |
| 6187 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6188 | } finally { |
| 6189 | Binder.restoreCallingIdentity(identity); |
| 6190 | |
| 6191 | } |
| 6192 | } |
| 6193 | |
| 6194 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6195 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6196 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6197 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6198 | |
| 6199 | final long identity = Binder.clearCallingIdentity(); |
| 6200 | try { |
| 6201 | final Phone phone = getPhone(subId); |
| 6202 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6203 | } finally { |
| 6204 | Binder.restoreCallingIdentity(identity); |
| 6205 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6206 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6207 | |
| 6208 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6209 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6210 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6211 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6212 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6213 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6214 | |
| 6215 | final long identity = Binder.clearCallingIdentity(); |
| 6216 | try { |
| 6217 | final Phone phone = getPhone(subId); |
| 6218 | if (phone == null) { |
| 6219 | return false; |
| 6220 | } |
| 6221 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6222 | cdmaNonRoamingList); |
| 6223 | } finally { |
| 6224 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6225 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6226 | } |
| 6227 | |
| 6228 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6229 | @Deprecated |
| 6230 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6231 | enforceModifyPermission(); |
| 6232 | |
| 6233 | int returnValue = 0; |
| 6234 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6235 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6236 | if(result.exception == null) { |
| 6237 | if (result.result != null) { |
| 6238 | byte[] responseData = (byte[])(result.result); |
| 6239 | if(responseData.length > oemResp.length) { |
| 6240 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6241 | responseData.length + "bytes. Buffer Size is " + |
| 6242 | oemResp.length + "bytes."); |
| 6243 | } |
| 6244 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6245 | returnValue = responseData.length; |
| 6246 | } |
| 6247 | } else { |
| 6248 | CommandException ex = (CommandException) result.exception; |
| 6249 | returnValue = ex.getCommandError().ordinal(); |
| 6250 | if(returnValue > 0) returnValue *= -1; |
| 6251 | } |
| 6252 | } catch (RuntimeException e) { |
| 6253 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6254 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6255 | if(returnValue > 0) returnValue *= -1; |
| 6256 | } |
| 6257 | |
| 6258 | return returnValue; |
| 6259 | } |
| 6260 | |
| 6261 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6262 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6263 | try { |
| 6264 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6265 | } catch (RuntimeException e) { |
| 6266 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6267 | } |
| 6268 | } |
| 6269 | |
| 6270 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6271 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6272 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6273 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6274 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6275 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6276 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6277 | final long identity = Binder.clearCallingIdentity(); |
| 6278 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6279 | TelephonyPermissions |
| 6280 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6281 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6282 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6283 | } finally { |
| 6284 | Binder.restoreCallingIdentity(identity); |
| 6285 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6286 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6287 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6288 | |
| 6289 | @Override |
| 6290 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6291 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6292 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6293 | |
| 6294 | final long identity = Binder.clearCallingIdentity(); |
| 6295 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6296 | ImsManager.getInstance(defaultPhone.getContext(), |
| 6297 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6298 | } finally { |
| 6299 | Binder.restoreCallingIdentity(identity); |
| 6300 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6301 | } |
| 6302 | |
| 6303 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6304 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6305 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6306 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 6307 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6308 | return false; |
| 6309 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6310 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6311 | final long identity = Binder.clearCallingIdentity(); |
| 6312 | try { |
| 6313 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 6314 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 6315 | // In the long run, we may instead need to check if there exists a connection service |
| 6316 | // which can support video calling. |
| 6317 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6318 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6319 | return imsManager.isVtEnabledByPlatform() |
| 6320 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 6321 | && imsManager.isVtEnabledByUser(); |
| 6322 | } finally { |
| 6323 | Binder.restoreCallingIdentity(identity); |
| 6324 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6325 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 6326 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6327 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6328 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 6329 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6330 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6331 | mApp, subId, callingPackage, callingFeatureId, |
| 6332 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6333 | return false; |
| 6334 | } |
| 6335 | |
| 6336 | final long identity = Binder.clearCallingIdentity(); |
| 6337 | try { |
| 6338 | CarrierConfigManager configManager = |
| 6339 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6340 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6341 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 6342 | } finally { |
| 6343 | Binder.restoreCallingIdentity(identity); |
| 6344 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6345 | } |
| 6346 | |
| 6347 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6348 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6349 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6350 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6351 | return false; |
| 6352 | } |
| 6353 | |
| 6354 | final long identity = Binder.clearCallingIdentity(); |
| 6355 | try { |
| 6356 | CarrierConfigManager configManager = |
| 6357 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6358 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6359 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 6360 | } finally { |
| 6361 | Binder.restoreCallingIdentity(identity); |
| 6362 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6363 | } |
| 6364 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6365 | @Override |
| 6366 | public boolean isTtyModeSupported() { |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6367 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 6368 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6369 | } |
| 6370 | |
| 6371 | @Override |
| 6372 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6373 | final long identity = Binder.clearCallingIdentity(); |
| 6374 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6375 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6376 | } finally { |
| 6377 | Binder.restoreCallingIdentity(identity); |
| 6378 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6379 | } |
| 6380 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6381 | /** |
| 6382 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 6383 | * support for the feature and device firmware support. |
| 6384 | * |
| 6385 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 6386 | */ |
| 6387 | @Override |
| 6388 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6389 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6390 | final Phone phone = getPhone(subscriptionId); |
| 6391 | if (phone == null) { |
| 6392 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 6393 | return false; |
| 6394 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6395 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6396 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6397 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 6398 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6399 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6400 | return isCarrierSupported && isDeviceSupported; |
| 6401 | } finally { |
| 6402 | Binder.restoreCallingIdentity(identity); |
| 6403 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 6404 | } |
| 6405 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6406 | /** |
Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 6407 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 6408 | * RTT setting, will return true if the device and carrier both support RTT. |
| 6409 | * 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] | 6410 | */ |
| 6411 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6412 | final long identity = Binder.clearCallingIdentity(); |
| 6413 | try { |
Hall Liu | 63767ec | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 6414 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 6415 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 6416 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 6417 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 6418 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 6419 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6420 | } finally { |
| 6421 | Binder.restoreCallingIdentity(identity); |
| 6422 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 6423 | } |
| 6424 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6425 | @Deprecated |
| 6426 | @Override |
| 6427 | public String getDeviceId(String callingPackage) { |
| 6428 | return getDeviceIdWithFeature(callingPackage, null); |
| 6429 | } |
| 6430 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6431 | /** |
| 6432 | * Returns the unique device ID of phone, for example, the IMEI for |
| 6433 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 6434 | * |
| 6435 | * <p>Requires Permission: |
| 6436 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 6437 | */ |
| 6438 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6439 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6440 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6441 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6442 | return null; |
| 6443 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6444 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 6445 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6446 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6447 | return null; |
| 6448 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6449 | |
| 6450 | final long identity = Binder.clearCallingIdentity(); |
| 6451 | try { |
| 6452 | return phone.getDeviceId(); |
| 6453 | } finally { |
| 6454 | Binder.restoreCallingIdentity(identity); |
| 6455 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6456 | } |
| 6457 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6458 | /** |
| 6459 | * {@hide} |
| 6460 | * Returns the IMS Registration Status on a particular subid |
| 6461 | * |
| 6462 | * @param subId |
| 6463 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6464 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6465 | Phone phone = getPhone(subId); |
| 6466 | if (phone != null) { |
| 6467 | return phone.isImsRegistered(); |
| 6468 | } else { |
| 6469 | return false; |
| 6470 | } |
| 6471 | } |
| 6472 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6473 | @Override |
| 6474 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6475 | final long identity = Binder.clearCallingIdentity(); |
| 6476 | try { |
| 6477 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 6478 | } finally { |
| 6479 | Binder.restoreCallingIdentity(identity); |
| 6480 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6481 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 6482 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6483 | @Override |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6484 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6485 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6486 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6487 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6488 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6489 | } |
| 6490 | final long identity = Binder.clearCallingIdentity(); |
| 6491 | try { |
| 6492 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 6493 | } finally { |
| 6494 | Binder.restoreCallingIdentity(identity); |
| 6495 | } |
| 6496 | } |
| 6497 | |
| 6498 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6499 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
| 6500 | final long identity = Binder.clearCallingIdentity(); |
| 6501 | try { |
| 6502 | Phone phone = getPhone(subscriptionId); |
| 6503 | if (phone == null) { |
| 6504 | return null; |
| 6505 | } |
| 6506 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 6507 | } finally { |
| 6508 | Binder.restoreCallingIdentity(identity); |
| 6509 | } |
| 6510 | } |
| 6511 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6512 | /** |
| 6513 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6514 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6515 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6516 | final long identity = Binder.clearCallingIdentity(); |
| 6517 | try { |
| 6518 | Phone phone = getPhone(subId); |
| 6519 | if (phone != null) { |
| 6520 | return phone.isWifiCallingEnabled(); |
| 6521 | } else { |
| 6522 | return false; |
| 6523 | } |
| 6524 | } finally { |
| 6525 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6526 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6527 | } |
| 6528 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6529 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6530 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6531 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6532 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6533 | final long identity = Binder.clearCallingIdentity(); |
| 6534 | try { |
| 6535 | Phone phone = getPhone(subId); |
| 6536 | if (phone != null) { |
| 6537 | return phone.isVideoEnabled(); |
| 6538 | } else { |
| 6539 | return false; |
| 6540 | } |
| 6541 | } finally { |
| 6542 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6543 | } |
| 6544 | } |
| 6545 | |
| 6546 | /** |
| 6547 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 6548 | * defined in {@link ImsRegistrationImplBase}. |
| 6549 | */ |
| 6550 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6551 | final long identity = Binder.clearCallingIdentity(); |
| 6552 | try { |
| 6553 | Phone phone = getPhone(subId); |
| 6554 | if (phone != null) { |
| 6555 | return phone.getImsRegistrationTech(); |
| 6556 | } else { |
| 6557 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 6558 | } |
| 6559 | } finally { |
| 6560 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6561 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6562 | } |
| 6563 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6564 | @Override |
| 6565 | public void factoryReset(int subId) { |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 6566 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6567 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 6568 | return; |
| 6569 | } |
| 6570 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6571 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6572 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6573 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 6574 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 6575 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6576 | setUserDataEnabled(subId, getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6577 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 6578 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6579 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 6580 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6581 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6582 | // There has been issues when Sms raw table somehow stores orphan |
| 6583 | // fragments. They lead to garbled message when new fragments come |
| 6584 | // in and combined with those stale ones. In case this happens again, |
| 6585 | // user can reset all network settings which will clean up this table. |
| 6586 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 6587 | // Clean up IMS settings as well here. |
| 6588 | int slotId = getSlotIndex(subId); |
| 6589 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 6590 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 6591 | } |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 6592 | |
| 6593 | // Erase modem config if erase modem on network setting is enabled. |
| 6594 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 6595 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 6596 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 6597 | sendEraseModemConfig(getDefaultPhone()); |
| 6598 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 6599 | } finally { |
| 6600 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 6601 | } |
| 6602 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6603 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 6604 | private void cleanUpSmsRawTable(Context context) { |
| 6605 | ContentResolver resolver = context.getContentResolver(); |
| 6606 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 6607 | resolver.delete(uri, null, null); |
| 6608 | } |
| 6609 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6610 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6611 | public String getSimLocaleForSubscriber(int subId) { |
| 6612 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 6613 | final Phone phone = getPhone(subId); |
| 6614 | if (phone == null) { |
| 6615 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 6616 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6617 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6618 | final long identity = Binder.clearCallingIdentity(); |
| 6619 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6620 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6621 | phone.getContext().getOpPackageName(), null); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 6622 | if (info == null) { |
| 6623 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 6624 | return null; |
| 6625 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6626 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 6627 | // preferences (EF-PL and EF-LI)... |
| 6628 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6629 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6630 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 6631 | if (localeFromDefaultSim != null) { |
| 6632 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 6633 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 6634 | + localeFromDefaultSim); |
| 6635 | return localeFromDefaultSim.toLanguageTag(); |
| 6636 | } else { |
| 6637 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6638 | } |
| 6639 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6640 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6641 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 6642 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 6643 | // the SIM and carrier preferences does not include a country we add the country |
| 6644 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 6645 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6646 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 6647 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6648 | return mccLocale.toLanguageTag(); |
| 6649 | } |
| 6650 | |
| 6651 | if (DBG) log("No locale found - returning null"); |
| 6652 | return null; |
| 6653 | } finally { |
| 6654 | Binder.restoreCallingIdentity(identity); |
| 6655 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6656 | } |
| 6657 | |
| 6658 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6659 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
| 6660 | null); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6661 | } |
| 6662 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6663 | /** |
| 6664 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 6665 | */ |
| 6666 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6667 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
| 6668 | null); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 6669 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6670 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6671 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6672 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6673 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6674 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6675 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 6676 | * representing the state of the modem. |
| 6677 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6678 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 6679 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6680 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6681 | */ |
| 6682 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 6683 | public void requestModemActivityInfo(ResultReceiver result) { |
| 6684 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6685 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6686 | |
| 6687 | final long identity = Binder.clearCallingIdentity(); |
| 6688 | try { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 6689 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6690 | } finally { |
| 6691 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 6692 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 6693 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6694 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6695 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 6696 | // less than total activity duration. |
| 6697 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 6698 | if (info == null) { |
| 6699 | return false; |
| 6700 | } |
| 6701 | int activityDurationMs = |
| 6702 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 6703 | int totalTxTimeMs = 0; |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6704 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 6705 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 6706 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6707 | } |
| 6708 | return (info.isValid() |
| 6709 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 6710 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 6711 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 6712 | && (totalTxTimeMs <= activityDurationMs)); |
| 6713 | } |
| 6714 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6715 | /** |
| 6716 | * {@hide} |
| 6717 | * Returns the service state information on specified subscription. |
| 6718 | */ |
| 6719 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6720 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 6721 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6722 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6723 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6724 | return null; |
| 6725 | } |
| 6726 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6727 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 6728 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6729 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6730 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6731 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6732 | .setCallingPid(Binder.getCallingPid()) |
| 6733 | .setCallingUid(Binder.getCallingUid()) |
| 6734 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6735 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6736 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 6737 | .build()); |
| 6738 | |
| 6739 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 6740 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 6741 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 6742 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6743 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6744 | .setCallingPid(Binder.getCallingPid()) |
| 6745 | .setCallingUid(Binder.getCallingUid()) |
| 6746 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 6747 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6748 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 6749 | .build()); |
| 6750 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 6751 | boolean hasFinePermission = |
| 6752 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6753 | boolean hasCoarsePermission = |
| 6754 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 6755 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6756 | final long identity = Binder.clearCallingIdentity(); |
| 6757 | try { |
| 6758 | final Phone phone = getPhone(subId); |
| 6759 | if (phone == null) { |
| 6760 | return null; |
| 6761 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6762 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 6763 | ServiceState ss = phone.getServiceState(); |
| 6764 | |
| 6765 | // Scrub out the location info in ServiceState depending on what level of access |
| 6766 | // the caller has. |
| 6767 | if (hasFinePermission) return ss; |
Malcolm Chen | db33797 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 6768 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 6769 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6770 | } finally { |
| 6771 | Binder.restoreCallingIdentity(identity); |
| 6772 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 6773 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6774 | |
| 6775 | /** |
| 6776 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 6777 | * |
| 6778 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6779 | * voicemail ringtone. |
| 6780 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 6781 | * PhoneAccount. |
| 6782 | */ |
| 6783 | @Override |
| 6784 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6785 | final long identity = Binder.clearCallingIdentity(); |
| 6786 | try { |
| 6787 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6788 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6789 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6790 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6791 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6792 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 6793 | } finally { |
| 6794 | Binder.restoreCallingIdentity(identity); |
| 6795 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6796 | } |
| 6797 | |
| 6798 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6799 | * Sets the per-account voicemail ringtone. |
| 6800 | * |
| 6801 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6802 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6803 | * |
| 6804 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6805 | * voicemail ringtone. |
| 6806 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 6807 | * PhoneAccount. |
| 6808 | */ |
| 6809 | @Override |
| 6810 | public void setVoicemailRingtoneUri(String callingPackage, |
| 6811 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6812 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6813 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6814 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6815 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6816 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6817 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6818 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6819 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6820 | |
| 6821 | final long identity = Binder.clearCallingIdentity(); |
| 6822 | try { |
| 6823 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6824 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6825 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6826 | } |
| 6827 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 6828 | } finally { |
| 6829 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6830 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6831 | } |
| 6832 | |
| 6833 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6834 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 6835 | * |
| 6836 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 6837 | * voicemail vibration setting. |
| 6838 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 6839 | */ |
| 6840 | @Override |
| 6841 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6842 | final long identity = Binder.clearCallingIdentity(); |
| 6843 | try { |
| 6844 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 6845 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6846 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6847 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6848 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6849 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 6850 | } finally { |
| 6851 | Binder.restoreCallingIdentity(identity); |
| 6852 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 6853 | } |
| 6854 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6855 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6856 | * Sets the per-account voicemail vibration. |
| 6857 | * |
| 6858 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 6859 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 6860 | * |
| 6861 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 6862 | * voicemail vibration setting. |
| 6863 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 6864 | * specific PhoneAccount. |
| 6865 | */ |
| 6866 | @Override |
| 6867 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 6868 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6869 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6870 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6871 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 6872 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6873 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6874 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 6875 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6876 | } |
| 6877 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6878 | final long identity = Binder.clearCallingIdentity(); |
| 6879 | try { |
| 6880 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 6881 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6882 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6883 | } |
| 6884 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 6885 | } finally { |
| 6886 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6887 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 6888 | } |
| 6889 | |
| 6890 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6891 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 6892 | * |
| 6893 | * @throws SecurityException if the caller does not have the required permission |
| 6894 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6895 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6896 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6897 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6898 | } |
| 6899 | |
| 6900 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6901 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 6902 | * permission. |
| 6903 | * |
| 6904 | * @throws SecurityException if the caller does not have the required permission |
| 6905 | */ |
| 6906 | private void enforceSendSmsPermission() { |
| 6907 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 6908 | } |
| 6909 | |
| 6910 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6911 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6912 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6913 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6914 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 6915 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6916 | final long identity = Binder.clearCallingIdentity(); |
| 6917 | try { |
| 6918 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6919 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6920 | if (componentName == null) { |
| 6921 | throw new SecurityException( |
| 6922 | "Caller not current active visual voicemail package[null]"); |
| 6923 | } |
| 6924 | String vvmPackage = componentName.getPackageName(); |
| 6925 | if (!callingPackage.equals(vvmPackage)) { |
| 6926 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 6927 | + vvmPackage + "]"); |
| 6928 | } |
| 6929 | } finally { |
| 6930 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 6931 | } |
| 6932 | } |
| 6933 | |
| 6934 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6935 | * Return the application ID for the app type. |
| 6936 | * |
| 6937 | * @param subId the subscription ID that this request applies to. |
| 6938 | * @param appType the uicc app type. |
| 6939 | * @return Application ID for specificied app type, or null if no uicc. |
| 6940 | */ |
| 6941 | @Override |
| 6942 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6943 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6944 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6945 | |
| 6946 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6947 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6948 | if (phone == null) { |
| 6949 | return null; |
| 6950 | } |
| 6951 | String aid = null; |
| 6952 | try { |
| 6953 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 6954 | .getApplicationByType(appType).getAid(); |
| 6955 | } catch (Exception e) { |
| 6956 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 6957 | } |
| 6958 | return aid; |
| 6959 | } finally { |
| 6960 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6961 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 6962 | } |
| 6963 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6964 | /** |
| 6965 | * Return the Electronic Serial Number. |
| 6966 | * |
| 6967 | * @param subId the subscription ID that this request applies to. |
| 6968 | * @return ESN or null if error. |
| 6969 | */ |
| 6970 | @Override |
| 6971 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 6972 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6973 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6974 | |
| 6975 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6976 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6977 | if (phone == null) { |
| 6978 | return null; |
| 6979 | } |
| 6980 | String esn = null; |
| 6981 | try { |
| 6982 | esn = phone.getEsn(); |
| 6983 | } catch (Exception e) { |
| 6984 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 6985 | } |
| 6986 | return esn; |
| 6987 | } finally { |
| 6988 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6989 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 6990 | } |
| 6991 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 6992 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 6993 | * Return the Preferred Roaming List Version. |
| 6994 | * |
| 6995 | * @param subId the subscription ID that this request applies to. |
| 6996 | * @return PRLVersion or null if error. |
| 6997 | */ |
| 6998 | @Override |
| 6999 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7000 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7001 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7002 | |
| 7003 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7004 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7005 | if (phone == null) { |
| 7006 | return null; |
| 7007 | } |
| 7008 | String cdmaPrlVersion = null; |
| 7009 | try { |
| 7010 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7011 | } catch (Exception e) { |
| 7012 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7013 | } |
| 7014 | return cdmaPrlVersion; |
| 7015 | } finally { |
| 7016 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7017 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7018 | } |
| 7019 | |
| 7020 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7021 | * Get snapshot of Telephony histograms |
| 7022 | * @return List of Telephony histograms |
| 7023 | * @hide |
| 7024 | */ |
| 7025 | @Override |
| 7026 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7027 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7028 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7029 | |
| 7030 | final long identity = Binder.clearCallingIdentity(); |
| 7031 | try { |
| 7032 | return RIL.getTelephonyRILTimingHistograms(); |
| 7033 | } finally { |
| 7034 | Binder.restoreCallingIdentity(identity); |
| 7035 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7036 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7037 | |
| 7038 | /** |
| 7039 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7040 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7041 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7042 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7043 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7044 | * @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] | 7045 | */ |
| 7046 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7047 | @TelephonyManager.SetCarrierRestrictionResult |
| 7048 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7049 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7050 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7051 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7052 | if (carrierRestrictionRules == null) { |
| 7053 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7054 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7055 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7056 | final long identity = Binder.clearCallingIdentity(); |
| 7057 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7058 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7059 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7060 | } finally { |
| 7061 | Binder.restoreCallingIdentity(identity); |
| 7062 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7063 | } |
| 7064 | |
| 7065 | /** |
| 7066 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7067 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7068 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7069 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7070 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7071 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7072 | */ |
| 7073 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7074 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7075 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7076 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7077 | |
| 7078 | final long identity = Binder.clearCallingIdentity(); |
| 7079 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7080 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7081 | if (response instanceof CarrierRestrictionRules) { |
| 7082 | return (CarrierRestrictionRules) response; |
| 7083 | } |
| 7084 | // Response is an Exception of some kind, |
| 7085 | // which is signalled to the user as a NULL retval |
| 7086 | return null; |
| 7087 | } catch (Exception e) { |
| 7088 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7089 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7090 | } finally { |
| 7091 | Binder.restoreCallingIdentity(identity); |
| 7092 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7093 | } |
| 7094 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7095 | /** |
| 7096 | * Action set from carrier signalling broadcast receivers to enable/disable metered apns |
| 7097 | * @param subId the subscription ID that this action applies to. |
| 7098 | * @param enabled control enable or disable metered apns. |
| 7099 | * {@hide} |
| 7100 | */ |
| 7101 | @Override |
| 7102 | public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) { |
| 7103 | enforceModifyPermission(); |
| 7104 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7105 | |
| 7106 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7107 | if (phone == null) { |
| 7108 | loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId); |
| 7109 | return; |
| 7110 | } |
| 7111 | try { |
| 7112 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7113 | } catch (Exception e) { |
| 7114 | Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7115 | } finally { |
| 7116 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7117 | } |
| 7118 | } |
| 7119 | |
| 7120 | /** |
| 7121 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7122 | * @param subId the subscription ID that this action applies to. |
| 7123 | * @param enabled control enable or disable radio. |
| 7124 | * {@hide} |
| 7125 | */ |
| 7126 | @Override |
| 7127 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7128 | enforceModifyPermission(); |
| 7129 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7130 | |
| 7131 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7132 | if (phone == null) { |
| 7133 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7134 | return; |
| 7135 | } |
| 7136 | try { |
| 7137 | phone.carrierActionSetRadioEnabled(enabled); |
| 7138 | } catch (Exception e) { |
| 7139 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7140 | } finally { |
| 7141 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7142 | } |
| 7143 | } |
| 7144 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7145 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7146 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7147 | * network status based on which carrier apps could apply actions accordingly, |
| 7148 | * enable/disable default url handler for example. |
| 7149 | * |
| 7150 | * @param subId the subscription ID that this action applies to. |
| 7151 | * @param report control start/stop reporting the default network status. |
| 7152 | * {@hide} |
| 7153 | */ |
| 7154 | @Override |
| 7155 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7156 | enforceModifyPermission(); |
| 7157 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7158 | |
| 7159 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7160 | if (phone == null) { |
| 7161 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7162 | return; |
| 7163 | } |
| 7164 | try { |
| 7165 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7166 | } catch (Exception e) { |
| 7167 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7168 | } finally { |
| 7169 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7170 | } |
| 7171 | } |
| 7172 | |
| 7173 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7174 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7175 | * @param subId the subscription ID that this action applies to. |
| 7176 | * {@hide} |
| 7177 | */ |
| 7178 | @Override |
| 7179 | public void carrierActionResetAll(int subId) { |
| 7180 | enforceModifyPermission(); |
| 7181 | final Phone phone = getPhone(subId); |
| 7182 | if (phone == null) { |
| 7183 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7184 | return; |
| 7185 | } |
| 7186 | try { |
| 7187 | phone.carrierActionResetAll(); |
| 7188 | } catch (Exception e) { |
| 7189 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7190 | } |
| 7191 | } |
| 7192 | |
| 7193 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7194 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7195 | * bug report is being generated. |
| 7196 | */ |
| 7197 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7198 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7199 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7200 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7201 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7202 | + Binder.getCallingPid() |
| 7203 | + ", uid=" + Binder.getCallingUid() |
| 7204 | + "without permission " |
| 7205 | + android.Manifest.permission.DUMP); |
| 7206 | return; |
| 7207 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7208 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7209 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7210 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7211 | @Override |
| 7212 | public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err, |
| 7213 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) |
| 7214 | throws RemoteException { |
Torbjorn Eklund | 1050cb0 | 2018-11-16 14:05:38 +0100 | [diff] [blame] | 7215 | (new TelephonyShellCommand(this, getDefaultPhone().getContext())) |
| 7216 | .exec(this, in, out, err, args, callback, resultReceiver); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7217 | } |
| 7218 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7219 | /** |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7220 | * Policy control of data connection. Usually used when data limit is passed. |
| 7221 | * @param enabled True if enabling the data, otherwise disabling. |
| 7222 | * @param subId Subscription index |
| 7223 | * {@hide} |
| 7224 | */ |
| 7225 | @Override |
| 7226 | public void setPolicyDataEnabled(boolean enabled, int subId) { |
| 7227 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7228 | |
| 7229 | final long identity = Binder.clearCallingIdentity(); |
| 7230 | try { |
| 7231 | Phone phone = getPhone(subId); |
| 7232 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 7233 | phone.getDataEnabledSettings().setPolicyDataEnabled(enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7234 | } |
| 7235 | } finally { |
| 7236 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7237 | } |
| 7238 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7239 | |
| 7240 | /** |
| 7241 | * Get Client request stats |
| 7242 | * @return List of Client Request Stats |
| 7243 | * @hide |
| 7244 | */ |
| 7245 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7246 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7247 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7248 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7249 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7250 | return null; |
| 7251 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7252 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7253 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7254 | final long identity = Binder.clearCallingIdentity(); |
| 7255 | try { |
| 7256 | if (phone != null) { |
| 7257 | return phone.getClientRequestStats(); |
| 7258 | } |
| 7259 | |
| 7260 | return null; |
| 7261 | } finally { |
| 7262 | Binder.restoreCallingIdentity(identity); |
| 7263 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7264 | } |
| 7265 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7266 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7267 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7268 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7269 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7270 | |
| 7271 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7272 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7273 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7274 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7275 | * @param state State of SIM (power down, power up, pass through) |
| 7276 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7277 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7278 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7279 | * |
| 7280 | **/ |
| 7281 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7282 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7283 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7284 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7285 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7286 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7287 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7288 | final long identity = Binder.clearCallingIdentity(); |
| 7289 | try { |
| 7290 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7291 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7292 | } |
| 7293 | } finally { |
| 7294 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7295 | } |
| 7296 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7297 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7298 | private boolean isUssdApiAllowed(int subId) { |
| 7299 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7300 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7301 | if (configManager == null) { |
| 7302 | return false; |
| 7303 | } |
| 7304 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 7305 | if (pb == null) { |
| 7306 | return false; |
| 7307 | } |
| 7308 | return pb.getBoolean( |
| 7309 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 7310 | } |
| 7311 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7312 | /** |
| 7313 | * Check if phone is in emergency callback mode |
| 7314 | * @return true if phone is in emergency callback mode |
| 7315 | * @param subId sub id |
| 7316 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 7317 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7318 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7319 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7320 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7321 | |
| 7322 | final long identity = Binder.clearCallingIdentity(); |
| 7323 | try { |
| 7324 | if (phone != null) { |
| 7325 | return phone.isInEcm(); |
| 7326 | } else { |
| 7327 | return false; |
| 7328 | } |
| 7329 | } finally { |
| 7330 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7331 | } |
| 7332 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7333 | |
| 7334 | /** |
| 7335 | * Get the current signal strength information for the given subscription. |
| 7336 | * Because this information is not updated when the device is in a low power state |
| 7337 | * it should not be relied-upon to be current. |
| 7338 | * @param subId Subscription index |
| 7339 | * @return the most recent cached signal strength info from the modem |
| 7340 | */ |
| 7341 | @Override |
| 7342 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7343 | final long identity = Binder.clearCallingIdentity(); |
| 7344 | try { |
| 7345 | Phone p = getPhone(subId); |
| 7346 | if (p == null) { |
| 7347 | return null; |
| 7348 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7349 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7350 | return p.getSignalStrength(); |
| 7351 | } finally { |
| 7352 | Binder.restoreCallingIdentity(identity); |
| 7353 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7354 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7355 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7356 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7357 | * Get the current modem radio state for the given slot. |
| 7358 | * @param slotIndex slot index. |
| 7359 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7360 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7361 | * @return the current radio power state from the modem |
| 7362 | */ |
| 7363 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7364 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7365 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7366 | if (phone != null) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7367 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 7368 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7369 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7370 | } |
| 7371 | |
| 7372 | final long identity = Binder.clearCallingIdentity(); |
| 7373 | try { |
| 7374 | return phone.getRadioPowerState(); |
| 7375 | } finally { |
| 7376 | Binder.restoreCallingIdentity(identity); |
| 7377 | } |
| 7378 | } |
| 7379 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7380 | } |
| 7381 | |
| 7382 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7383 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 7384 | * |
| 7385 | * <p>Requires one of the following permissions: |
| 7386 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 7387 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 7388 | * privileges. |
| 7389 | * |
| 7390 | * @param subId subscription id |
| 7391 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 7392 | * {@code false}. |
| 7393 | */ |
| 7394 | @Override |
| 7395 | public boolean isDataRoamingEnabled(int subId) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7396 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7397 | null /* message */); |
| 7398 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7399 | boolean isEnabled = false; |
| 7400 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7401 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7402 | Phone phone = getPhone(subId); |
| 7403 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7404 | } catch (Exception e) { |
| 7405 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 7406 | mApp, subId, "isDataRoamingEnabled"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7407 | } finally { |
| 7408 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7409 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7410 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7411 | } |
| 7412 | |
| 7413 | |
| 7414 | /** |
| 7415 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 7416 | * |
| 7417 | * <p> Requires permission: |
| 7418 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 7419 | * privileges. |
| 7420 | * |
| 7421 | * @param subId subscription id |
| 7422 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 7423 | */ |
| 7424 | @Override |
| 7425 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7426 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7427 | mApp, subId, "setDataRoamingEnabled"); |
| 7428 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7429 | final long identity = Binder.clearCallingIdentity(); |
| 7430 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7431 | Phone phone = getPhone(subId); |
| 7432 | if (phone != null) { |
| 7433 | phone.setDataRoamingEnabled(isEnabled); |
| 7434 | } |
| 7435 | } finally { |
| 7436 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7437 | } |
| 7438 | } |
| 7439 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7440 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7441 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 7442 | TelephonyPermissions |
| 7443 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7444 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 7445 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7446 | boolean isAllowed = true; |
| 7447 | final long identity = Binder.clearCallingIdentity(); |
| 7448 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7449 | Phone phone = getPhone(subId); |
| 7450 | if (phone != null) { |
| 7451 | isAllowed = phone.isCspPlmnEnabled(); |
| 7452 | } |
| 7453 | } finally { |
| 7454 | Binder.restoreCallingIdentity(identity); |
| 7455 | } |
| 7456 | return isAllowed; |
| 7457 | } |
| 7458 | |
| 7459 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7460 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | cfdfe3a | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 7461 | // Verify that tha callingPackage belongs to the calling UID |
| 7462 | mApp.getSystemService(AppOpsManager.class) |
| 7463 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 7464 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7465 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7466 | try { |
| 7467 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7468 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7469 | } catch (SecurityException e) { |
| 7470 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 7471 | // has carrier privileges on an active UICC |
| 7472 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 7473 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7474 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7475 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7476 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7477 | |
| 7478 | final long identity = Binder.clearCallingIdentity(); |
| 7479 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7480 | UiccController uiccController = UiccController.getInstance(); |
| 7481 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7482 | if (hasReadPermission) { |
| 7483 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7484 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7485 | |
| 7486 | // Remove private info if the caller doesn't have access |
| 7487 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 7488 | for (UiccCardInfo cardInfo : cardInfos) { |
| 7489 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 7490 | // is available |
| 7491 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 7492 | if (card == null || card.getUiccProfile() == null) { |
| 7493 | // assume no access if the card or profile is unavailable |
| 7494 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7495 | continue; |
| 7496 | } |
| 7497 | UiccProfile profile = card.getUiccProfile(); |
| 7498 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 7499 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7500 | filteredInfos.add(cardInfo); |
| 7501 | } else { |
| 7502 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7503 | } |
| 7504 | } |
| 7505 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7506 | } finally { |
| 7507 | Binder.restoreCallingIdentity(identity); |
| 7508 | } |
| 7509 | } |
| 7510 | |
| 7511 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7512 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7513 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7514 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7515 | final long identity = Binder.clearCallingIdentity(); |
| 7516 | try { |
| 7517 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 7518 | if (slots == null) { |
| 7519 | Rlog.i(LOG_TAG, "slots is null."); |
| 7520 | return null; |
| 7521 | } |
| 7522 | |
| 7523 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 7524 | for (int i = 0; i < slots.length; i++) { |
| 7525 | UiccSlot slot = slots[i]; |
| 7526 | if (slot == null) { |
| 7527 | continue; |
| 7528 | } |
| 7529 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7530 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7531 | UiccCard card = slot.getUiccCard(); |
| 7532 | if (card != null) { |
| 7533 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7534 | } else { |
Jordan Liu | d96b529 | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 7535 | cardId = slot.getEid(); |
| 7536 | if (TextUtils.isEmpty(cardId)) { |
| 7537 | cardId = slot.getIccId(); |
| 7538 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7539 | } |
| 7540 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 7541 | if (cardId != null) { |
| 7542 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 7543 | // if cardId is an EID, it's all digits so this is fine |
| 7544 | cardId = IccUtils.stripTrailingFs(cardId); |
| 7545 | } |
| 7546 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7547 | int cardState = 0; |
| 7548 | switch (slot.getCardState()) { |
| 7549 | case CARDSTATE_ABSENT: |
| 7550 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 7551 | break; |
| 7552 | case CARDSTATE_PRESENT: |
| 7553 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 7554 | break; |
| 7555 | case CARDSTATE_ERROR: |
| 7556 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 7557 | break; |
| 7558 | case CARDSTATE_RESTRICTED: |
| 7559 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 7560 | break; |
| 7561 | default: |
| 7562 | break; |
| 7563 | |
| 7564 | } |
| 7565 | |
| 7566 | infos[i] = new UiccSlotInfo( |
| 7567 | slot.isActive(), |
| 7568 | slot.isEuicc(), |
| 7569 | cardId, |
| 7570 | cardState, |
| 7571 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 7572 | slot.isExtendedApduSupported(), |
| 7573 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7574 | } |
| 7575 | return infos; |
| 7576 | } finally { |
| 7577 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 7578 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7579 | } |
| 7580 | |
| 7581 | @Override |
| 7582 | public boolean switchSlots(int[] physicalSlots) { |
| 7583 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7584 | |
| 7585 | final long identity = Binder.clearCallingIdentity(); |
| 7586 | try { |
| 7587 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 7588 | } finally { |
| 7589 | Binder.restoreCallingIdentity(identity); |
| 7590 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7591 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 7592 | |
| 7593 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7594 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 7595 | final long identity = Binder.clearCallingIdentity(); |
| 7596 | try { |
| 7597 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 7598 | } finally { |
| 7599 | Binder.restoreCallingIdentity(identity); |
| 7600 | } |
| 7601 | } |
| 7602 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7603 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 7604 | * A test API to reload the UICC profile. |
| 7605 | * |
| 7606 | * <p>Requires that the calling app has permission |
| 7607 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7608 | * @hide |
| 7609 | */ |
| 7610 | @Override |
| 7611 | public void refreshUiccProfile(int subId) { |
| 7612 | enforceModifyPermission(); |
| 7613 | |
| 7614 | final long identity = Binder.clearCallingIdentity(); |
| 7615 | try { |
| 7616 | Phone phone = getPhone(subId); |
| 7617 | if (phone == null) { |
| 7618 | return; |
| 7619 | } |
| 7620 | UiccCard uiccCard = phone.getUiccCard(); |
| 7621 | if (uiccCard == null) { |
| 7622 | return; |
| 7623 | } |
| 7624 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 7625 | if (uiccProfile == null) { |
| 7626 | return; |
| 7627 | } |
| 7628 | uiccProfile.refresh(); |
| 7629 | } finally { |
| 7630 | Binder.restoreCallingIdentity(identity); |
| 7631 | } |
| 7632 | } |
| 7633 | |
| 7634 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7635 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 7636 | */ |
| 7637 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7638 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7639 | } |
| 7640 | |
| 7641 | /** |
| 7642 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 7643 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 7644 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 7645 | */ |
| 7646 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 7647 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7648 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7649 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7650 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 7651 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 7652 | return isDataRoamingEnabled; |
| 7653 | } |
| 7654 | |
| 7655 | /** |
| 7656 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 7657 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 7658 | */ |
| 7659 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 7660 | List<Integer> list = TelephonyProperties.default_network(); |
| 7661 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 7662 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 7663 | return list.get(phoneId); |
| 7664 | } |
| 7665 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7666 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7667 | |
| 7668 | @Override |
| 7669 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7670 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7671 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7672 | |
| 7673 | final long identity = Binder.clearCallingIdentity(); |
| 7674 | try { |
| 7675 | final Phone phone = getPhone(subId); |
| 7676 | if (phone == null) { |
| 7677 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 7678 | return; |
| 7679 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 7680 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 7681 | carrierPrivilegeRules, apn); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7682 | } finally { |
| 7683 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7684 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7685 | } |
| 7686 | |
| 7687 | @Override |
| 7688 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7689 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7690 | |
| 7691 | final long identity = Binder.clearCallingIdentity(); |
| 7692 | try { |
| 7693 | final Phone phone = getPhone(subId); |
| 7694 | if (phone == null) { |
| 7695 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 7696 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 7697 | } |
| 7698 | return phone.getCarrierIdListVersion(); |
| 7699 | } finally { |
| 7700 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7701 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 7702 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7703 | |
| 7704 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7705 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 7706 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7707 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7708 | mApp, subId, callingPackage, callingFeatureId, |
| 7709 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 7710 | return -1; |
| 7711 | } |
| 7712 | |
| 7713 | final long identity = Binder.clearCallingIdentity(); |
| 7714 | try { |
| 7715 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 7716 | } finally { |
| 7717 | Binder.restoreCallingIdentity(identity); |
| 7718 | } |
| 7719 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7720 | |
| 7721 | @Override |
| 7722 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 0723870 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 7723 | TelephonyPermissions |
| 7724 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7725 | mApp, subId, "getCdmaRoamingMode"); |
| 7726 | |
| 7727 | final long identity = Binder.clearCallingIdentity(); |
| 7728 | try { |
| 7729 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 7730 | } finally { |
| 7731 | Binder.restoreCallingIdentity(identity); |
| 7732 | } |
| 7733 | } |
| 7734 | |
| 7735 | @Override |
| 7736 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 7737 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7738 | mApp, subId, "setCdmaRoamingMode"); |
| 7739 | |
| 7740 | final long identity = Binder.clearCallingIdentity(); |
| 7741 | try { |
| 7742 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 7743 | } finally { |
| 7744 | Binder.restoreCallingIdentity(identity); |
| 7745 | } |
| 7746 | } |
| 7747 | |
| 7748 | @Override |
| 7749 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 7750 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7751 | mApp, subId, "setCdmaSubscriptionMode"); |
| 7752 | |
| 7753 | final long identity = Binder.clearCallingIdentity(); |
| 7754 | try { |
| 7755 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 7756 | } finally { |
| 7757 | Binder.restoreCallingIdentity(identity); |
| 7758 | } |
| 7759 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 7760 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7761 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7762 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7763 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7764 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7765 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 7766 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7767 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7768 | } |
| 7769 | final long identity = Binder.clearCallingIdentity(); |
| 7770 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7771 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 7772 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7773 | if (phone.getEmergencyNumberTracker() != null |
| 7774 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 7775 | emergencyNumberListInternal.put( |
| 7776 | phone.getSubId(), |
| 7777 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 7778 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7779 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7780 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7781 | } finally { |
| 7782 | Binder.restoreCallingIdentity(identity); |
| 7783 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 7784 | } |
| 7785 | |
| 7786 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7787 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7788 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7789 | if (!exactMatch) { |
| 7790 | TelephonyPermissions |
| 7791 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 7792 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7793 | } |
| 7794 | final long identity = Binder.clearCallingIdentity(); |
| 7795 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 7796 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7797 | if (phone.getEmergencyNumberTracker() != null |
| 7798 | && phone.getEmergencyNumberTracker() != null) { |
| 7799 | if (phone.getEmergencyNumberTracker().isEmergencyNumber( |
| 7800 | number, exactMatch)) { |
| 7801 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7802 | } |
| 7803 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 7804 | } |
| 7805 | return false; |
| 7806 | } finally { |
| 7807 | Binder.restoreCallingIdentity(identity); |
| 7808 | } |
| 7809 | } |
| 7810 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 7811 | /** |
| 7812 | * Update emergency number list for test mode. |
| 7813 | */ |
| 7814 | @Override |
| 7815 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 7816 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7817 | "updateEmergencyNumberListTestMode"); |
| 7818 | |
| 7819 | final long identity = Binder.clearCallingIdentity(); |
| 7820 | try { |
| 7821 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7822 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7823 | if (tracker != null) { |
| 7824 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 7825 | } |
| 7826 | } |
| 7827 | } finally { |
| 7828 | Binder.restoreCallingIdentity(identity); |
| 7829 | } |
| 7830 | } |
| 7831 | |
| 7832 | /** |
| 7833 | * Get the full emergency number list for test mode. |
| 7834 | */ |
| 7835 | @Override |
| 7836 | public List<String> getEmergencyNumberListTestMode() { |
| 7837 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 7838 | "getEmergencyNumberListTestMode"); |
| 7839 | |
| 7840 | final long identity = Binder.clearCallingIdentity(); |
| 7841 | try { |
| 7842 | Set<String> emergencyNumbers = new HashSet<>(); |
| 7843 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7844 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7845 | if (tracker != null) { |
| 7846 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 7847 | emergencyNumbers.add(num.getNumber()); |
| 7848 | } |
| 7849 | } |
| 7850 | } |
| 7851 | return new ArrayList<>(emergencyNumbers); |
| 7852 | } finally { |
| 7853 | Binder.restoreCallingIdentity(identity); |
| 7854 | } |
| 7855 | } |
| 7856 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7857 | @Override |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7858 | public int getEmergencyNumberDbVersion(int subId) { |
| 7859 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 7860 | |
| 7861 | final long identity = Binder.clearCallingIdentity(); |
| 7862 | try { |
| 7863 | final Phone phone = getPhone(subId); |
| 7864 | if (phone == null) { |
| 7865 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 7866 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 7867 | } |
| 7868 | return phone.getEmergencyNumberDbVersion(); |
| 7869 | } finally { |
| 7870 | Binder.restoreCallingIdentity(identity); |
| 7871 | } |
| 7872 | } |
| 7873 | |
| 7874 | @Override |
| 7875 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 7876 | enforceModifyPermission(); |
| 7877 | |
| 7878 | final long identity = Binder.clearCallingIdentity(); |
| 7879 | try { |
| 7880 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7881 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7882 | if (tracker != null) { |
| 7883 | tracker.updateOtaEmergencyNumberDatabase(); |
| 7884 | } |
| 7885 | } |
| 7886 | } finally { |
| 7887 | Binder.restoreCallingIdentity(identity); |
| 7888 | } |
| 7889 | } |
| 7890 | |
| 7891 | @Override |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 7892 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7893 | enforceActiveEmergencySessionPermission(); |
| 7894 | |
| 7895 | final long identity = Binder.clearCallingIdentity(); |
| 7896 | try { |
| 7897 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7898 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7899 | if (tracker != null) { |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 7900 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 7901 | } |
| 7902 | } |
| 7903 | } finally { |
| 7904 | Binder.restoreCallingIdentity(identity); |
| 7905 | } |
| 7906 | } |
| 7907 | |
| 7908 | @Override |
| 7909 | public void resetOtaEmergencyNumberDbFilePath() { |
| 7910 | enforceActiveEmergencySessionPermission(); |
| 7911 | |
| 7912 | final long identity = Binder.clearCallingIdentity(); |
| 7913 | try { |
| 7914 | for (Phone phone: PhoneFactory.getPhones()) { |
| 7915 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 7916 | if (tracker != null) { |
| 7917 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 7918 | } |
| 7919 | } |
| 7920 | } finally { |
| 7921 | Binder.restoreCallingIdentity(identity); |
| 7922 | } |
| 7923 | } |
| 7924 | |
| 7925 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 7926 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 7927 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 7928 | Phone phone = getPhone(subId); |
| 7929 | if (phone == null) { |
| 7930 | return null; |
| 7931 | } |
| 7932 | final long identity = Binder.clearCallingIdentity(); |
| 7933 | try { |
| 7934 | UiccProfile profile = UiccController.getInstance() |
| 7935 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 7936 | if (profile != null) { |
| 7937 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 7938 | } |
| 7939 | } finally { |
| 7940 | Binder.restoreCallingIdentity(identity); |
| 7941 | } |
| 7942 | return null; |
| 7943 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 7944 | |
| 7945 | /** |
| 7946 | * Enable or disable a modem stack. |
| 7947 | */ |
| 7948 | @Override |
| 7949 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 7950 | enforceModifyPermission(); |
| 7951 | |
| 7952 | final long identity = Binder.clearCallingIdentity(); |
| 7953 | try { |
| 7954 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7955 | if (phone == null) { |
| 7956 | return false; |
| 7957 | } else { |
| 7958 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 7959 | } |
| 7960 | } finally { |
| 7961 | Binder.restoreCallingIdentity(identity); |
| 7962 | } |
| 7963 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7964 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7965 | /** |
| 7966 | * Whether a modem stack is enabled or not. |
| 7967 | */ |
| 7968 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7969 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 7970 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7971 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7972 | if (phone == null) return false; |
| 7973 | |
| 7974 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7975 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 7976 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7977 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7978 | } |
| 7979 | |
| 7980 | final long identity = Binder.clearCallingIdentity(); |
| 7981 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 7982 | try { |
| 7983 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 7984 | } catch (NoSuchElementException ex) { |
| 7985 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 7986 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 7987 | } finally { |
| 7988 | Binder.restoreCallingIdentity(identity); |
| 7989 | } |
| 7990 | } |
| 7991 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7992 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7993 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 7994 | enforceModifyPermission(); |
| 7995 | |
| 7996 | final long identity = Binder.clearCallingIdentity(); |
| 7997 | try { |
| 7998 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 7999 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8000 | .commit(); |
| 8001 | } finally { |
| 8002 | Binder.restoreCallingIdentity(identity); |
| 8003 | } |
| 8004 | } |
| 8005 | |
| 8006 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8007 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8008 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8009 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8010 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8011 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8012 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8013 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8014 | |
| 8015 | final long identity = Binder.clearCallingIdentity(); |
| 8016 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8017 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8018 | } finally { |
| 8019 | Binder.restoreCallingIdentity(identity); |
| 8020 | } |
| 8021 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8022 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8023 | @TelephonyManager.IsMultiSimSupportedResult |
| 8024 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8025 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8026 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8027 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8028 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8029 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8030 | } |
| 8031 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8032 | // supported by the modem, indicate that it is restricted. |
| 8033 | PhoneCapability staticCapability = |
| 8034 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8035 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8036 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8037 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8038 | } |
Sarah Chin | 09f38ee | 2020-02-25 00:13:10 +0000 | [diff] [blame] | 8039 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8040 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8041 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8042 | } |
| 8043 | // Check if support of multiple SIMs is restricted by carrier |
| 8044 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8045 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8046 | } |
| 8047 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8048 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8049 | } |
| 8050 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8051 | /** |
| 8052 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8053 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8054 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8055 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8056 | * @param numOfSims number of active sims we want to switch to |
| 8057 | */ |
| 8058 | @Override |
| 8059 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8060 | if (numOfSims == 1) { |
| 8061 | enforceModifyPermission(); |
| 8062 | } else { |
| 8063 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8064 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8065 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8066 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8067 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8068 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8069 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8070 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8071 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8072 | return; |
| 8073 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8074 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8075 | } finally { |
| 8076 | Binder.restoreCallingIdentity(identity); |
| 8077 | } |
| 8078 | } |
| 8079 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8080 | @Override |
| 8081 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8082 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8083 | Phone phone = getPhone(subId); |
| 8084 | if (phone == null) { |
| 8085 | return false; |
| 8086 | } |
| 8087 | final long identity = Binder.clearCallingIdentity(); |
| 8088 | try { |
| 8089 | UiccCard uiccCard = phone.getUiccCard(); |
| 8090 | if (uiccCard == null) { |
| 8091 | return false; |
| 8092 | } |
| 8093 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8094 | if (uiccProfile == null) { |
| 8095 | return false; |
| 8096 | } |
| 8097 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8098 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8099 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8100 | } |
| 8101 | return false; |
| 8102 | } finally { |
| 8103 | Binder.restoreCallingIdentity(identity); |
| 8104 | } |
| 8105 | } |
| 8106 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8107 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8108 | * Get whether making changes to modem configurations will trigger reboot. |
| 8109 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8110 | */ |
| 8111 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8112 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8113 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8114 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8115 | mApp, subId, callingPackage, callingFeatureId, |
| 8116 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8117 | return false; |
| 8118 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8119 | final long identity = Binder.clearCallingIdentity(); |
| 8120 | try { |
| 8121 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8122 | } finally { |
| 8123 | Binder.restoreCallingIdentity(identity); |
| 8124 | } |
| 8125 | } |
| 8126 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8127 | private void updateModemStateMetrics() { |
| 8128 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8129 | // TODO: check the state for each modem if the api is ready. |
| 8130 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8131 | } |
| 8132 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8133 | @Override |
| 8134 | public int[] getSlotsMapping() { |
| 8135 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8136 | |
| 8137 | final long identity = Binder.clearCallingIdentity(); |
| 8138 | try { |
| 8139 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8140 | // All logical slots should have a mapping to a physical slot. |
| 8141 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8142 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8143 | for (int i = 0; i < slotInfos.length; i++) { |
| 8144 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8145 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8146 | } |
| 8147 | } |
| 8148 | return logicalSlotsMapping; |
| 8149 | } finally { |
| 8150 | Binder.restoreCallingIdentity(identity); |
| 8151 | } |
| 8152 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8153 | |
| 8154 | /** |
| 8155 | * Get the IRadio HAL Version |
| 8156 | */ |
| 8157 | @Override |
| 8158 | public int getRadioHalVersion() { |
| 8159 | Phone phone = getDefaultPhone(); |
| 8160 | if (phone == null) return -1; |
| 8161 | HalVersion hv = phone.getHalVersion(); |
| 8162 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8163 | return hv.major * 100 + hv.minor; |
| 8164 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8165 | |
| 8166 | /** |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8167 | * Get the current calling package name. |
| 8168 | * @return the current calling package name |
| 8169 | */ |
| 8170 | @Override |
| 8171 | public String getCurrentPackageName() { |
| 8172 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8173 | } |
| 8174 | |
| 8175 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8176 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8177 | * corresponding network requests on a subId. |
| 8178 | * |
| 8179 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8180 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8181 | * 2) APN is un-metered for this subscription, or |
| 8182 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
changbetty | 97defcf | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8183 | * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8184 | * |
| 8185 | * @return whether data is allowed for a apn type. |
| 8186 | * |
| 8187 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8188 | */ |
| 8189 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8190 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | f250974 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8191 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8192 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8193 | |
| 8194 | // Now that all security checks passes, perform the operation as ourselves. |
| 8195 | final long identity = Binder.clearCallingIdentity(); |
| 8196 | try { |
| 8197 | Phone phone = getPhone(subId); |
| 8198 | if (phone == null) return false; |
| 8199 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8200 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8201 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8202 | } finally { |
| 8203 | Binder.restoreCallingIdentity(identity); |
| 8204 | } |
| 8205 | } |
| 8206 | |
| 8207 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8208 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8209 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8210 | |
| 8211 | // Now that all security checks passes, perform the operation as ourselves. |
| 8212 | final long identity = Binder.clearCallingIdentity(); |
| 8213 | try { |
| 8214 | Phone phone = getPhone(subId); |
| 8215 | if (phone == null) return true; // By default return true. |
| 8216 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8217 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8218 | } finally { |
| 8219 | Binder.restoreCallingIdentity(identity); |
| 8220 | } |
| 8221 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8222 | |
| 8223 | @Override |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 8224 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 8225 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 8226 | enforceModifyPermission(); |
| 8227 | long token = Binder.clearCallingIdentity(); |
| 8228 | try { |
| 8229 | Phone phone = getPhone(subscriptionId); |
| 8230 | if (phone == null) { |
| 8231 | try { |
| 8232 | if (resultCallback != null) { |
| 8233 | resultCallback.accept(false); |
| 8234 | } |
| 8235 | } catch (RemoteException e) { |
| 8236 | // ignore |
| 8237 | } |
| 8238 | return; |
| 8239 | } |
| 8240 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 8241 | Pair.create(specifiers, (x) -> { |
| 8242 | try { |
| 8243 | if (resultCallback != null) { |
| 8244 | resultCallback.accept(x); |
| 8245 | } |
| 8246 | } catch (RemoteException e) { |
| 8247 | // ignore |
| 8248 | } |
| 8249 | }); |
| 8250 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 8251 | } finally { |
| 8252 | Binder.restoreCallingIdentity(token); |
| 8253 | } |
| 8254 | } |
| 8255 | |
| 8256 | @Override |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8257 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
| 8258 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 8259 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 8260 | if (iccRecords == null) { |
| 8261 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 8262 | return false; |
| 8263 | } |
| 8264 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 8265 | } |
| 8266 | |
| 8267 | @Override |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8268 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 8269 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8270 | if (callingPackage == null) { |
| 8271 | callingPackage = getCurrentPackageName(); |
| 8272 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8273 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 8274 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8275 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 8276 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8277 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 8278 | } |
| 8279 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 8280 | Intent intent = new Intent(); |
| 8281 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 8282 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 8283 | // Bring up choose default SMS subscription dialog right now |
| 8284 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 8285 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 8286 | mApp.startActivity(intent); |
| 8287 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8288 | |
| 8289 | @Override |
| 8290 | public String getMmsUAProfUrl(int subId) { |
| 8291 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8292 | final long identity = Binder.clearCallingIdentity(); |
| 8293 | try { |
| 8294 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8295 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 8296 | } finally { |
| 8297 | Binder.restoreCallingIdentity(identity); |
| 8298 | } |
| 8299 | } |
| 8300 | |
| 8301 | @Override |
| 8302 | public String getMmsUserAgent(int subId) { |
| 8303 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8304 | final long identity = Binder.clearCallingIdentity(); |
| 8305 | try { |
| 8306 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8307 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 8308 | } finally { |
| 8309 | Binder.restoreCallingIdentity(identity); |
| 8310 | } |
| 8311 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8312 | |
| 8313 | @Override |
| 8314 | public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) { |
| 8315 | enforceModifyPermission(); |
| 8316 | |
| 8317 | // Now that all security checks passes, perform the operation as ourselves. |
| 8318 | final long identity = Binder.clearCallingIdentity(); |
| 8319 | try { |
| 8320 | Phone phone = getPhone(subId); |
| 8321 | if (phone == null) return false; |
| 8322 | |
| 8323 | return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow); |
| 8324 | } finally { |
| 8325 | Binder.restoreCallingIdentity(identity); |
| 8326 | } |
| 8327 | } |
| 8328 | |
| 8329 | @Override |
| 8330 | public boolean isDataAllowedInVoiceCall(int subId) { |
| 8331 | enforceReadPrivilegedPermission("isDataAllowedInVoiceCall"); |
| 8332 | |
| 8333 | // Now that all security checks passes, perform the operation as ourselves. |
| 8334 | final long identity = Binder.clearCallingIdentity(); |
| 8335 | try { |
| 8336 | Phone phone = getPhone(subId); |
| 8337 | if (phone == null) return false; |
| 8338 | |
| 8339 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 8340 | } finally { |
| 8341 | Binder.restoreCallingIdentity(identity); |
| 8342 | } |
| 8343 | } |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8344 | |
changbetty | 97defcf | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 8345 | @Override |
| 8346 | public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) { |
| 8347 | enforceModifyPermission(); |
| 8348 | |
| 8349 | // Now that all security checks passes, perform the operation as ourselves. |
| 8350 | final long identity = Binder.clearCallingIdentity(); |
| 8351 | try { |
| 8352 | Phone phone = getPhone(subId); |
| 8353 | if (phone == null) return false; |
| 8354 | |
| 8355 | return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow); |
| 8356 | } finally { |
| 8357 | Binder.restoreCallingIdentity(identity); |
| 8358 | } |
| 8359 | } |
| 8360 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8361 | /** |
| 8362 | * Updates whether conference event pacakge handling is enabled. |
| 8363 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 8364 | * otherwise. |
| 8365 | */ |
| 8366 | @Override |
| 8367 | public void setCepEnabled(boolean isCepEnabled) { |
| 8368 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 8369 | |
| 8370 | final long identity = Binder.clearCallingIdentity(); |
| 8371 | try { |
| 8372 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 8373 | for (Phone phone : PhoneFactory.getPhones()) { |
| 8374 | Phone defaultPhone = phone.getImsPhone(); |
| 8375 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 8376 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 8377 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 8378 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 8379 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 8380 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 8381 | + imsPhone.getMsisdn()); |
| 8382 | } |
| 8383 | } |
| 8384 | } finally { |
| 8385 | Binder.restoreCallingIdentity(identity); |
| 8386 | } |
| 8387 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 8388 | |
| 8389 | /** |
| 8390 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 8391 | * |
| 8392 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 8393 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 8394 | * before being read. |
| 8395 | */ |
| 8396 | @Override |
| 8397 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 8398 | isCompressed) { |
| 8399 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8400 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
| 8401 | try { |
| 8402 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 8403 | if (configBinder == null) { |
| 8404 | Rlog.e(LOG_TAG, "null result for getImsConfig"); |
| 8405 | } else { |
| 8406 | configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed); |
| 8407 | } |
| 8408 | } catch (RemoteException e) { |
| 8409 | Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage()); |
| 8410 | } |
| 8411 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8412 | |
| 8413 | @Override |
| 8414 | public boolean isIccLockEnabled(int subId) { |
| 8415 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 8416 | |
| 8417 | // Now that all security checks passes, perform the operation as ourselves. |
| 8418 | final long identity = Binder.clearCallingIdentity(); |
| 8419 | try { |
| 8420 | Phone phone = getPhone(subId); |
| 8421 | if (phone != null && phone.getIccCard() != null) { |
| 8422 | return phone.getIccCard().getIccLockEnabled(); |
| 8423 | } else { |
| 8424 | return false; |
| 8425 | } |
| 8426 | } finally { |
| 8427 | Binder.restoreCallingIdentity(identity); |
| 8428 | } |
| 8429 | } |
| 8430 | |
| 8431 | /** |
| 8432 | * Set the ICC pin lock enabled or disabled.. |
| 8433 | * |
| 8434 | * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return |
| 8435 | * 0 or a positive integer as the attempts remaining value. |
| 8436 | * |
| 8437 | */ |
| 8438 | @Override |
| 8439 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 8440 | enforceModifyPermission(); |
| 8441 | |
| 8442 | Phone phone = getPhone(subId); |
| 8443 | if (phone == null) { |
| 8444 | return 0; |
| 8445 | } |
| 8446 | // Now that all security checks passes, perform the operation as ourselves. |
| 8447 | final long identity = Binder.clearCallingIdentity(); |
| 8448 | try { |
| 8449 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 8450 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 8451 | return attemptsRemaining; |
| 8452 | |
| 8453 | } catch (Exception e) { |
| 8454 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 8455 | } finally { |
| 8456 | Binder.restoreCallingIdentity(identity); |
| 8457 | } |
| 8458 | return 0; |
| 8459 | } |
| 8460 | |
| 8461 | /** |
| 8462 | * Change the ICC password used in ICC pin lock. |
| 8463 | * |
| 8464 | * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return |
| 8465 | * 0 or a positive integer as the attempts remaining value. |
| 8466 | * |
| 8467 | */ |
| 8468 | @Override |
| 8469 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 8470 | enforceModifyPermission(); |
| 8471 | |
| 8472 | Phone phone = getPhone(subId); |
| 8473 | if (phone == null) { |
| 8474 | return 0; |
| 8475 | } |
| 8476 | // Now that all security checks passes, perform the operation as ourselves. |
| 8477 | final long identity = Binder.clearCallingIdentity(); |
| 8478 | try { |
| 8479 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 8480 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 8481 | return attemptsRemaining; |
| 8482 | |
| 8483 | } catch (Exception e) { |
| 8484 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 8485 | } finally { |
| 8486 | Binder.restoreCallingIdentity(identity); |
| 8487 | } |
| 8488 | return 0; |
| 8489 | } |
Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 8490 | |
| 8491 | @Override |
| 8492 | public boolean canConnectTo5GInDsdsMode() { |
| 8493 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 8494 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 8495 | } |