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; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 54 | import android.os.ServiceSpecificException; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 55 | import android.os.UserHandle; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 56 | import android.os.UserManager; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 57 | import android.os.WorkSource; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 58 | import android.preference.PreferenceManager; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 59 | import android.provider.DeviceConfig; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 60 | import android.provider.Settings; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 61 | import android.provider.Telephony; |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 62 | import android.sysprop.TelephonyProperties; |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 63 | import android.telecom.PhoneAccount; |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 64 | import android.telecom.PhoneAccountHandle; |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 65 | import android.telecom.TelecomManager; |
Chen Xu | c7b18ec | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 66 | import android.telephony.Annotation.ApnType; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 67 | import android.telephony.CallForwardingInfo; |
Sooraj Sasindran | 1f812e0 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 68 | import android.telephony.CarrierBandwidth; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 69 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 70 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 71 | import android.telephony.CellIdentity; |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 72 | import android.telephony.CellIdentityCdma; |
| 73 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 74 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 75 | import android.telephony.CellInfoGsm; |
| 76 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 77 | import android.telephony.ClientRequestStats; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 78 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 79 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 80 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 81 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 82 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 83 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 84 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 85 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 86 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 87 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 88 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 89 | import android.telephony.SignalStrength; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 90 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 91 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 92 | import android.telephony.TelephonyFrameworkInitializer; |
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.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 109 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 110 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 111 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 112 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 113 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 114 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 115 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 116 | import android.util.ArraySet; |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 117 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 118 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 119 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 120 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 121 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 122 | import com.android.ims.internal.IImsServiceFeatureCallback; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 123 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 124 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 125 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 126 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 127 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.CommandException; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 130 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 132 | import com.android.internal.telephony.HalVersion; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 133 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 134 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 136 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 138 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 144 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 153 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 154 | import com.android.internal.telephony.TelephonyIntents; |
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; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 175 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 176 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 177 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 178 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 179 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 180 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 181 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 182 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 183 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 184 | import java.io.FileDescriptor; |
| 185 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 186 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 187 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 188 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 189 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 190 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 191 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 192 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 193 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 194 | import java.util.Set; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 195 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 196 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 197 | |
| 198 | /** |
| 199 | * Implementation of the ITelephony interface. |
| 200 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 201 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 202 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 203 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 204 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 205 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 206 | |
| 207 | // Message codes used with mMainThreadHandler |
| 208 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 209 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 210 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 211 | private static final int CMD_OPEN_CHANNEL = 9; |
| 212 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 213 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 214 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 215 | private static final int CMD_NV_READ_ITEM = 13; |
| 216 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 217 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 218 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 219 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 220 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 221 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 222 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 223 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 224 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 225 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 226 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 227 | private static final int CMD_SEND_ENVELOPE = 25; |
| 228 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 229 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 230 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 231 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 232 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 233 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 234 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 235 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 236 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 237 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 238 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 239 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 240 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 241 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 242 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 243 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 244 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 245 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 246 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 247 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 248 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 249 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 250 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 251 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 252 | private static final int CMD_SWITCH_SLOTS = 50; |
| 253 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 254 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 255 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 256 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 257 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 258 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 259 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 260 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 261 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 262 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 263 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 264 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 265 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 266 | private static final int CMD_MODEM_REBOOT = 64; |
| 267 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 268 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 269 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 270 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 271 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 272 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 273 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 274 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 275 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 276 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 277 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 278 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 279 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 280 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 281 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 282 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 283 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 284 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 285 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 286 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 287 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 288 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 289 | private static final int CMD_GET_CALL_WAITING = 87; |
| 290 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 291 | private static final int CMD_SET_CALL_WAITING = 89; |
| 292 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 293 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 294 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 295 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 296 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 297 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 298 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 299 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 300 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 301 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 302 | // Parameters of select command. |
| 303 | private static final int SELECT_COMMAND = 0xA4; |
| 304 | private static final int SELECT_P1 = 0x04; |
| 305 | private static final int SELECT_P2 = 0; |
| 306 | private static final int SELECT_P3 = 0x10; |
| 307 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 308 | /** The singleton instance. */ |
| 309 | private static PhoneInterfaceManager sInstance; |
| 310 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 311 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 312 | private CallManager mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 313 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 314 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 315 | private AppOpsManager mAppOps; |
| 316 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 317 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 318 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 319 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 320 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 321 | /** User Activity */ |
| 322 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 323 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 324 | |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 325 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 326 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 327 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 328 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 329 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 330 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 331 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 332 | // String to store multi SIM allowed |
| 333 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 334 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 335 | // The AID of ISD-R. |
| 336 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 337 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 338 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 339 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 340 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 341 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 342 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 343 | /** |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 344 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 345 | */ |
| 346 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 347 | "reset_network_erase_modem_config_enabled"; |
| 348 | |
| 349 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 350 | * A request object to use for transmitting data to an ICC. |
| 351 | */ |
| 352 | private static final class IccAPDUArgument { |
| 353 | public int channel, cla, command, p1, p2, p3; |
| 354 | public String data; |
| 355 | |
| 356 | public IccAPDUArgument(int channel, int cla, int command, |
| 357 | int p1, int p2, int p3, String data) { |
| 358 | this.channel = channel; |
| 359 | this.cla = cla; |
| 360 | this.command = command; |
| 361 | this.p1 = p1; |
| 362 | this.p2 = p2; |
| 363 | this.p3 = p3; |
| 364 | this.data = data; |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 369 | * A request object to use for transmitting data to an ICC. |
| 370 | */ |
| 371 | private static final class ManualNetworkSelectionArgument { |
| 372 | public OperatorInfo operatorInfo; |
| 373 | public boolean persistSelection; |
| 374 | |
| 375 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 376 | this.operatorInfo = operatorInfo; |
| 377 | this.persistSelection = persistSelection; |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 382 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 383 | * request after sending. The main thread will notify the request when it is complete. |
| 384 | */ |
| 385 | private static final class MainThreadRequest { |
| 386 | /** The argument to use for the request */ |
| 387 | public Object argument; |
| 388 | /** The result of the request that is run on the main thread */ |
| 389 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 390 | // The subscriber id that this request applies to. Defaults to |
| 391 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 392 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 393 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 394 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 395 | public Phone phone; |
| 396 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 397 | public WorkSource workSource; |
| 398 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 399 | public MainThreadRequest(Object argument) { |
| 400 | this.argument = argument; |
| 401 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 402 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 403 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 404 | this.argument = argument; |
| 405 | if (phone != null) { |
| 406 | this.phone = phone; |
| 407 | } |
| 408 | this.workSource = workSource; |
| 409 | } |
| 410 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 411 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 412 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 413 | if (subId != null) { |
| 414 | this.subId = subId; |
| 415 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 416 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 417 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 418 | } |
| 419 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 420 | private static final class IncomingThirdPartyCallArgs { |
| 421 | public final ComponentName component; |
| 422 | public final String callId; |
| 423 | public final String callerDisplayName; |
| 424 | |
| 425 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 426 | String callerDisplayName) { |
| 427 | this.component = component; |
| 428 | this.callId = callId; |
| 429 | this.callerDisplayName = callerDisplayName; |
| 430 | } |
| 431 | } |
| 432 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 433 | /** |
| 434 | * A handler that processes messages on the main thread in the phone process. Since many |
| 435 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 436 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 437 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 438 | * on, which will be notified when the operation completes and will contain the result of the |
| 439 | * request. |
| 440 | * |
| 441 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 442 | * note that request.result must be set to something non-null for the calling thread to |
| 443 | * unblock. |
| 444 | */ |
| 445 | private final class MainThreadHandler extends Handler { |
| 446 | @Override |
| 447 | public void handleMessage(Message msg) { |
| 448 | MainThreadRequest request; |
| 449 | Message onCompleted; |
| 450 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 451 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 452 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 453 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 454 | |
| 455 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 456 | case CMD_HANDLE_USSD_REQUEST: { |
| 457 | request = (MainThreadRequest) msg.obj; |
| 458 | final Phone phone = getPhoneFromRequest(request); |
| 459 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 460 | String ussdRequest = ussdObject.first; |
| 461 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 462 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 463 | if (!isUssdApiAllowed(request.subId)) { |
| 464 | // Carrier does not support use of this API, return failure. |
| 465 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 466 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 467 | Bundle returnData = new Bundle(); |
| 468 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 469 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 470 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 471 | request.result = true; |
| 472 | notifyRequester(request); |
| 473 | return; |
| 474 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 475 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 476 | try { |
| 477 | request.result = phone != null |
| 478 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 479 | } catch (CallStateException cse) { |
| 480 | request.result = false; |
| 481 | } |
| 482 | // Wake up the requesting thread |
| 483 | notifyRequester(request); |
| 484 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 485 | } |
| 486 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 487 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 488 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 489 | final Phone phone = getPhoneFromRequest(request); |
| 490 | request.result = phone != null ? |
| 491 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 492 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 493 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 494 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 495 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 496 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 497 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 498 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 499 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 500 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 501 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 502 | if (uiccCard == null) { |
| 503 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 504 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 505 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 506 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 507 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 508 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 509 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 510 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 511 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 512 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 513 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 514 | break; |
| 515 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 516 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 517 | ar = (AsyncResult) msg.obj; |
| 518 | request = (MainThreadRequest) ar.userObj; |
| 519 | if (ar.exception == null && ar.result != null) { |
| 520 | request.result = ar.result; |
| 521 | } else { |
| 522 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 523 | if (ar.result == null) { |
| 524 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 525 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 526 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 527 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 528 | } else { |
| 529 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 530 | } |
| 531 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 532 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 533 | break; |
| 534 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 535 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 536 | request = (MainThreadRequest) msg.obj; |
| 537 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 538 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 539 | if (uiccCard == null) { |
| 540 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 541 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 542 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 543 | } else { |
| 544 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 545 | request); |
| 546 | uiccCard.iccTransmitApduBasicChannel( |
| 547 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 548 | iccArgument.p3, iccArgument.data, onCompleted); |
| 549 | } |
| 550 | break; |
| 551 | |
| 552 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 553 | ar = (AsyncResult) msg.obj; |
| 554 | request = (MainThreadRequest) ar.userObj; |
| 555 | if (ar.exception == null && ar.result != null) { |
| 556 | request.result = ar.result; |
| 557 | } else { |
| 558 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 559 | if (ar.result == null) { |
| 560 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 561 | } else if (ar.exception instanceof CommandException) { |
| 562 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 563 | ar.exception); |
| 564 | } else { |
| 565 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 566 | } |
| 567 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 568 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 569 | break; |
| 570 | |
| 571 | case CMD_EXCHANGE_SIM_IO: |
| 572 | request = (MainThreadRequest) msg.obj; |
| 573 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 574 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 575 | if (uiccCard == null) { |
| 576 | loge("iccExchangeSimIO: No UICC"); |
| 577 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 578 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 579 | } else { |
| 580 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 581 | request); |
| 582 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 583 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 584 | iccArgument.data, onCompleted); |
| 585 | } |
| 586 | break; |
| 587 | |
| 588 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 589 | ar = (AsyncResult) msg.obj; |
| 590 | request = (MainThreadRequest) ar.userObj; |
| 591 | if (ar.exception == null && ar.result != null) { |
| 592 | request.result = ar.result; |
| 593 | } else { |
| 594 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 595 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 596 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 597 | break; |
| 598 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 599 | case CMD_SEND_ENVELOPE: |
| 600 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 601 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 602 | if (uiccCard == null) { |
| 603 | loge("sendEnvelopeWithStatus: No UICC"); |
| 604 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 605 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 606 | } else { |
| 607 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 608 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 609 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 610 | break; |
| 611 | |
| 612 | case EVENT_SEND_ENVELOPE_DONE: |
| 613 | ar = (AsyncResult) msg.obj; |
| 614 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 615 | if (ar.exception == null && ar.result != null) { |
| 616 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 617 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 618 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 619 | if (ar.result == null) { |
| 620 | loge("sendEnvelopeWithStatus: Empty response"); |
| 621 | } else if (ar.exception instanceof CommandException) { |
| 622 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 623 | ar.exception); |
| 624 | } else { |
| 625 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 626 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 627 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 628 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 629 | break; |
| 630 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 631 | case CMD_OPEN_CHANNEL: |
| 632 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 633 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 634 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 635 | if (uiccCard == null) { |
| 636 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 637 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 638 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 639 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 640 | } else { |
| 641 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 642 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 643 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 644 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 645 | break; |
| 646 | |
| 647 | case EVENT_OPEN_CHANNEL_DONE: |
| 648 | ar = (AsyncResult) msg.obj; |
| 649 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 650 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 651 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 652 | int[] result = (int[]) ar.result; |
| 653 | int channelId = result[0]; |
| 654 | byte[] selectResponse = null; |
| 655 | if (result.length > 1) { |
| 656 | selectResponse = new byte[result.length - 1]; |
| 657 | for (int i = 1; i < result.length; ++i) { |
| 658 | selectResponse[i - 1] = (byte) result[i]; |
| 659 | } |
| 660 | } |
| 661 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 662 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 663 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 664 | if (ar.result == null) { |
| 665 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 666 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 667 | if (ar.exception != null) { |
| 668 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 669 | } |
| 670 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 671 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 672 | if (ar.exception instanceof CommandException) { |
| 673 | CommandException.Error error = |
| 674 | ((CommandException) (ar.exception)).getCommandError(); |
| 675 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 676 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 677 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 678 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 679 | } |
| 680 | } |
| 681 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 682 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 683 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 684 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 685 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 686 | break; |
| 687 | |
| 688 | case CMD_CLOSE_CHANNEL: |
| 689 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 690 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 691 | if (uiccCard == null) { |
| 692 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 693 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 694 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 695 | } else { |
| 696 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 697 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 698 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 699 | break; |
| 700 | |
| 701 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 702 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 703 | break; |
| 704 | |
| 705 | case CMD_NV_READ_ITEM: |
| 706 | request = (MainThreadRequest) msg.obj; |
| 707 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 708 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 709 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 710 | break; |
| 711 | |
| 712 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 713 | ar = (AsyncResult) msg.obj; |
| 714 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 715 | if (ar.exception == null && ar.result != null) { |
| 716 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 717 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 718 | request.result = ""; |
| 719 | if (ar.result == null) { |
| 720 | loge("nvReadItem: Empty response"); |
| 721 | } else if (ar.exception instanceof CommandException) { |
| 722 | loge("nvReadItem: CommandException: " + |
| 723 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 724 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 725 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 726 | } |
| 727 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 728 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 729 | break; |
| 730 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 731 | case CMD_NV_WRITE_ITEM: |
| 732 | request = (MainThreadRequest) msg.obj; |
| 733 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 734 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 735 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 736 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 737 | break; |
| 738 | |
| 739 | case EVENT_NV_WRITE_ITEM_DONE: |
| 740 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 741 | break; |
| 742 | |
| 743 | case CMD_NV_WRITE_CDMA_PRL: |
| 744 | request = (MainThreadRequest) msg.obj; |
| 745 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 746 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 747 | break; |
| 748 | |
| 749 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 750 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 751 | break; |
| 752 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 753 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 754 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 755 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 756 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 757 | break; |
| 758 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 759 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 760 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 761 | break; |
| 762 | |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 763 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 764 | request = (MainThreadRequest) msg.obj; |
| 765 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 766 | request); |
| 767 | Phone phone = getPhoneFromRequest(request); |
| 768 | if (phone != null) { |
| 769 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 770 | } else { |
| 771 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 772 | request.result = false; |
| 773 | notifyRequester(request); |
| 774 | } |
| 775 | break; |
| 776 | } |
| 777 | |
| 778 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 779 | ar = (AsyncResult) msg.obj; |
| 780 | request = (MainThreadRequest) ar.userObj; |
| 781 | if (ar.exception == null && ar.result != null) { |
| 782 | request.result = ar.result; |
| 783 | } else { |
| 784 | // request.result must be set to something non-null |
| 785 | // for the calling thread to unblock |
| 786 | if (request.result != null) { |
| 787 | request.result = ar.result; |
| 788 | } else { |
| 789 | request.result = false; |
| 790 | } |
| 791 | if (ar.result == null) { |
| 792 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 793 | } else if (ar.exception instanceof CommandException) { |
| 794 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 795 | + ar.exception); |
| 796 | } else { |
| 797 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 798 | } |
| 799 | } |
| 800 | notifyRequester(request); |
| 801 | break; |
| 802 | |
| 803 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 804 | request = (MainThreadRequest) msg.obj; |
| 805 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 806 | Phone phone = getPhoneFromRequest(request); |
| 807 | if (phone != null) { |
| 808 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 809 | request.workSource); |
| 810 | } else { |
| 811 | loge("enableNrDualConnectivity: No phone object"); |
| 812 | request.result = |
| 813 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 814 | notifyRequester(request); |
| 815 | } |
| 816 | break; |
| 817 | } |
| 818 | |
| 819 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 820 | ar = (AsyncResult) msg.obj; |
| 821 | request = (MainThreadRequest) ar.userObj; |
| 822 | if (ar.exception == null) { |
| 823 | request.result = |
| 824 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 825 | } else { |
| 826 | request.result = |
| 827 | TelephonyManager |
| 828 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 829 | if (ar.exception instanceof CommandException) { |
| 830 | CommandException.Error error = |
| 831 | ((CommandException) (ar.exception)).getCommandError(); |
| 832 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 833 | request.result = |
| 834 | TelephonyManager |
| 835 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 836 | } |
| 837 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 838 | + ar.exception); |
| 839 | } else { |
| 840 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 841 | } |
| 842 | } |
| 843 | notifyRequester(request); |
| 844 | break; |
| 845 | } |
| 846 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 847 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 848 | request = (MainThreadRequest) msg.obj; |
| 849 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 850 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 851 | break; |
| 852 | |
| 853 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 854 | ar = (AsyncResult) msg.obj; |
| 855 | request = (MainThreadRequest) ar.userObj; |
| 856 | if (ar.exception == null && ar.result != null) { |
| 857 | request.result = ar.result; // Integer |
| 858 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 859 | // request.result must be set to something non-null |
| 860 | // for the calling thread to unblock |
| 861 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 862 | if (ar.result == null) { |
| 863 | loge("getPreferredNetworkType: Empty response"); |
| 864 | } else if (ar.exception instanceof CommandException) { |
| 865 | loge("getPreferredNetworkType: CommandException: " + |
| 866 | ar.exception); |
| 867 | } else { |
| 868 | loge("getPreferredNetworkType: Unknown exception"); |
| 869 | } |
| 870 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 871 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 872 | break; |
| 873 | |
| 874 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 875 | request = (MainThreadRequest) msg.obj; |
| 876 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 877 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 878 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 879 | break; |
| 880 | |
| 881 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 882 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 883 | break; |
| 884 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 885 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 886 | request = (MainThreadRequest)msg.obj; |
| 887 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 888 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 889 | break; |
| 890 | |
| 891 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 892 | ar = (AsyncResult)msg.obj; |
| 893 | request = (MainThreadRequest)ar.userObj; |
| 894 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 895 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 896 | break; |
| 897 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 898 | case CMD_SET_VOICEMAIL_NUMBER: |
| 899 | request = (MainThreadRequest) msg.obj; |
| 900 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 901 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 902 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 903 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 904 | break; |
| 905 | |
| 906 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 907 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 908 | break; |
| 909 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 910 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 911 | request = (MainThreadRequest) msg.obj; |
| 912 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 913 | request); |
| 914 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 915 | break; |
| 916 | |
| 917 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 918 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 919 | break; |
| 920 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 921 | case CMD_PERFORM_NETWORK_SCAN: |
| 922 | request = (MainThreadRequest) msg.obj; |
| 923 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 924 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 925 | break; |
| 926 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 927 | case CMD_GET_CALL_FORWARDING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 928 | request = (MainThreadRequest) msg.obj; |
| 929 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 930 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 931 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 932 | request.argument; |
| 933 | int callForwardingReason = args.first; |
| 934 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 935 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 936 | } |
| 937 | case EVENT_GET_CALL_FORWARDING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 938 | ar = (AsyncResult) msg.obj; |
| 939 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 940 | TelephonyManager.CallForwardingInfoCallback callback = |
| 941 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 942 | request.argument).second; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 943 | if (ar.exception == null && ar.result != null) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 944 | CallForwardingInfo callForwardingInfo = null; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 945 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 946 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 947 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 948 | // any service for voice call. |
| 949 | if ((callForwardInfo.serviceClass |
| 950 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 951 | callForwardingInfo = new CallForwardingInfo(true, |
| 952 | callForwardInfo.reason, |
| 953 | callForwardInfo.number, |
| 954 | callForwardInfo.timeSeconds); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 955 | break; |
| 956 | } |
| 957 | } |
| 958 | // Didn't find a call forward info for voice call. |
| 959 | if (callForwardingInfo == null) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 960 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 961 | 0 /* reason */, null /* number */, 0 /* timeout */); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 962 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 963 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 964 | } else { |
| 965 | if (ar.result == null) { |
| 966 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 967 | } |
| 968 | if (ar.exception != null) { |
| 969 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 970 | } |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 971 | int errorCode = TelephonyManager |
| 972 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 973 | if (ar.exception instanceof CommandException) { |
| 974 | CommandException.Error error = |
| 975 | ((CommandException) (ar.exception)).getCommandError(); |
| 976 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 977 | errorCode = TelephonyManager |
| 978 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 979 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 980 | errorCode = TelephonyManager |
| 981 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 982 | } |
| 983 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 984 | callback.onError(errorCode); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 985 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 986 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 987 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 988 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 989 | case CMD_SET_CALL_FORWARDING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 990 | request = (MainThreadRequest) msg.obj; |
| 991 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 992 | request = (MainThreadRequest) msg.obj; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 993 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 994 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 995 | request.argument).first; |
| 996 | request.phone.setCallForwardingOption( |
| 997 | callForwardingInfoToSet.isEnabled() |
| 998 | ? CommandsInterface.CF_ACTION_ENABLE |
| 999 | : CommandsInterface.CF_ACTION_DISABLE, |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1000 | callForwardingInfoToSet.getReason(), |
| 1001 | callForwardingInfoToSet.getNumber(), |
| 1002 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1003 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1004 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1005 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1006 | case EVENT_SET_CALL_FORWARDING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1007 | ar = (AsyncResult) msg.obj; |
| 1008 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1009 | Consumer<Integer> callback = |
| 1010 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1011 | request.argument).second; |
| 1012 | if (ar.exception != null) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1013 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1014 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1015 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1016 | if (ar.exception instanceof CommandException) { |
| 1017 | CommandException.Error error = |
| 1018 | ((CommandException) (ar.exception)).getCommandError(); |
| 1019 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1020 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1021 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1022 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1023 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1024 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1025 | } |
| 1026 | } |
| 1027 | callback.accept(errorCode); |
| 1028 | } else { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1029 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1030 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1031 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1032 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1033 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1034 | case CMD_GET_CALL_WAITING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1035 | request = (MainThreadRequest) msg.obj; |
| 1036 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1037 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1038 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1039 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1040 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1041 | case EVENT_GET_CALL_WAITING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1042 | ar = (AsyncResult) msg.obj; |
| 1043 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1044 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1045 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1046 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1047 | int[] callForwardResults = (int[]) ar.result; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1048 | // Service Class is a bit mask per 3gpp 27.007. |
| 1049 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1050 | if (callForwardResults.length > 1 |
| 1051 | && ((callForwardResults[1] |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1052 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1053 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1054 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1055 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1056 | } else { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1057 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1058 | } |
| 1059 | } else { |
| 1060 | if (ar.result == null) { |
| 1061 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1062 | } |
| 1063 | if (ar.exception != null) { |
| 1064 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1065 | } |
| 1066 | if (ar.exception instanceof CommandException) { |
| 1067 | CommandException.Error error = |
| 1068 | ((CommandException) (ar.exception)).getCommandError(); |
| 1069 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1070 | callForwardingStatus = |
| 1071 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1072 | } |
| 1073 | } |
| 1074 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1075 | callback.accept(callForwardingStatus); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1076 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1077 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1078 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1079 | case CMD_SET_CALL_WAITING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1080 | request = (MainThreadRequest) msg.obj; |
| 1081 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1082 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1083 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1084 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1085 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1086 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1087 | case EVENT_SET_CALL_WAITING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1088 | ar = (AsyncResult) msg.obj; |
| 1089 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1090 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1091 | Consumer<Integer> callback = |
| 1092 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1093 | if (ar.exception != null) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1094 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1095 | if (ar.exception instanceof CommandException) { |
| 1096 | CommandException.Error error = |
| 1097 | ((CommandException) (ar.exception)).getCommandError(); |
| 1098 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1099 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1100 | } else { |
| 1101 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1102 | } |
| 1103 | } else { |
| 1104 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1105 | } |
| 1106 | } else { |
| 1107 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1108 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1109 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1110 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1111 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1112 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1113 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1114 | ar = (AsyncResult) msg.obj; |
| 1115 | request = (MainThreadRequest) ar.userObj; |
| 1116 | CellNetworkScanResult cellScanResult; |
| 1117 | if (ar.exception == null && ar.result != null) { |
| 1118 | cellScanResult = new CellNetworkScanResult( |
| 1119 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1120 | (List<OperatorInfo>) ar.result); |
| 1121 | } else { |
| 1122 | if (ar.result == null) { |
| 1123 | loge("getCellNetworkScanResults: Empty response"); |
| 1124 | } |
| 1125 | if (ar.exception != null) { |
| 1126 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1127 | } |
| 1128 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1129 | if (ar.exception instanceof CommandException) { |
| 1130 | CommandException.Error error = |
| 1131 | ((CommandException) (ar.exception)).getCommandError(); |
| 1132 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1133 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1134 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1135 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1136 | } |
| 1137 | } |
| 1138 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1139 | } |
| 1140 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1141 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1142 | break; |
| 1143 | |
| 1144 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1145 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1146 | ManualNetworkSelectionArgument selArg = |
| 1147 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1148 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1149 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1150 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1151 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1152 | break; |
| 1153 | |
| 1154 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1155 | ar = (AsyncResult) msg.obj; |
| 1156 | request = (MainThreadRequest) ar.userObj; |
| 1157 | if (ar.exception == null) { |
| 1158 | request.result = true; |
| 1159 | } else { |
| 1160 | request.result = false; |
| 1161 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1162 | } |
| 1163 | notifyRequester(request); |
| 1164 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1165 | break; |
| 1166 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1167 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1168 | request = (MainThreadRequest) msg.obj; |
| 1169 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1170 | if (defaultPhone != null) { |
| 1171 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1172 | } else { |
| 1173 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1174 | Bundle bundle = new Bundle(); |
| 1175 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
| 1176 | new ModemActivityInfo(0, 0, 0, new int[0], 0)); |
| 1177 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1178 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1179 | break; |
| 1180 | |
| 1181 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 1182 | ar = (AsyncResult) msg.obj; |
| 1183 | request = (MainThreadRequest) ar.userObj; |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1184 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1185 | |
| 1186 | ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1187 | if (ar.exception == null && ar.result != null) { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1188 | // Update the last modem activity info and the result of the request. |
| 1189 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1190 | if (isModemActivityInfoValid(info)) { |
| 1191 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 1192 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1193 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1194 | .getTransmitTimeMillis(); |
| 1195 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1196 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1197 | } |
| 1198 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 1199 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1200 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1201 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1202 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1203 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1204 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1205 | info.getReceiveTimeMillis() |
| 1206 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1207 | } |
| 1208 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 1209 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1210 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1211 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1212 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1213 | } else { |
| 1214 | if (ar.result == null) { |
| 1215 | loge("queryModemActivityInfo: Empty response"); |
| 1216 | } else if (ar.exception instanceof CommandException) { |
| 1217 | loge("queryModemActivityInfo: CommandException: " + |
| 1218 | ar.exception); |
| 1219 | } else { |
| 1220 | loge("queryModemActivityInfo: Unknown exception"); |
| 1221 | } |
| 1222 | } |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1223 | Bundle bundle = new Bundle(); |
| 1224 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1225 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1226 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1227 | break; |
| 1228 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1229 | case CMD_SET_ALLOWED_CARRIERS: |
| 1230 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1231 | CarrierRestrictionRules argument = |
| 1232 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1233 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1234 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1235 | break; |
| 1236 | |
| 1237 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1238 | ar = (AsyncResult) msg.obj; |
| 1239 | request = (MainThreadRequest) ar.userObj; |
| 1240 | if (ar.exception == null && ar.result != null) { |
| 1241 | request.result = ar.result; |
| 1242 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1243 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1244 | if (ar.exception instanceof CommandException) { |
| 1245 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1246 | CommandException.Error error = |
| 1247 | ((CommandException) (ar.exception)).getCommandError(); |
| 1248 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1249 | request.result = |
| 1250 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1251 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1252 | } else { |
| 1253 | loge("setAllowedCarriers: Unknown exception"); |
| 1254 | } |
| 1255 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1256 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1257 | break; |
| 1258 | |
| 1259 | case CMD_GET_ALLOWED_CARRIERS: |
| 1260 | request = (MainThreadRequest) msg.obj; |
| 1261 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1262 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1263 | break; |
| 1264 | |
| 1265 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1266 | ar = (AsyncResult) msg.obj; |
| 1267 | request = (MainThreadRequest) ar.userObj; |
| 1268 | if (ar.exception == null && ar.result != null) { |
| 1269 | request.result = ar.result; |
| 1270 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1271 | request.result = new IllegalStateException( |
| 1272 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1273 | if (ar.result == null) { |
| 1274 | loge("getAllowedCarriers: Empty response"); |
| 1275 | } else if (ar.exception instanceof CommandException) { |
| 1276 | loge("getAllowedCarriers: CommandException: " + |
| 1277 | ar.exception); |
| 1278 | } else { |
| 1279 | loge("getAllowedCarriers: Unknown exception"); |
| 1280 | } |
| 1281 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1282 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1283 | break; |
| 1284 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1285 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1286 | ar = (AsyncResult) msg.obj; |
| 1287 | request = (MainThreadRequest) ar.userObj; |
| 1288 | if (ar.exception == null && ar.result != null) { |
| 1289 | request.result = ar.result; |
| 1290 | } else { |
| 1291 | request.result = new IllegalArgumentException( |
| 1292 | "Failed to retrieve Forbidden Plmns"); |
| 1293 | if (ar.result == null) { |
| 1294 | loge("getForbiddenPlmns: Empty response"); |
| 1295 | } else { |
| 1296 | loge("getForbiddenPlmns: Unknown exception"); |
| 1297 | } |
| 1298 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1299 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1300 | break; |
| 1301 | |
| 1302 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1303 | request = (MainThreadRequest) msg.obj; |
| 1304 | uiccCard = getUiccCardFromRequest(request); |
| 1305 | if (uiccCard == null) { |
| 1306 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1307 | request.result = new IllegalArgumentException( |
| 1308 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1309 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1310 | break; |
| 1311 | } |
| 1312 | Integer appType = (Integer) request.argument; |
| 1313 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1314 | if (uiccApp == null) { |
| 1315 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1316 | + appType); |
| 1317 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1318 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1319 | break; |
| 1320 | } else { |
| 1321 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1322 | + " specified type -- " + appType); |
| 1323 | } |
| 1324 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1325 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1326 | onCompleted); |
| 1327 | break; |
| 1328 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1329 | case CMD_SWITCH_SLOTS: |
| 1330 | request = (MainThreadRequest) msg.obj; |
| 1331 | int[] physicalSlots = (int[]) request.argument; |
| 1332 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1333 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1334 | break; |
| 1335 | |
| 1336 | case EVENT_SWITCH_SLOTS_DONE: |
| 1337 | ar = (AsyncResult) msg.obj; |
| 1338 | request = (MainThreadRequest) ar.userObj; |
| 1339 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1340 | notifyRequester(request); |
| 1341 | break; |
| 1342 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1343 | request = (MainThreadRequest) msg.obj; |
| 1344 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1345 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1346 | break; |
| 1347 | |
| 1348 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1349 | ar = (AsyncResult) msg.obj; |
| 1350 | request = (MainThreadRequest) ar.userObj; |
| 1351 | if (ar.exception != null) { |
| 1352 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1353 | } else { |
| 1354 | int mode = ((int[]) ar.result)[0]; |
| 1355 | if (mode == 0) { |
| 1356 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1357 | } else { |
| 1358 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1359 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1360 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1361 | notifyRequester(request); |
| 1362 | break; |
| 1363 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1364 | request = (MainThreadRequest) msg.obj; |
| 1365 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1366 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1367 | break; |
| 1368 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1369 | ar = (AsyncResult) msg.obj; |
| 1370 | request = (MainThreadRequest) ar.userObj; |
| 1371 | if (ar.exception != null) { |
| 1372 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1373 | } else { |
| 1374 | request.result = ((int[]) ar.result)[0]; |
| 1375 | } |
| 1376 | notifyRequester(request); |
| 1377 | break; |
| 1378 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1379 | request = (MainThreadRequest) msg.obj; |
| 1380 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1381 | int mode = (int) request.argument; |
| 1382 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1383 | break; |
| 1384 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1385 | ar = (AsyncResult) msg.obj; |
| 1386 | request = (MainThreadRequest) ar.userObj; |
| 1387 | request.result = ar.exception == null; |
| 1388 | notifyRequester(request); |
| 1389 | break; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1390 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1391 | request = (MainThreadRequest) msg.obj; |
| 1392 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1393 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1394 | break; |
| 1395 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1396 | ar = (AsyncResult) msg.obj; |
| 1397 | request = (MainThreadRequest) ar.userObj; |
| 1398 | if (ar.exception != null) { |
| 1399 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1400 | } else { |
| 1401 | request.result = ((int[]) ar.result)[0]; |
| 1402 | } |
| 1403 | notifyRequester(request); |
| 1404 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1405 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1406 | request = (MainThreadRequest) msg.obj; |
| 1407 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1408 | int subscriptionMode = (int) request.argument; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1409 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1410 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1411 | break; |
| 1412 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1413 | ar = (AsyncResult) msg.obj; |
| 1414 | request = (MainThreadRequest) ar.userObj; |
| 1415 | request.result = ar.exception == null; |
| 1416 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1417 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1418 | case CMD_GET_ALL_CELL_INFO: |
| 1419 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1420 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1421 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1422 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1423 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1424 | ar = (AsyncResult) msg.obj; |
| 1425 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1426 | // If a timeout occurs, the response will be null |
| 1427 | request.result = (ar.exception == null && ar.result != null) |
| 1428 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1429 | synchronized (request) { |
| 1430 | request.notifyAll(); |
| 1431 | } |
| 1432 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1433 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1434 | request = (MainThreadRequest) msg.obj; |
| 1435 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1436 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1437 | break; |
| 1438 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1439 | ar = (AsyncResult) msg.obj; |
| 1440 | request = (MainThreadRequest) ar.userObj; |
| 1441 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1442 | try { |
| 1443 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1444 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1445 | cb.onError( |
| 1446 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1447 | ar.exception.getClass().getName(), |
| 1448 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1449 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1450 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1451 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1452 | } else { |
| 1453 | // use the result as returned |
| 1454 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1455 | } |
| 1456 | } catch (RemoteException re) { |
| 1457 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1458 | } |
| 1459 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1460 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1461 | request = (MainThreadRequest) msg.obj; |
| 1462 | WorkSource ws = (WorkSource) request.argument; |
| 1463 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1464 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1465 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1466 | } |
| 1467 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1468 | ar = (AsyncResult) msg.obj; |
| 1469 | request = (MainThreadRequest) ar.userObj; |
| 1470 | if (ar.exception == null) { |
| 1471 | request.result = ar.result; |
| 1472 | } else { |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1473 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1474 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1475 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1476 | } |
| 1477 | |
| 1478 | synchronized (request) { |
| 1479 | request.notifyAll(); |
| 1480 | } |
| 1481 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1482 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1483 | case CMD_MODEM_REBOOT: |
| 1484 | request = (MainThreadRequest) msg.obj; |
| 1485 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1486 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1487 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1488 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1489 | handleNullReturnEvent(msg, "rebootModem"); |
| 1490 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1491 | case CMD_REQUEST_ENABLE_MODEM: |
| 1492 | request = (MainThreadRequest) msg.obj; |
| 1493 | boolean enable = (boolean) request.argument; |
| 1494 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1495 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1496 | PhoneConfigurationManager.getInstance() |
| 1497 | .enablePhone(request.phone, enable, onCompleted); |
| 1498 | break; |
| 1499 | case EVENT_ENABLE_MODEM_DONE: |
| 1500 | ar = (AsyncResult) msg.obj; |
| 1501 | request = (MainThreadRequest) ar.userObj; |
| 1502 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1503 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1504 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1505 | if ((boolean) request.result) { |
| 1506 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1507 | updateModemStateMetrics(); |
| 1508 | } else { |
| 1509 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1510 | + ar.exception); |
| 1511 | } |
| 1512 | notifyRequester(request); |
| 1513 | break; |
| 1514 | case CMD_GET_MODEM_STATUS: |
| 1515 | request = (MainThreadRequest) msg.obj; |
| 1516 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1517 | PhoneConfigurationManager.getInstance() |
| 1518 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1519 | break; |
| 1520 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1521 | ar = (AsyncResult) msg.obj; |
| 1522 | request = (MainThreadRequest) ar.userObj; |
| 1523 | int id = request.phone.getPhoneId(); |
| 1524 | if (ar.exception == null && ar.result != null) { |
| 1525 | request.result = ar.result; |
| 1526 | //update the cache as modem status has changed |
| 1527 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1528 | (boolean) request.result); |
| 1529 | } else { |
| 1530 | // Return true if modem status cannot be retrieved. For most cases, |
| 1531 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1532 | // and disable modem are not supported. Modem is always on. |
| 1533 | // TODO: this should be fixed in R to support a third |
| 1534 | // status UNKNOWN b/131631629 |
| 1535 | request.result = true; |
| 1536 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1537 | + ar.exception); |
| 1538 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1539 | notifyRequester(request); |
| 1540 | break; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1541 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1542 | request = (MainThreadRequest) msg.obj; |
| 1543 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1544 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1545 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1546 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1547 | break; |
| 1548 | } |
| 1549 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1550 | ar = (AsyncResult) msg.obj; |
| 1551 | request = (MainThreadRequest) ar.userObj; |
| 1552 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1553 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1554 | args.second.accept(ar.exception == null); |
| 1555 | notifyRequester(request); |
| 1556 | break; |
| 1557 | } |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1558 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1559 | request = (MainThreadRequest) msg.obj; |
| 1560 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1561 | Phone phone = getPhoneFromRequest(request); |
| 1562 | if (phone != null) { |
| 1563 | phone.getSystemSelectionChannels(onCompleted); |
| 1564 | } else { |
| 1565 | loge("getSystemSelectionChannels: No phone object"); |
| 1566 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1567 | notifyRequester(request); |
| 1568 | } |
| 1569 | break; |
| 1570 | } |
| 1571 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1572 | ar = (AsyncResult) msg.obj; |
| 1573 | request = (MainThreadRequest) ar.userObj; |
| 1574 | if (ar.exception == null && ar.result != null) { |
| 1575 | request.result = ar.result; |
| 1576 | } else { |
| 1577 | request.result = new IllegalArgumentException( |
| 1578 | "Failed to retrieve system selection channels"); |
| 1579 | if (ar.result == null) { |
| 1580 | loge("getSystemSelectionChannels: Empty response"); |
| 1581 | } else { |
| 1582 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1583 | } |
| 1584 | } |
| 1585 | notifyRequester(request); |
| 1586 | break; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1587 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1588 | ar = (AsyncResult) msg.obj; |
| 1589 | request = (MainThreadRequest) ar.userObj; |
| 1590 | if (ar.exception == null && ar.result != null) { |
| 1591 | request.result = ar.result; |
| 1592 | } else { |
| 1593 | request.result = -1; |
| 1594 | loge("Failed to set Forbidden Plmns"); |
| 1595 | if (ar.result == null) { |
| 1596 | loge("setForbidenPlmns: Empty response"); |
| 1597 | } else if (ar.exception != null) { |
| 1598 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1599 | request.result = -1; |
| 1600 | } else { |
| 1601 | loge("setForbiddenPlmns: Unknown exception"); |
| 1602 | } |
| 1603 | } |
| 1604 | notifyRequester(request); |
| 1605 | break; |
| 1606 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1607 | request = (MainThreadRequest) msg.obj; |
| 1608 | uiccCard = getUiccCardFromRequest(request); |
| 1609 | if (uiccCard == null) { |
| 1610 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1611 | request.result = -1; |
| 1612 | notifyRequester(request); |
| 1613 | break; |
| 1614 | } |
| 1615 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1616 | (Pair<Integer, List<String>>) request.argument; |
| 1617 | appType = setFplmnsArgs.first; |
| 1618 | List<String> fplmns = setFplmnsArgs.second; |
| 1619 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1620 | if (uiccApp == null) { |
| 1621 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1622 | request.result = -1; |
| 1623 | loge("Failed to get UICC App"); |
| 1624 | notifyRequester(request); |
| 1625 | } else { |
| 1626 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1627 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1628 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1629 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1630 | break; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1631 | case CMD_ERASE_MODEM_CONFIG: |
| 1632 | request = (MainThreadRequest) msg.obj; |
| 1633 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1634 | defaultPhone.eraseModemConfig(onCompleted); |
| 1635 | break; |
| 1636 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1637 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1638 | break; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1639 | |
| 1640 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1641 | request = (MainThreadRequest) msg.obj; |
| 1642 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1643 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1644 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1645 | changed.first, changed.second, onCompleted); |
| 1646 | break; |
| 1647 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1648 | ar = (AsyncResult) msg.obj; |
| 1649 | request = (MainThreadRequest) ar.userObj; |
| 1650 | if (ar.exception == null) { |
| 1651 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1652 | } else { |
| 1653 | request.result = msg.arg1; |
| 1654 | } |
| 1655 | notifyRequester(request); |
| 1656 | break; |
| 1657 | |
| 1658 | case CMD_SET_ICC_LOCK_ENABLED: |
| 1659 | request = (MainThreadRequest) msg.obj; |
| 1660 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1661 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1662 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1663 | enabled.first, enabled.second, onCompleted); |
| 1664 | break; |
| 1665 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1666 | ar = (AsyncResult) msg.obj; |
| 1667 | request = (MainThreadRequest) ar.userObj; |
| 1668 | if (ar.exception == null) { |
| 1669 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1670 | } else { |
| 1671 | request.result = msg.arg1; |
| 1672 | } |
| 1673 | notifyRequester(request); |
| 1674 | break; |
| 1675 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1676 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1677 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1678 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1679 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1680 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1681 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1682 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1683 | default: |
| 1684 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1685 | break; |
| 1686 | } |
| 1687 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1688 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1689 | private void notifyRequester(MainThreadRequest request) { |
| 1690 | synchronized (request) { |
| 1691 | request.notifyAll(); |
| 1692 | } |
| 1693 | } |
| 1694 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1695 | private void handleNullReturnEvent(Message msg, String command) { |
| 1696 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1697 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1698 | if (ar.exception == null) { |
| 1699 | request.result = true; |
| 1700 | } else { |
| 1701 | request.result = false; |
| 1702 | if (ar.exception instanceof CommandException) { |
| 1703 | loge(command + ": CommandException: " + ar.exception); |
| 1704 | } else { |
| 1705 | loge(command + ": Unknown exception"); |
| 1706 | } |
| 1707 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1708 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1709 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1710 | } |
| 1711 | |
| 1712 | /** |
| 1713 | * Posts the specified command to be executed on the main thread, |
| 1714 | * waits for the request to complete, and returns the result. |
| 1715 | * @see #sendRequestAsync |
| 1716 | */ |
| 1717 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1718 | return sendRequest( |
| 1719 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1720 | } |
| 1721 | |
| 1722 | /** |
| 1723 | * Posts the specified command to be executed on the main thread, |
| 1724 | * waits for the request to complete, and returns the result. |
| 1725 | * @see #sendRequestAsync |
| 1726 | */ |
| 1727 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1728 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1729 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1730 | } |
| 1731 | |
| 1732 | /** |
| 1733 | * Posts the specified command to be executed on the main thread, |
| 1734 | * waits for the request to complete, and returns the result. |
| 1735 | * @see #sendRequestAsync |
| 1736 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1737 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1738 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1739 | } |
| 1740 | |
| 1741 | /** |
| 1742 | * Posts the specified command to be executed on the main thread, |
| 1743 | * waits for the request to complete, and returns the result. |
| 1744 | * @see #sendRequestAsync |
| 1745 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1746 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1747 | return sendRequest(command, argument, subId, null, workSource); |
| 1748 | } |
| 1749 | |
| 1750 | /** |
| 1751 | * Posts the specified command to be executed on the main thread, |
| 1752 | * waits for the request to complete, and returns the result. |
| 1753 | * @see #sendRequestAsync |
| 1754 | */ |
| 1755 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1756 | return sendRequest( |
| 1757 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1758 | } |
| 1759 | |
| 1760 | /** |
| 1761 | * Posts the specified command to be executed on the main thread, |
| 1762 | * waits for the request to complete, and returns the result. |
| 1763 | * @see #sendRequestAsync |
| 1764 | */ |
| 1765 | private Object sendRequest( |
| 1766 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1767 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1768 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1769 | } |
| 1770 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1771 | MainThreadRequest request = null; |
| 1772 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1773 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1774 | } else if (phone != null) { |
| 1775 | request = new MainThreadRequest(argument, phone, workSource); |
| 1776 | } else { |
| 1777 | request = new MainThreadRequest(argument, subId, workSource); |
| 1778 | } |
| 1779 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1780 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1781 | msg.sendToTarget(); |
| 1782 | |
| 1783 | // Wait for the request to complete |
| 1784 | synchronized (request) { |
| 1785 | while (request.result == null) { |
| 1786 | try { |
| 1787 | request.wait(); |
| 1788 | } catch (InterruptedException e) { |
| 1789 | // Do nothing, go back and wait until the request is complete |
| 1790 | } |
| 1791 | } |
| 1792 | } |
| 1793 | return request.result; |
| 1794 | } |
| 1795 | |
| 1796 | /** |
| 1797 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1798 | * Posts the specified command to be executed on the main thread, and |
| 1799 | * returns immediately. |
| 1800 | * @see #sendRequest |
| 1801 | */ |
| 1802 | private void sendRequestAsync(int command) { |
| 1803 | mMainThreadHandler.sendEmptyMessage(command); |
| 1804 | } |
| 1805 | |
| 1806 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1807 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1808 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1809 | */ |
| 1810 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1811 | sendRequestAsync(command, argument, null, null); |
| 1812 | } |
| 1813 | |
| 1814 | /** |
| 1815 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1816 | * @see {@link #sendRequest(int,Object)} |
| 1817 | */ |
| 1818 | private void sendRequestAsync( |
| 1819 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1820 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1821 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1822 | msg.sendToTarget(); |
| 1823 | } |
| 1824 | |
| 1825 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1826 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1827 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1828 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1829 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1830 | synchronized (PhoneInterfaceManager.class) { |
| 1831 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1832 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1833 | } else { |
| 1834 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1835 | } |
| 1836 | return sInstance; |
| 1837 | } |
| 1838 | } |
| 1839 | |
| 1840 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 1841 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1842 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1843 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1844 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1845 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1846 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1847 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1848 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1849 | mTelephonySharedPreferences = |
| 1850 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1851 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1852 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 1853 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1854 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1855 | publish(); |
| 1856 | } |
| 1857 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1858 | private Phone getDefaultPhone() { |
| 1859 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1860 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1861 | } |
| 1862 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1863 | private void publish() { |
| 1864 | if (DBG) log("publish: " + this); |
| 1865 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 1866 | TelephonyFrameworkInitializer |
| 1867 | .getTelephonyServiceManager() |
| 1868 | .getTelephonyServiceRegisterer() |
| 1869 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1870 | } |
| 1871 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1872 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1873 | if (request.phone != null) { |
| 1874 | return request.phone; |
| 1875 | } else { |
| 1876 | return getPhoneFromSubId(request.subId); |
| 1877 | } |
| 1878 | } |
| 1879 | |
| 1880 | private Phone getPhoneFromSubId(int subId) { |
| 1881 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1882 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1883 | } |
| 1884 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1885 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1886 | Phone phone = getPhoneFromRequest(request); |
| 1887 | return phone == null ? null : |
| 1888 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1889 | } |
| 1890 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1891 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1892 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1893 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1894 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1895 | |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1896 | private void sendEraseModemConfig(Phone phone) { |
| 1897 | if (phone != null) { |
| 1898 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 1899 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 1900 | final long identity = Binder.clearCallingIdentity(); |
| 1901 | try { |
| 1902 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 1903 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 1904 | } finally { |
| 1905 | Binder.restoreCallingIdentity(identity); |
| 1906 | } |
| 1907 | } |
| 1908 | } |
| 1909 | |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 1910 | private boolean isImsAvailableOnDevice() { |
| 1911 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 1912 | if (pm == null) { |
| 1913 | // For some reason package manger is not available.. This will fail internally anyway, |
| 1914 | // so do not throw error and allow. |
| 1915 | return true; |
| 1916 | } |
| 1917 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 1918 | } |
| 1919 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1920 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1921 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1922 | } |
| 1923 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1924 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1925 | if (DBG) log("dial: " + number); |
| 1926 | // No permission check needed here: This is just a wrapper around the |
| 1927 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1928 | // the UI before it does anything. |
| 1929 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1930 | final long identity = Binder.clearCallingIdentity(); |
| 1931 | try { |
| 1932 | String url = createTelUrl(number); |
| 1933 | if (url == null) { |
| 1934 | return; |
| 1935 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1936 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1937 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1938 | PhoneConstants.State state = mCM.getState(subId); |
| 1939 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1940 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1941 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1942 | mApp.startActivity(intent); |
| 1943 | } |
| 1944 | } finally { |
| 1945 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1946 | } |
| 1947 | } |
| 1948 | |
| 1949 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1950 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1951 | } |
| 1952 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1953 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1954 | if (DBG) log("call: " + number); |
| 1955 | |
| 1956 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 1957 | // need to do a permission check since we're calling startActivity() |
| 1958 | // from the context of the phone app. |
| 1959 | enforceCallPermission(); |
| 1960 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 1961 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1962 | != AppOpsManager.MODE_ALLOWED) { |
| 1963 | return; |
| 1964 | } |
| 1965 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1966 | final long identity = Binder.clearCallingIdentity(); |
| 1967 | try { |
| 1968 | String url = createTelUrl(number); |
| 1969 | if (url == null) { |
| 1970 | return; |
| 1971 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1972 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1973 | boolean isValid = false; |
| 1974 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 1975 | if (slist != null) { |
| 1976 | for (SubscriptionInfo subInfoRecord : slist) { |
| 1977 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 1978 | isValid = true; |
| 1979 | break; |
| 1980 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1981 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1982 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1983 | if (!isValid) { |
| 1984 | return; |
| 1985 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 1986 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1987 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 1988 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 1989 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1990 | mApp.startActivity(intent); |
| 1991 | } finally { |
| 1992 | Binder.restoreCallingIdentity(identity); |
| 1993 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1994 | } |
| 1995 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1996 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1997 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 1998 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 1999 | } |
| 2000 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2001 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2002 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2003 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2004 | } |
| 2005 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2006 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2007 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2008 | |
| 2009 | final long identity = Binder.clearCallingIdentity(); |
| 2010 | try { |
| 2011 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 2012 | checkSimPin.start(); |
| 2013 | return checkSimPin.unlockSim(null, pin); |
| 2014 | } finally { |
| 2015 | Binder.restoreCallingIdentity(identity); |
| 2016 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2017 | } |
| 2018 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2019 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2020 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2021 | |
| 2022 | final long identity = Binder.clearCallingIdentity(); |
| 2023 | try { |
| 2024 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 2025 | checkSimPuk.start(); |
| 2026 | return checkSimPuk.unlockSim(puk, pin); |
| 2027 | } finally { |
| 2028 | Binder.restoreCallingIdentity(identity); |
| 2029 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2030 | } |
| 2031 | |
| 2032 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2033 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2034 | * a synchronous one. |
| 2035 | */ |
| 2036 | private static class UnlockSim extends Thread { |
| 2037 | |
| 2038 | private final IccCard mSimCard; |
| 2039 | |
| 2040 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2041 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2042 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2043 | |
| 2044 | // For replies from SimCard interface |
| 2045 | private Handler mHandler; |
| 2046 | |
| 2047 | // For async handler to identify request type |
| 2048 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2049 | |
| 2050 | public UnlockSim(IccCard simCard) { |
| 2051 | mSimCard = simCard; |
| 2052 | } |
| 2053 | |
| 2054 | @Override |
| 2055 | public void run() { |
| 2056 | Looper.prepare(); |
| 2057 | synchronized (UnlockSim.this) { |
| 2058 | mHandler = new Handler() { |
| 2059 | @Override |
| 2060 | public void handleMessage(Message msg) { |
| 2061 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2062 | switch (msg.what) { |
| 2063 | case SUPPLY_PIN_COMPLETE: |
| 2064 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2065 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2066 | mRetryCount = msg.arg1; |
| 2067 | if (ar.exception != null) { |
| 2068 | if (ar.exception instanceof CommandException && |
| 2069 | ((CommandException)(ar.exception)).getCommandError() |
| 2070 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2071 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2072 | } //When UiccCardApp dispose,handle message and return exception |
| 2073 | else if (ar.exception instanceof CommandException && |
| 2074 | ((CommandException) (ar.exception)).getCommandError() |
| 2075 | == CommandException.Error.ABORTED) { |
| 2076 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2077 | } else { |
| 2078 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2079 | } |
| 2080 | } else { |
| 2081 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2082 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2083 | mDone = true; |
| 2084 | UnlockSim.this.notifyAll(); |
| 2085 | } |
| 2086 | break; |
| 2087 | } |
| 2088 | } |
| 2089 | }; |
| 2090 | UnlockSim.this.notifyAll(); |
| 2091 | } |
| 2092 | Looper.loop(); |
| 2093 | } |
| 2094 | |
| 2095 | /* |
| 2096 | * Use PIN or PUK to unlock SIM card |
| 2097 | * |
| 2098 | * If PUK is null, unlock SIM card with PIN |
| 2099 | * |
| 2100 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2101 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2102 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2103 | |
| 2104 | while (mHandler == null) { |
| 2105 | try { |
| 2106 | wait(); |
| 2107 | } catch (InterruptedException e) { |
| 2108 | Thread.currentThread().interrupt(); |
| 2109 | } |
| 2110 | } |
| 2111 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2112 | |
| 2113 | if (puk == null) { |
| 2114 | mSimCard.supplyPin(pin, callback); |
| 2115 | } else { |
| 2116 | mSimCard.supplyPuk(puk, pin, callback); |
| 2117 | } |
| 2118 | |
| 2119 | while (!mDone) { |
| 2120 | try { |
| 2121 | Log.d(LOG_TAG, "wait for done"); |
| 2122 | wait(); |
| 2123 | } catch (InterruptedException e) { |
| 2124 | // Restore the interrupted status |
| 2125 | Thread.currentThread().interrupt(); |
| 2126 | } |
| 2127 | } |
| 2128 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2129 | int[] resultArray = new int[2]; |
| 2130 | resultArray[0] = mResult; |
| 2131 | resultArray[1] = mRetryCount; |
| 2132 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2133 | } |
| 2134 | } |
| 2135 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2136 | /** |
| 2137 | * This method has been removed due to privacy and stability concerns. |
| 2138 | */ |
| 2139 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2140 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2141 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2142 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2143 | } |
| 2144 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2145 | @Override |
| 2146 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2147 | mApp.getSystemService(AppOpsManager.class) |
| 2148 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2149 | |
| 2150 | final int targetSdk = getTargetSdk(callingPackage); |
| 2151 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2152 | // Callers targeting S have no business invoking this method. |
| 2153 | return; |
| 2154 | } |
| 2155 | |
| 2156 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2157 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2158 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2159 | .setCallingPackage(callingPackage) |
| 2160 | .setCallingFeatureId(null) |
| 2161 | .setCallingPid(Binder.getCallingPid()) |
| 2162 | .setCallingUid(Binder.getCallingUid()) |
| 2163 | .setMethod("updateServiceLocation") |
| 2164 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2165 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2166 | .build()); |
| 2167 | // Apps that lack location permission have no business calling this method; |
| 2168 | // however, because no permission was declared in the public API, denials must |
| 2169 | // all be "soft". |
| 2170 | switch (locationResult) { |
| 2171 | case DENIED_HARD: /* fall through */ |
| 2172 | case DENIED_SOFT: |
| 2173 | return; |
| 2174 | } |
| 2175 | |
| 2176 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2177 | final long identity = Binder.clearCallingIdentity(); |
| 2178 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2179 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2180 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2181 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2182 | } |
| 2183 | } finally { |
| 2184 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2185 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2186 | } |
| 2187 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2188 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2189 | @Override |
| 2190 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2191 | return isRadioOnWithFeature(callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2192 | } |
| 2193 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2194 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2195 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2196 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2197 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2198 | callingFeatureId); |
| 2199 | } |
| 2200 | |
| 2201 | @Deprecated |
| 2202 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2203 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2204 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
| 2205 | } |
| 2206 | |
| 2207 | @Override |
| 2208 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2209 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2210 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2211 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2212 | return false; |
| 2213 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2214 | |
| 2215 | final long identity = Binder.clearCallingIdentity(); |
| 2216 | try { |
| 2217 | return isRadioOnForSubscriber(subId); |
| 2218 | } finally { |
| 2219 | Binder.restoreCallingIdentity(identity); |
| 2220 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2221 | } |
| 2222 | |
| 2223 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2224 | final long identity = Binder.clearCallingIdentity(); |
| 2225 | try { |
| 2226 | final Phone phone = getPhone(subId); |
| 2227 | if (phone != null) { |
| 2228 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2229 | } else { |
| 2230 | return false; |
| 2231 | } |
| 2232 | } finally { |
| 2233 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2234 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2235 | } |
| 2236 | |
| 2237 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2238 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2239 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2240 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2241 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2242 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2243 | |
| 2244 | final long identity = Binder.clearCallingIdentity(); |
| 2245 | try { |
| 2246 | final Phone phone = getPhone(subId); |
| 2247 | if (phone != null) { |
| 2248 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2249 | } |
| 2250 | } finally { |
| 2251 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2252 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2253 | } |
| 2254 | |
| 2255 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2256 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2257 | } |
| 2258 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2259 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2260 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2261 | |
| 2262 | final long identity = Binder.clearCallingIdentity(); |
| 2263 | try { |
| 2264 | final Phone phone = getPhone(subId); |
| 2265 | if (phone == null) { |
| 2266 | return false; |
| 2267 | } |
| 2268 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2269 | toggleRadioOnOffForSubscriber(subId); |
| 2270 | } |
| 2271 | return true; |
| 2272 | } finally { |
| 2273 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2274 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2275 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2276 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2277 | public boolean needMobileRadioShutdown() { |
Shuo Qian | afeaf7d | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2278 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2279 | /* |
| 2280 | * If any of the Radios are available, it will need to be |
| 2281 | * shutdown. So return true if any Radio is available. |
| 2282 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2283 | final long identity = Binder.clearCallingIdentity(); |
| 2284 | try { |
| 2285 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2286 | Phone phone = PhoneFactory.getPhone(i); |
| 2287 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2288 | } |
| 2289 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2290 | return false; |
| 2291 | } finally { |
| 2292 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2293 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2294 | } |
| 2295 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2296 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2297 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2298 | enforceModifyPermission(); |
| 2299 | |
| 2300 | final long identity = Binder.clearCallingIdentity(); |
| 2301 | try { |
| 2302 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2303 | logv("Shutting down Phone " + i); |
| 2304 | shutdownRadioUsingPhoneId(i); |
| 2305 | } |
| 2306 | } finally { |
| 2307 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2308 | } |
| 2309 | } |
| 2310 | |
| 2311 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2312 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2313 | if (phone != null && phone.isRadioAvailable()) { |
| 2314 | phone.shutdownRadio(); |
| 2315 | } |
| 2316 | } |
| 2317 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2318 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2319 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2320 | |
| 2321 | final long identity = Binder.clearCallingIdentity(); |
| 2322 | try { |
| 2323 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2324 | if (defaultPhone != null) { |
| 2325 | defaultPhone.setRadioPower(turnOn); |
| 2326 | return true; |
| 2327 | } else { |
| 2328 | loge("There's no default phone."); |
| 2329 | return false; |
| 2330 | } |
| 2331 | } finally { |
| 2332 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2333 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2334 | } |
| 2335 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2336 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2337 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2338 | |
| 2339 | final long identity = Binder.clearCallingIdentity(); |
| 2340 | try { |
| 2341 | final Phone phone = getPhone(subId); |
| 2342 | if (phone != null) { |
| 2343 | phone.setRadioPower(turnOn); |
| 2344 | return true; |
| 2345 | } else { |
| 2346 | return false; |
| 2347 | } |
| 2348 | } finally { |
| 2349 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2350 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2351 | } |
| 2352 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2353 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2354 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2355 | public boolean enableDataConnectivity() { |
| 2356 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2357 | |
| 2358 | final long identity = Binder.clearCallingIdentity(); |
| 2359 | try { |
| 2360 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2361 | final Phone phone = getPhone(subId); |
| 2362 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 2363 | phone.getDataEnabledSettings().setDataEnabled( |
| 2364 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2365 | return true; |
| 2366 | } else { |
| 2367 | return false; |
| 2368 | } |
| 2369 | } finally { |
| 2370 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2371 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2372 | } |
| 2373 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2374 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2375 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2376 | public boolean disableDataConnectivity() { |
| 2377 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2378 | |
| 2379 | final long identity = Binder.clearCallingIdentity(); |
| 2380 | try { |
| 2381 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2382 | final Phone phone = getPhone(subId); |
| 2383 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 2384 | phone.getDataEnabledSettings().setDataEnabled( |
| 2385 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2386 | return true; |
| 2387 | } else { |
| 2388 | return false; |
| 2389 | } |
| 2390 | } finally { |
| 2391 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2392 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2393 | } |
| 2394 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2395 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2396 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2397 | final long identity = Binder.clearCallingIdentity(); |
| 2398 | try { |
| 2399 | final Phone phone = getPhone(subId); |
| 2400 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2401 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2402 | } else { |
| 2403 | return false; |
| 2404 | } |
| 2405 | } finally { |
| 2406 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2407 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2408 | } |
| 2409 | |
| 2410 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2411 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2412 | } |
| 2413 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2414 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2415 | enforceCallPermission(); |
| 2416 | |
| 2417 | final long identity = Binder.clearCallingIdentity(); |
| 2418 | try { |
| 2419 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2420 | return; |
| 2421 | } |
| 2422 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2423 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2424 | } finally { |
| 2425 | Binder.restoreCallingIdentity(identity); |
| 2426 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2427 | }; |
| 2428 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2429 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2430 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2431 | |
| 2432 | final long identity = Binder.clearCallingIdentity(); |
| 2433 | try { |
| 2434 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2435 | return false; |
| 2436 | } |
| 2437 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2438 | } finally { |
| 2439 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2440 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2441 | } |
| 2442 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2443 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2444 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2445 | } |
| 2446 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2447 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2448 | final long identity = Binder.clearCallingIdentity(); |
| 2449 | try { |
| 2450 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2451 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2452 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2453 | } finally { |
| 2454 | Binder.restoreCallingIdentity(identity); |
| 2455 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2456 | } |
| 2457 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2458 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2459 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2460 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2461 | } |
| 2462 | |
| 2463 | @Override |
| 2464 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2465 | final long identity = Binder.clearCallingIdentity(); |
| 2466 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2467 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2468 | if (phone != null) { |
| 2469 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2470 | } else { |
| 2471 | return PhoneConstantConversions.convertDataState( |
| 2472 | PhoneConstants.DataState.DISCONNECTED); |
| 2473 | } |
| 2474 | } finally { |
| 2475 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2476 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2477 | } |
| 2478 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2479 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2480 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2481 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2482 | } |
| 2483 | |
| 2484 | @Override |
| 2485 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2486 | final long identity = Binder.clearCallingIdentity(); |
| 2487 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2488 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2489 | if (phone != null) { |
| 2490 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2491 | } else { |
| 2492 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2493 | } |
| 2494 | } finally { |
| 2495 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2496 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2497 | } |
| 2498 | |
| 2499 | @Override |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2500 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2501 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2502 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2503 | |
| 2504 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2505 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2506 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2507 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2508 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2509 | .setCallingPid(Binder.getCallingPid()) |
| 2510 | .setCallingUid(Binder.getCallingUid()) |
| 2511 | .setMethod("getCellLocation") |
Hall Liu | c3f8eb6 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2512 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2513 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2514 | .build()); |
| 2515 | switch (locationResult) { |
| 2516 | case DENIED_HARD: |
| 2517 | throw new SecurityException("Not allowed to access cell location"); |
| 2518 | case DENIED_SOFT: |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2519 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2520 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2521 | } |
| 2522 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2523 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2524 | final long identity = Binder.clearCallingIdentity(); |
| 2525 | try { |
| 2526 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2527 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2528 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2529 | } finally { |
| 2530 | Binder.restoreCallingIdentity(identity); |
| 2531 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2532 | } |
| 2533 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2534 | @Override |
Jack Yu | 0142503 | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2535 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2536 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2537 | // registered cell info, so return a NULL country instead. |
| 2538 | final long identity = Binder.clearCallingIdentity(); |
| 2539 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2540 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2541 | // Get default phone in this case. |
| 2542 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2543 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2544 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2545 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | cf38ed9 | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2546 | if (phone == null) return ""; |
| 2547 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2548 | if (sst == null) return ""; |
| 2549 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2550 | if (lt == null) return ""; |
| 2551 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry(); |
| 2552 | EmergencyNumberTracker ent = phone.getEmergencyNumberTracker(); |
| 2553 | return (ent == null) ? "" : ent.getEmergencyCountryIso(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2554 | } finally { |
| 2555 | Binder.restoreCallingIdentity(identity); |
| 2556 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2557 | } |
| 2558 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2559 | /** |
| 2560 | * This method was removed due to potential issues caused by performing partial |
| 2561 | * updates of service state, and lack of a credible use case. |
| 2562 | * |
| 2563 | * This has the ability to break the telephony implementation by disabling notification of |
| 2564 | * changes in device connectivity. DO NOT USE THIS! |
| 2565 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2566 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2567 | public void enableLocationUpdates() { |
| 2568 | mApp.enforceCallingOrSelfPermission( |
| 2569 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2570 | } |
| 2571 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2572 | /** |
| 2573 | * This method was removed due to potential issues caused by performing partial |
| 2574 | * updates of service state, and lack of a credible use case. |
| 2575 | * |
| 2576 | * This has the ability to break the telephony implementation by disabling notification of |
| 2577 | * changes in device connectivity. DO NOT USE THIS! |
| 2578 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2579 | @Override |
| 2580 | public void disableLocationUpdates() { |
| 2581 | mApp.enforceCallingOrSelfPermission( |
| 2582 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2583 | } |
| 2584 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2585 | /** |
| 2586 | * Returns the target SDK version number for a given package name. |
| 2587 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2588 | * This call MUST be invoked before clearing the calling UID. |
| 2589 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2590 | * @return target SDK if the package is found or INT_MAX. |
| 2591 | */ |
| 2592 | private int getTargetSdk(String packageName) { |
| 2593 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2594 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 54d2030 | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2595 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2596 | if (ai != null) return ai.targetSdkVersion; |
| 2597 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2598 | loge("Failed to get package info for pkg=" |
| 2599 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2600 | } |
| 2601 | return Integer.MAX_VALUE; |
| 2602 | } |
| 2603 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2604 | @Override |
| 2605 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2606 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2607 | String callingFeatureId) { |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2608 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2609 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2610 | throw new SecurityException( |
| 2611 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2612 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2613 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2614 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2615 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2616 | return null; |
| 2617 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2618 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2619 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2620 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2621 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2622 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2623 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2624 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2625 | for (CellInfo ci : info) { |
| 2626 | if (ci instanceof CellInfoGsm) { |
| 2627 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2628 | } else if (ci instanceof CellInfoWcdma) { |
| 2629 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2630 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2631 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2632 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2633 | } |
| 2634 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2635 | private List<CellInfo> getCachedCellInfo() { |
| 2636 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2637 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2638 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2639 | if (info != null) cellInfos.addAll(info); |
| 2640 | } |
| 2641 | return cellInfos; |
| 2642 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2643 | |
| 2644 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2645 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2646 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2647 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2648 | |
| 2649 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2650 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2651 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2652 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2653 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2654 | .setCallingPid(Binder.getCallingPid()) |
| 2655 | .setCallingUid(Binder.getCallingUid()) |
| 2656 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2657 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2658 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2659 | .build()); |
| 2660 | switch (locationResult) { |
| 2661 | case DENIED_HARD: |
| 2662 | throw new SecurityException("Not allowed to access cell info"); |
| 2663 | case DENIED_SOFT: |
| 2664 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2665 | } |
| 2666 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2667 | final int targetSdk = getTargetSdk(callingPackage); |
| 2668 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2669 | return getCachedCellInfo(); |
| 2670 | } |
| 2671 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2672 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2673 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2674 | final long identity = Binder.clearCallingIdentity(); |
| 2675 | try { |
| 2676 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2677 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2678 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2679 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2680 | if (info != null) cellInfos.addAll(info); |
| 2681 | } |
| 2682 | return cellInfos; |
| 2683 | } finally { |
| 2684 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2685 | } |
| 2686 | } |
| 2687 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2688 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2689 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2690 | String callingFeatureId) { |
| 2691 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2692 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2693 | } |
| 2694 | |
| 2695 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2696 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2697 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2698 | enforceModifyPermission(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2699 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2700 | } |
| 2701 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2702 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2703 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2704 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2705 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2706 | |
| 2707 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2708 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2709 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2710 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2711 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2712 | .setCallingPid(Binder.getCallingPid()) |
| 2713 | .setCallingUid(Binder.getCallingUid()) |
| 2714 | .setMethod("requestCellInfoUpdate") |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2715 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2716 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2717 | .build()); |
| 2718 | switch (locationResult) { |
| 2719 | case DENIED_HARD: |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2720 | if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) { |
| 2721 | // Safetynet logging for b/154934934 |
| 2722 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2723 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2724 | throw new SecurityException("Not allowed to access cell info"); |
| 2725 | case DENIED_SOFT: |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2726 | if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) { |
| 2727 | // Safetynet logging for b/154934934 |
| 2728 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2729 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2730 | try { |
| 2731 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2732 | } catch (RemoteException re) { |
| 2733 | // Drop without consequences |
| 2734 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2735 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2736 | } |
| 2737 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2738 | |
| 2739 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2740 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2741 | |
| 2742 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2743 | } |
| 2744 | |
| 2745 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2746 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2747 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2748 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2749 | |
| 2750 | final long identity = Binder.clearCallingIdentity(); |
| 2751 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2752 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2753 | } finally { |
| 2754 | Binder.restoreCallingIdentity(identity); |
| 2755 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2756 | } |
| 2757 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2758 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2759 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2760 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2761 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2762 | return null; |
| 2763 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2764 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2765 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2766 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2767 | return null; |
| 2768 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2769 | |
| 2770 | final long identity = Binder.clearCallingIdentity(); |
| 2771 | try { |
| 2772 | return phone.getImei(); |
| 2773 | } finally { |
| 2774 | Binder.restoreCallingIdentity(identity); |
| 2775 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2776 | } |
| 2777 | |
| 2778 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2779 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2780 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2781 | String tac = null; |
| 2782 | if (phone != null) { |
| 2783 | String imei = phone.getImei(); |
| 2784 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2785 | } |
| 2786 | return tac; |
| 2787 | } |
| 2788 | |
| 2789 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2790 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2791 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2792 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2793 | return null; |
| 2794 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2795 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2796 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2797 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2798 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2799 | return null; |
| 2800 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2801 | |
| 2802 | final long identity = Binder.clearCallingIdentity(); |
| 2803 | try { |
| 2804 | return phone.getMeid(); |
| 2805 | } finally { |
| 2806 | Binder.restoreCallingIdentity(identity); |
| 2807 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2808 | } |
| 2809 | |
| 2810 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2811 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2812 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2813 | String manufacturerCode = null; |
| 2814 | if (phone != null) { |
| 2815 | String meid = phone.getMeid(); |
| 2816 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2817 | } |
| 2818 | return manufacturerCode; |
| 2819 | } |
| 2820 | |
| 2821 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2822 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2823 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2824 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2825 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2826 | return null; |
| 2827 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2828 | int subId = phone.getSubId(); |
| 2829 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2830 | mApp, subId, callingPackage, callingFeatureId, |
| 2831 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2832 | return null; |
| 2833 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2834 | |
| 2835 | final long identity = Binder.clearCallingIdentity(); |
| 2836 | try { |
| 2837 | return phone.getDeviceSvn(); |
| 2838 | } finally { |
| 2839 | Binder.restoreCallingIdentity(identity); |
| 2840 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2841 | } |
| 2842 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2843 | @Override |
| 2844 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2845 | final long identity = Binder.clearCallingIdentity(); |
| 2846 | try { |
| 2847 | final Phone phone = getPhone(subId); |
| 2848 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2849 | } finally { |
| 2850 | Binder.restoreCallingIdentity(identity); |
| 2851 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2852 | } |
| 2853 | |
| 2854 | @Override |
| 2855 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2856 | final long identity = Binder.clearCallingIdentity(); |
| 2857 | try { |
| 2858 | final Phone phone = getPhone(subId); |
| 2859 | return phone == null ? null : phone.getCarrierName(); |
| 2860 | } finally { |
| 2861 | Binder.restoreCallingIdentity(identity); |
| 2862 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2863 | } |
| 2864 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2865 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2866 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2867 | final long identity = Binder.clearCallingIdentity(); |
| 2868 | try { |
| 2869 | final Phone phone = getPhone(subId); |
| 2870 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2871 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2872 | } finally { |
| 2873 | Binder.restoreCallingIdentity(identity); |
| 2874 | } |
| 2875 | } |
| 2876 | |
| 2877 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2878 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2879 | final long identity = Binder.clearCallingIdentity(); |
| 2880 | try { |
| 2881 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2882 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2883 | } finally { |
| 2884 | Binder.restoreCallingIdentity(identity); |
| 2885 | } |
| 2886 | } |
| 2887 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2888 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2889 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2890 | if (!isSubscriptionMccMnc) { |
| 2891 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2892 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2893 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2894 | if (phone == null) { |
| 2895 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2896 | } |
| 2897 | final long identity = Binder.clearCallingIdentity(); |
| 2898 | try { |
| 2899 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2900 | } finally { |
| 2901 | Binder.restoreCallingIdentity(identity); |
| 2902 | } |
| 2903 | } |
| 2904 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2905 | // |
| 2906 | // Internal helper methods. |
| 2907 | // |
| 2908 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2909 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2910 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2911 | * |
| 2912 | * @throws SecurityException if the caller does not have the required permission |
| 2913 | */ |
| 2914 | private void enforceModifyPermission() { |
| 2915 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2916 | } |
| 2917 | |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 2918 | /** |
| 2919 | * Make sure the caller is system. |
| 2920 | * |
| 2921 | * @throws SecurityException if the caller is not system. |
| 2922 | */ |
| 2923 | private void enforceSystemCaller() { |
| 2924 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 2925 | throw new SecurityException("Caller must be system"); |
| 2926 | } |
| 2927 | } |
| 2928 | |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 2929 | private void enforceActiveEmergencySessionPermission() { |
| 2930 | mApp.enforceCallingOrSelfPermission( |
| 2931 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 2932 | } |
| 2933 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2934 | /** |
| 2935 | * Make sure the caller has the CALL_PHONE permission. |
| 2936 | * |
| 2937 | * @throws SecurityException if the caller does not have the required permission |
| 2938 | */ |
| 2939 | private void enforceCallPermission() { |
| 2940 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2941 | } |
| 2942 | |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 2943 | private void enforceSettingsPermission() { |
| 2944 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 2945 | } |
| 2946 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2947 | private String createTelUrl(String number) { |
| 2948 | if (TextUtils.isEmpty(number)) { |
| 2949 | return null; |
| 2950 | } |
| 2951 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 2952 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2953 | } |
| 2954 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2955 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2956 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2957 | } |
| 2958 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2959 | private static void logv(String msg) { |
| 2960 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2961 | } |
| 2962 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 2963 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2964 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 2965 | } |
| 2966 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2967 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2968 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2969 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2970 | } |
| 2971 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2972 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2973 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2974 | final long identity = Binder.clearCallingIdentity(); |
| 2975 | try { |
| 2976 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2977 | if (phone == null) { |
| 2978 | return PhoneConstants.PHONE_TYPE_NONE; |
| 2979 | } else { |
| 2980 | return phone.getPhoneType(); |
| 2981 | } |
| 2982 | } finally { |
| 2983 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2984 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2985 | } |
| 2986 | |
| 2987 | /** |
| 2988 | * Returns the CDMA ERI icon index to display |
| 2989 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2990 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2991 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 2992 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 2993 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2994 | } |
| 2995 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2996 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2997 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 2998 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2999 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3000 | mApp, subId, callingPackage, callingFeatureId, |
| 3001 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3002 | return -1; |
| 3003 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3004 | |
| 3005 | final long identity = Binder.clearCallingIdentity(); |
| 3006 | try { |
| 3007 | final Phone phone = getPhone(subId); |
| 3008 | if (phone != null) { |
| 3009 | return phone.getCdmaEriIconIndex(); |
| 3010 | } else { |
| 3011 | return -1; |
| 3012 | } |
| 3013 | } finally { |
| 3014 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3015 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3016 | } |
| 3017 | |
| 3018 | /** |
| 3019 | * Returns the CDMA ERI icon mode, |
| 3020 | * 0 - ON |
| 3021 | * 1 - FLASHING |
| 3022 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3023 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3024 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3025 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3026 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3027 | } |
| 3028 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3029 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3030 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3031 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3032 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3033 | mApp, subId, callingPackage, callingFeatureId, |
| 3034 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3035 | return -1; |
| 3036 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3037 | |
| 3038 | final long identity = Binder.clearCallingIdentity(); |
| 3039 | try { |
| 3040 | final Phone phone = getPhone(subId); |
| 3041 | if (phone != null) { |
| 3042 | return phone.getCdmaEriIconMode(); |
| 3043 | } else { |
| 3044 | return -1; |
| 3045 | } |
| 3046 | } finally { |
| 3047 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3048 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3049 | } |
| 3050 | |
| 3051 | /** |
| 3052 | * Returns the CDMA ERI text, |
| 3053 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3054 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3055 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3056 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3057 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3058 | } |
| 3059 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3060 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3061 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3062 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3063 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3064 | mApp, subId, callingPackage, callingFeatureId, |
| 3065 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3066 | return null; |
| 3067 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3068 | |
| 3069 | final long identity = Binder.clearCallingIdentity(); |
| 3070 | try { |
| 3071 | final Phone phone = getPhone(subId); |
| 3072 | if (phone != null) { |
| 3073 | return phone.getCdmaEriText(); |
| 3074 | } else { |
| 3075 | return null; |
| 3076 | } |
| 3077 | } finally { |
| 3078 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3079 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3080 | } |
| 3081 | |
| 3082 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3083 | * Returns the CDMA MDN. |
| 3084 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3085 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3086 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3087 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3088 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3089 | |
| 3090 | final long identity = Binder.clearCallingIdentity(); |
| 3091 | try { |
| 3092 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3093 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3094 | return phone.getLine1Number(); |
| 3095 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3096 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3097 | return null; |
| 3098 | } |
| 3099 | } finally { |
| 3100 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3101 | } |
| 3102 | } |
| 3103 | |
| 3104 | /** |
| 3105 | * Returns the CDMA MIN. |
| 3106 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3107 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3108 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3109 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3110 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3111 | |
| 3112 | final long identity = Binder.clearCallingIdentity(); |
| 3113 | try { |
| 3114 | final Phone phone = getPhone(subId); |
| 3115 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3116 | return phone.getCdmaMin(); |
| 3117 | } else { |
| 3118 | return null; |
| 3119 | } |
| 3120 | } finally { |
| 3121 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3122 | } |
| 3123 | } |
| 3124 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3125 | @Override |
| 3126 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3127 | INumberVerificationCallback callback, String callingPackage) { |
| 3128 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3129 | != PERMISSION_GRANTED) { |
| 3130 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3131 | } |
| 3132 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3133 | |
| 3134 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3135 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 3136 | throw new SecurityException("Calling package must be configured in the device config"); |
| 3137 | } |
| 3138 | |
| 3139 | if (range == null) { |
| 3140 | throw new NullPointerException("Range must be non-null"); |
| 3141 | } |
| 3142 | |
| 3143 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3144 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3145 | |
| 3146 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3147 | } |
| 3148 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3149 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3150 | * Returns true if CDMA provisioning needs to run. |
| 3151 | */ |
| 3152 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3153 | final long identity = Binder.clearCallingIdentity(); |
| 3154 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3155 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3156 | } finally { |
| 3157 | Binder.restoreCallingIdentity(identity); |
| 3158 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3159 | } |
| 3160 | |
| 3161 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3162 | * Sets the voice mail number of a given subId. |
| 3163 | */ |
| 3164 | @Override |
| 3165 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3166 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3167 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3168 | |
| 3169 | final long identity = Binder.clearCallingIdentity(); |
| 3170 | try { |
| 3171 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3172 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3173 | return success; |
| 3174 | } finally { |
| 3175 | Binder.restoreCallingIdentity(identity); |
| 3176 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3177 | } |
| 3178 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3179 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3180 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3181 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3182 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3183 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3184 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3185 | throw new SecurityException("caller must be system dialer"); |
| 3186 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3187 | |
| 3188 | final long identity = Binder.clearCallingIdentity(); |
| 3189 | try { |
| 3190 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3191 | if (phoneAccountHandle == null) { |
| 3192 | return null; |
| 3193 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3194 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3195 | } finally { |
| 3196 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3197 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3198 | } |
| 3199 | |
| 3200 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3201 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3202 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3203 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3204 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3205 | mApp, subId, callingPackage, callingFeatureId, |
| 3206 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3207 | return null; |
| 3208 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3209 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3210 | final long identity = Binder.clearCallingIdentity(); |
| 3211 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3212 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3213 | } finally { |
| 3214 | Binder.restoreCallingIdentity(identity); |
| 3215 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3216 | } |
| 3217 | |
| 3218 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3219 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3220 | VisualVoicemailSmsFilterSettings settings) { |
| 3221 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3222 | |
| 3223 | final long identity = Binder.clearCallingIdentity(); |
| 3224 | try { |
| 3225 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3226 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3227 | } finally { |
| 3228 | Binder.restoreCallingIdentity(identity); |
| 3229 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3230 | } |
| 3231 | |
| 3232 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3233 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3234 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3235 | |
| 3236 | final long identity = Binder.clearCallingIdentity(); |
| 3237 | try { |
| 3238 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3239 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3240 | } finally { |
| 3241 | Binder.restoreCallingIdentity(identity); |
| 3242 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3243 | } |
| 3244 | |
| 3245 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3246 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3247 | String callingPackage, int subId) { |
| 3248 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3249 | |
| 3250 | final long identity = Binder.clearCallingIdentity(); |
| 3251 | try { |
| 3252 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3253 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3254 | } finally { |
| 3255 | Binder.restoreCallingIdentity(identity); |
| 3256 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3257 | } |
| 3258 | |
| 3259 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3260 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3261 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3262 | |
| 3263 | final long identity = Binder.clearCallingIdentity(); |
| 3264 | try { |
| 3265 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3266 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3267 | } finally { |
| 3268 | Binder.restoreCallingIdentity(identity); |
| 3269 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3270 | } |
| 3271 | |
| 3272 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3273 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3274 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3275 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3276 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3277 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3278 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3279 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3280 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3281 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3282 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3283 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3284 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3285 | * Sets the voice activation state of a given subId. |
| 3286 | */ |
| 3287 | @Override |
| 3288 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3289 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3290 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3291 | |
| 3292 | final long identity = Binder.clearCallingIdentity(); |
| 3293 | try { |
| 3294 | final Phone phone = getPhone(subId); |
| 3295 | if (phone != null) { |
| 3296 | phone.setVoiceActivationState(activationState); |
| 3297 | } else { |
| 3298 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3299 | } |
| 3300 | } finally { |
| 3301 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3302 | } |
| 3303 | } |
| 3304 | |
| 3305 | /** |
| 3306 | * Sets the data activation state of a given subId. |
| 3307 | */ |
| 3308 | @Override |
| 3309 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3310 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3311 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3312 | |
| 3313 | final long identity = Binder.clearCallingIdentity(); |
| 3314 | try { |
| 3315 | final Phone phone = getPhone(subId); |
| 3316 | if (phone != null) { |
| 3317 | phone.setDataActivationState(activationState); |
| 3318 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3319 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3320 | } |
| 3321 | } finally { |
| 3322 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3323 | } |
| 3324 | } |
| 3325 | |
| 3326 | /** |
| 3327 | * Returns the voice activation state of a given subId. |
| 3328 | */ |
| 3329 | @Override |
| 3330 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3331 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3332 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3333 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3334 | final long identity = Binder.clearCallingIdentity(); |
| 3335 | try { |
| 3336 | if (phone != null) { |
| 3337 | return phone.getVoiceActivationState(); |
| 3338 | } else { |
| 3339 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3340 | } |
| 3341 | } finally { |
| 3342 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3343 | } |
| 3344 | } |
| 3345 | |
| 3346 | /** |
| 3347 | * Returns the data activation state of a given subId. |
| 3348 | */ |
| 3349 | @Override |
| 3350 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3351 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3352 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3353 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3354 | final long identity = Binder.clearCallingIdentity(); |
| 3355 | try { |
| 3356 | if (phone != null) { |
| 3357 | return phone.getDataActivationState(); |
| 3358 | } else { |
| 3359 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3360 | } |
| 3361 | } finally { |
| 3362 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3363 | } |
| 3364 | } |
| 3365 | |
| 3366 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3367 | * Returns the unread count of voicemails for a subId |
| 3368 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3369 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3370 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3371 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3372 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3373 | mApp, subId, callingPackage, callingFeatureId, |
| 3374 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3375 | return 0; |
| 3376 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3377 | final long identity = Binder.clearCallingIdentity(); |
| 3378 | try { |
| 3379 | final Phone phone = getPhone(subId); |
| 3380 | if (phone != null) { |
| 3381 | return phone.getVoiceMessageCount(); |
| 3382 | } else { |
| 3383 | return 0; |
| 3384 | } |
| 3385 | } finally { |
| 3386 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3387 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3388 | } |
| 3389 | |
| 3390 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3391 | * returns true, if the device is in a state where both voice and data |
| 3392 | * are supported simultaneously. This can change based on location or network condition. |
| 3393 | */ |
| 3394 | @Override |
| 3395 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3396 | final long identity = Binder.clearCallingIdentity(); |
| 3397 | try { |
| 3398 | final Phone phone = getPhone(subId); |
| 3399 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3400 | } finally { |
| 3401 | Binder.restoreCallingIdentity(identity); |
| 3402 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3403 | } |
| 3404 | |
| 3405 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3406 | * Send the dialer code if called from the current default dialer or the caller has |
| 3407 | * carrier privilege. |
| 3408 | * @param inputCode The dialer code to send |
| 3409 | */ |
| 3410 | @Override |
| 3411 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3412 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3413 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3414 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3415 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3416 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3417 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3418 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3419 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3420 | |
| 3421 | final long identity = Binder.clearCallingIdentity(); |
| 3422 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3423 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3424 | } finally { |
| 3425 | Binder.restoreCallingIdentity(identity); |
| 3426 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3427 | } |
| 3428 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3429 | @Override |
| 3430 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3431 | TelephonyPermissions |
| 3432 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3433 | mApp, subId, "getNetworkSelectionMode"); |
| 3434 | final long identity = Binder.clearCallingIdentity(); |
| 3435 | try { |
| 3436 | if (!isActiveSubscription(subId)) { |
| 3437 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3438 | } |
| 3439 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3440 | } finally { |
| 3441 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3442 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3443 | } |
| 3444 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3445 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3446 | public boolean isInEmergencySmsMode() { |
| 3447 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3448 | final long identity = Binder.clearCallingIdentity(); |
| 3449 | try { |
| 3450 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3451 | if (phone.isInEmergencySmsMode()) { |
| 3452 | return true; |
| 3453 | } |
| 3454 | } |
| 3455 | } finally { |
| 3456 | Binder.restoreCallingIdentity(identity); |
| 3457 | } |
| 3458 | return false; |
| 3459 | } |
| 3460 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3461 | /** |
| 3462 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3463 | * @param subId The subscription to use to check the configuration. |
| 3464 | * @param c The callback that will be used to send the result. |
| 3465 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3466 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3467 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3468 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3469 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3470 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3471 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3472 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3473 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3474 | "IMS not available on device."); |
| 3475 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3476 | final long token = Binder.clearCallingIdentity(); |
| 3477 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3478 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3479 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3480 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3481 | } catch (ImsException e) { |
| 3482 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3483 | } finally { |
| 3484 | Binder.restoreCallingIdentity(token); |
| 3485 | } |
| 3486 | } |
| 3487 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3488 | /** |
| 3489 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3490 | * @param subId The subscription to use to check the configuration. |
| 3491 | * @param c The callback that will be used to send the result. |
| 3492 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3493 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3494 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3495 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3496 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3497 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3498 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3499 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3500 | final long token = Binder.clearCallingIdentity(); |
| 3501 | try { |
| 3502 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3503 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3504 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3505 | } catch (ImsException e) { |
| 3506 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3507 | + "is inactive, ignoring unregister."); |
| 3508 | // If the subscription is no longer active, just return, since the callback |
| 3509 | // will already have been removed internally. |
| 3510 | } finally { |
| 3511 | Binder.restoreCallingIdentity(token); |
| 3512 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3513 | } |
| 3514 | |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3515 | /** |
| 3516 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3517 | */ |
| 3518 | @Override |
| 3519 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3520 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3521 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3522 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3523 | "IMS not available on device."); |
| 3524 | } |
| 3525 | final long token = Binder.clearCallingIdentity(); |
| 3526 | try { |
| 3527 | Phone phone = getPhone(subId); |
| 3528 | if (phone == null) { |
| 3529 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3530 | + subId + "'"); |
| 3531 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3532 | } |
| 3533 | phone.getImsRegistrationState(regState -> { |
| 3534 | try { |
| 3535 | consumer.accept((regState == null) |
| 3536 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3537 | } catch (RemoteException e) { |
| 3538 | // Ignore if the remote process is no longer available to call back. |
| 3539 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3540 | } |
| 3541 | }); |
| 3542 | } finally { |
| 3543 | Binder.restoreCallingIdentity(token); |
| 3544 | } |
| 3545 | } |
| 3546 | |
| 3547 | /** |
| 3548 | * Get the transport type for the IMS service registration state. |
| 3549 | */ |
| 3550 | @Override |
| 3551 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3552 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3553 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3554 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3555 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3556 | "IMS not available on device."); |
| 3557 | } |
| 3558 | final long token = Binder.clearCallingIdentity(); |
| 3559 | try { |
| 3560 | Phone phone = getPhone(subId); |
| 3561 | if (phone == null) { |
| 3562 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3563 | + subId + "'"); |
| 3564 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3565 | } |
| 3566 | phone.getImsRegistrationTech(regTech -> { |
| 3567 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3568 | int regTechConverted = (regTech == null) |
| 3569 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3570 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3571 | regTechConverted); |
| 3572 | try { |
| 3573 | consumer.accept(regTechConverted); |
| 3574 | } catch (RemoteException e) { |
| 3575 | // Ignore if the remote process is no longer available to call back. |
| 3576 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3577 | } |
| 3578 | }); |
| 3579 | } finally { |
| 3580 | Binder.restoreCallingIdentity(token); |
| 3581 | } |
| 3582 | } |
| 3583 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3584 | /** |
| 3585 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3586 | * @param subId The subscription to use to check the configuration. |
| 3587 | * @param c The callback that will be used to send the result. |
| 3588 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3589 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3590 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3591 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3592 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3593 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3594 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3595 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3596 | "IMS not available on device."); |
| 3597 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3598 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3599 | final long token = Binder.clearCallingIdentity(); |
| 3600 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3601 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3602 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3603 | } catch (ImsException e) { |
| 3604 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3605 | } finally { |
| 3606 | Binder.restoreCallingIdentity(token); |
| 3607 | } |
| 3608 | } |
| 3609 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3610 | /** |
| 3611 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3612 | * @param subId The subscription to use to check the configuration. |
| 3613 | * @param c The callback that will be used to send the result. |
| 3614 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3615 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3616 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3617 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3618 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3619 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3620 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3621 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3622 | |
| 3623 | final long token = Binder.clearCallingIdentity(); |
| 3624 | try { |
| 3625 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3626 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3627 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3628 | } catch (ImsException e) { |
| 3629 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3630 | + "is inactive, ignoring unregister."); |
| 3631 | // If the subscription is no longer active, just return, since the callback |
| 3632 | // will already have been removed internally. |
| 3633 | } finally { |
| 3634 | Binder.restoreCallingIdentity(token); |
| 3635 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3636 | } |
| 3637 | |
| 3638 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3639 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3640 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3641 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3642 | final long token = Binder.clearCallingIdentity(); |
| 3643 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3644 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3645 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3646 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3647 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3648 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3649 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3650 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3651 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3652 | } finally { |
| 3653 | Binder.restoreCallingIdentity(token); |
| 3654 | } |
| 3655 | } |
| 3656 | |
| 3657 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3658 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3659 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3660 | final long token = Binder.clearCallingIdentity(); |
| 3661 | try { |
| 3662 | Phone phone = getPhone(subId); |
| 3663 | if (phone == null) return false; |
| 3664 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 32706d9 | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3665 | } catch (com.android.ims.ImsException e) { |
| 3666 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3667 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3668 | } finally { |
| 3669 | Binder.restoreCallingIdentity(token); |
| 3670 | } |
| 3671 | } |
| 3672 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3673 | /** |
| 3674 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3675 | * subscription. |
| 3676 | * @param subId The subscription to use to check the configuration. |
| 3677 | * @param callback The callback that will be used to send the result. |
| 3678 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3679 | * @param transportType The transport type of the MmTelFeature capability. |
| 3680 | */ |
| 3681 | @Override |
| 3682 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3683 | int transportType) { |
| 3684 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3685 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3686 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3687 | "IMS not available on device."); |
| 3688 | } |
| 3689 | final long token = Binder.clearCallingIdentity(); |
| 3690 | try { |
| 3691 | int slotId = getSlotIndex(subId); |
| 3692 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3693 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3694 | + subId + "'"); |
| 3695 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3696 | } |
| 3697 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3698 | transportType, aBoolean -> { |
| 3699 | try { |
| 3700 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3701 | } catch (RemoteException e) { |
| 3702 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3703 | + "running. Ignore"); |
| 3704 | } |
| 3705 | }); |
| 3706 | } finally { |
| 3707 | Binder.restoreCallingIdentity(token); |
| 3708 | } |
| 3709 | } |
| 3710 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3711 | /** |
| 3712 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3713 | * @param subId The subscription to use to check the configuration. |
| 3714 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3715 | @Override |
| 3716 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3717 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3718 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3719 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3720 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3721 | final long token = Binder.clearCallingIdentity(); |
| 3722 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3723 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3724 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3725 | } catch (ImsException e) { |
| 3726 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3727 | } finally { |
| 3728 | Binder.restoreCallingIdentity(token); |
| 3729 | } |
| 3730 | } |
| 3731 | |
| 3732 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3733 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3734 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3735 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3736 | final long identity = Binder.clearCallingIdentity(); |
| 3737 | try { |
| 3738 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3739 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3740 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3741 | } catch (ImsException e) { |
| 3742 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3743 | } finally { |
| 3744 | Binder.restoreCallingIdentity(identity); |
| 3745 | } |
| 3746 | } |
| 3747 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3748 | /** |
| 3749 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3750 | * @param subId The subscription to use to check the configuration. |
| 3751 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3752 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3753 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3754 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3755 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3756 | final long identity = Binder.clearCallingIdentity(); |
| 3757 | try { |
| 3758 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3759 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3760 | } catch (ImsException e) { |
| 3761 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3762 | } finally { |
| 3763 | Binder.restoreCallingIdentity(identity); |
| 3764 | } |
| 3765 | } |
| 3766 | |
| 3767 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3768 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3769 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3770 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3771 | final long identity = Binder.clearCallingIdentity(); |
| 3772 | try { |
| 3773 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3774 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3775 | } catch (ImsException e) { |
| 3776 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3777 | } finally { |
| 3778 | Binder.restoreCallingIdentity(identity); |
| 3779 | } |
| 3780 | } |
| 3781 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3782 | /** |
| 3783 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3784 | * @param subId The subscription to use to check the configuration. |
| 3785 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3786 | @Override |
| 3787 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3788 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3789 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3790 | final long identity = Binder.clearCallingIdentity(); |
| 3791 | try { |
| 3792 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3793 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3794 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3795 | } catch (ImsException e) { |
| 3796 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3797 | } finally { |
| 3798 | Binder.restoreCallingIdentity(identity); |
| 3799 | } |
| 3800 | } |
| 3801 | |
| 3802 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3803 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3804 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3805 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3806 | final long identity = Binder.clearCallingIdentity(); |
| 3807 | try { |
| 3808 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3809 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3810 | } catch (ImsException e) { |
| 3811 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3812 | } finally { |
| 3813 | Binder.restoreCallingIdentity(identity); |
| 3814 | } |
| 3815 | } |
| 3816 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3817 | /** |
| 3818 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3819 | * @param subId The subscription to use to check the configuration. |
| 3820 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3821 | @Override |
| 3822 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3823 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3824 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3825 | final long identity = Binder.clearCallingIdentity(); |
| 3826 | try { |
| 3827 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3828 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3829 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3830 | } catch (ImsException e) { |
| 3831 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3832 | } finally { |
| 3833 | Binder.restoreCallingIdentity(identity); |
| 3834 | } |
| 3835 | } |
| 3836 | |
| 3837 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3838 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3839 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3840 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3841 | final long identity = Binder.clearCallingIdentity(); |
| 3842 | try { |
| 3843 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3844 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3845 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3846 | } catch (ImsException e) { |
| 3847 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3848 | } finally { |
| 3849 | Binder.restoreCallingIdentity(identity); |
| 3850 | } |
| 3851 | } |
| 3852 | |
| 3853 | @Override |
| 3854 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3855 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3856 | "setVoWiFiNonPersistent"); |
| 3857 | final long identity = Binder.clearCallingIdentity(); |
| 3858 | try { |
| 3859 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3860 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3861 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3862 | } catch (ImsException e) { |
| 3863 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3864 | } finally { |
| 3865 | Binder.restoreCallingIdentity(identity); |
| 3866 | } |
| 3867 | } |
| 3868 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3869 | /** |
| 3870 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3871 | * @param subId The subscription to use to check the configuration. |
| 3872 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3873 | @Override |
| 3874 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3875 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3876 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3877 | final long identity = Binder.clearCallingIdentity(); |
| 3878 | try { |
| 3879 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3880 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3881 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3882 | } catch (ImsException e) { |
| 3883 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3884 | } finally { |
| 3885 | Binder.restoreCallingIdentity(identity); |
| 3886 | } |
| 3887 | } |
| 3888 | |
| 3889 | @Override |
| 3890 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3891 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3892 | "setVoWiFiModeSetting"); |
| 3893 | final long identity = Binder.clearCallingIdentity(); |
| 3894 | try { |
| 3895 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3896 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3897 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3898 | } catch (ImsException e) { |
| 3899 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3900 | } finally { |
| 3901 | Binder.restoreCallingIdentity(identity); |
| 3902 | } |
| 3903 | } |
| 3904 | |
| 3905 | @Override |
| 3906 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3907 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3908 | final long identity = Binder.clearCallingIdentity(); |
| 3909 | try { |
| 3910 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3911 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3912 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3913 | } catch (ImsException e) { |
| 3914 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3915 | } finally { |
| 3916 | Binder.restoreCallingIdentity(identity); |
| 3917 | } |
| 3918 | } |
| 3919 | |
| 3920 | @Override |
| 3921 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3922 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3923 | "setVoWiFiRoamingModeSetting"); |
| 3924 | final long identity = Binder.clearCallingIdentity(); |
| 3925 | try { |
| 3926 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3927 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3928 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3929 | } catch (ImsException e) { |
| 3930 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3931 | } finally { |
| 3932 | Binder.restoreCallingIdentity(identity); |
| 3933 | } |
| 3934 | } |
| 3935 | |
| 3936 | @Override |
| 3937 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3938 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3939 | "setRttCapabilityEnabled"); |
| 3940 | final long identity = Binder.clearCallingIdentity(); |
| 3941 | try { |
| 3942 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3943 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3944 | } catch (ImsException e) { |
| 3945 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3946 | } finally { |
| 3947 | Binder.restoreCallingIdentity(identity); |
| 3948 | } |
| 3949 | } |
| 3950 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3951 | /** |
| 3952 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3953 | * @param subId The subscription to use to check the configuration. |
| 3954 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3955 | @Override |
| 3956 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3957 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3958 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3959 | final long identity = Binder.clearCallingIdentity(); |
| 3960 | try { |
| 3961 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3962 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3963 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3964 | } catch (ImsException e) { |
| 3965 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3966 | } finally { |
| 3967 | Binder.restoreCallingIdentity(identity); |
| 3968 | } |
| 3969 | } |
| 3970 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3971 | @Override |
| 3972 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3973 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 3974 | final long identity = Binder.clearCallingIdentity(); |
| 3975 | try { |
Brad Ebinger | 6cf0f65 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 3976 | if (!isImsAvailableOnDevice()) { |
| 3977 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3978 | "IMS not available on device."); |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 3979 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3980 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3981 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3982 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3983 | } catch (ImsException e) { |
| 3984 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3985 | } finally { |
| 3986 | Binder.restoreCallingIdentity(identity); |
| 3987 | } |
| 3988 | } |
| 3989 | |
| 3990 | @Override |
| 3991 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 3992 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 3993 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3994 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3995 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3996 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 3997 | try { |
| 3998 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3999 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4000 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4001 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4002 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4003 | + "is inactive, ignoring unregister."); |
| 4004 | // If the subscription is no longer active, just return, since the callback will already |
| 4005 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4006 | } finally { |
| 4007 | Binder.restoreCallingIdentity(identity); |
| 4008 | } |
| 4009 | } |
| 4010 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4011 | |
| 4012 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4013 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4014 | message); |
| 4015 | } |
| 4016 | |
| 4017 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4018 | boolean isMmtelCapability) { |
| 4019 | Phone phone = getPhone(subId); |
| 4020 | if (phone == null) { |
| 4021 | loge("phone instance null for subid " + subId); |
| 4022 | return false; |
| 4023 | } |
| 4024 | if (isMmtelCapability) { |
| 4025 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4026 | return false; |
| 4027 | } |
| 4028 | } else { |
| 4029 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4030 | return false; |
| 4031 | } |
| 4032 | } |
| 4033 | return true; |
| 4034 | } |
| 4035 | |
| 4036 | @Override |
| 4037 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4038 | boolean isProvisioned) { |
| 4039 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4040 | |
| 4041 | final long identity = Binder.clearCallingIdentity(); |
| 4042 | try { |
| 4043 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4044 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4045 | return; |
| 4046 | } |
| 4047 | |
| 4048 | // this capability requires provisioning, route to the correct API. |
| 4049 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4050 | switch (capability) { |
| 4051 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4052 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4053 | ims.setEabProvisioned(isProvisioned); |
| 4054 | break; |
| 4055 | default: { |
| 4056 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4057 | + "rcs capability '" + capability + "', which does not require " |
| 4058 | + "provisioning."); |
| 4059 | } |
| 4060 | } |
| 4061 | } finally { |
| 4062 | Binder.restoreCallingIdentity(identity); |
| 4063 | } |
| 4064 | |
| 4065 | } |
| 4066 | |
| 4067 | |
| 4068 | @Override |
| 4069 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4070 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4071 | final long identity = Binder.clearCallingIdentity(); |
| 4072 | try { |
| 4073 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4074 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4075 | return true; |
| 4076 | } |
| 4077 | |
| 4078 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4079 | switch (capability) { |
| 4080 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4081 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4082 | return ims.isEabProvisionedOnDevice(); |
| 4083 | |
| 4084 | default: { |
| 4085 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4086 | + "capability '" + capability + "', which does not require " |
| 4087 | + "provisioning."); |
| 4088 | } |
| 4089 | } |
| 4090 | |
| 4091 | } finally { |
| 4092 | Binder.restoreCallingIdentity(identity); |
| 4093 | } |
| 4094 | } |
| 4095 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4096 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4097 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4098 | boolean isProvisioned) { |
| 4099 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4100 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4101 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4102 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4103 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4104 | final long identity = Binder.clearCallingIdentity(); |
| 4105 | try { |
| 4106 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4107 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4108 | return; |
| 4109 | } |
| 4110 | |
| 4111 | // this capability requires provisioning, route to the correct API. |
| 4112 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4113 | switch (capability) { |
| 4114 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4115 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4116 | ims.setVolteProvisioned(isProvisioned); |
| 4117 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4118 | ims.setWfcProvisioned(isProvisioned); |
| 4119 | } |
| 4120 | break; |
| 4121 | } |
| 4122 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4123 | // There is currently no difference in VT provisioning type. |
| 4124 | ims.setVtProvisioned(isProvisioned); |
| 4125 | break; |
| 4126 | } |
| 4127 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4128 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4129 | // change the capability of the feature instead if needed. |
| 4130 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4131 | == isProvisioned) { |
| 4132 | // No change in provisioning. |
| 4133 | return; |
| 4134 | } |
| 4135 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4136 | try { |
| 4137 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4138 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4139 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4140 | + ", Exception" + e.getMessage()); |
| 4141 | } |
| 4142 | break; |
| 4143 | } |
| 4144 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4145 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4146 | + "MmTel capability '" + capability + "', which does not require " |
| 4147 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4148 | } |
| 4149 | } |
| 4150 | |
| 4151 | } finally { |
| 4152 | Binder.restoreCallingIdentity(identity); |
| 4153 | } |
| 4154 | } |
| 4155 | |
| 4156 | @Override |
| 4157 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4158 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4159 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4160 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4161 | } |
| 4162 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4163 | final long identity = Binder.clearCallingIdentity(); |
| 4164 | try { |
| 4165 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4166 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4167 | return true; |
| 4168 | } |
| 4169 | |
| 4170 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4171 | switch (capability) { |
| 4172 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4173 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4174 | return ims.isVolteProvisionedOnDevice(); |
| 4175 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4176 | return ims.isWfcProvisionedOnDevice(); |
| 4177 | } |
| 4178 | // This should never happen, since we are checking tech above to make sure it |
| 4179 | // is either LTE or IWLAN. |
| 4180 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4181 | + "capability."); |
| 4182 | } |
| 4183 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4184 | // There is currently no difference in VT provisioning type. |
| 4185 | return ims.isVtProvisionedOnDevice(); |
| 4186 | } |
| 4187 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4188 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4189 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4190 | } |
| 4191 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4192 | throw new IllegalArgumentException( |
| 4193 | "Tried to get provisioning for MmTel capability '" + capability |
| 4194 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4195 | } |
| 4196 | } |
| 4197 | |
| 4198 | } finally { |
| 4199 | Binder.restoreCallingIdentity(identity); |
| 4200 | } |
| 4201 | } |
| 4202 | |
| 4203 | @Override |
| 4204 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4205 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4206 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4207 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4208 | } |
| 4209 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4210 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4211 | return (provisionedBits & capability) > 0; |
| 4212 | } |
| 4213 | |
| 4214 | @Override |
| 4215 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4216 | boolean isProvisioned) { |
| 4217 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4218 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4219 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4220 | } |
| 4221 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4222 | "setProvisioningStatusForCapability"); |
| 4223 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4224 | // If the current provisioning status for capability already matches isProvisioned, |
| 4225 | // do nothing. |
| 4226 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4227 | return; |
| 4228 | } |
| 4229 | if (isProvisioned) { |
| 4230 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4231 | } else { |
| 4232 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4233 | } |
| 4234 | } |
| 4235 | |
| 4236 | /** |
| 4237 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4238 | * technology. The bitfield should mirror the bitfield defined by |
| 4239 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4240 | */ |
| 4241 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4242 | String key = getMmTelProvisioningKey(subId, tech); |
| 4243 | // Default is no capabilities are provisioned. |
| 4244 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4245 | } |
| 4246 | |
| 4247 | /** |
| 4248 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4249 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4250 | * technology specified. |
| 4251 | * |
| 4252 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4253 | */ |
| 4254 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4255 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4256 | String key = getMmTelProvisioningKey(subId, tech); |
| 4257 | editor.putInt(key, newField); |
| 4258 | editor.commit(); |
| 4259 | } |
| 4260 | |
| 4261 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4262 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4263 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4264 | } |
| 4265 | |
| 4266 | /** |
| 4267 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4268 | * carrier associated with the subscription id. |
| 4269 | */ |
| 4270 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4271 | int capability) { |
| 4272 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4273 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4274 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4275 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4276 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4277 | false); |
| 4278 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4279 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4280 | |
| 4281 | // First check to make sure that the capability requires provisioning. |
| 4282 | switch (capability) { |
| 4283 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4284 | // intentional fallthrough |
| 4285 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4286 | if (requireVoiceVtProvisioning) { |
| 4287 | // Voice and Video requires provisioning |
| 4288 | return true; |
| 4289 | } |
| 4290 | break; |
| 4291 | } |
| 4292 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4293 | if (requireUtProvisioning) { |
| 4294 | // UT requires provisioning |
| 4295 | return true; |
| 4296 | } |
| 4297 | break; |
| 4298 | } |
| 4299 | } |
| 4300 | return false; |
| 4301 | } |
| 4302 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4303 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4304 | int capability) { |
| 4305 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4306 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4307 | |
| 4308 | boolean requireRcsProvisioning = c.getBoolean( |
| 4309 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4310 | |
| 4311 | // First check to make sure that the capability requires provisioning. |
| 4312 | switch (capability) { |
| 4313 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4314 | // intentional fallthrough |
| 4315 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4316 | if (requireRcsProvisioning) { |
| 4317 | // OPTION or PRESENCE requires provisioning |
| 4318 | return true; |
| 4319 | } |
| 4320 | break; |
| 4321 | } |
| 4322 | } |
| 4323 | return false; |
| 4324 | } |
| 4325 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4326 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4327 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4328 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4329 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4330 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4331 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4332 | final long identity = Binder.clearCallingIdentity(); |
| 4333 | try { |
| 4334 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4335 | int slotId = getSlotIndex(subId); |
| 4336 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4337 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4338 | + subId + "' for key:" + key); |
| 4339 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4340 | } |
| 4341 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4342 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4343 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4344 | + subId + "' for key:" + key); |
| 4345 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4346 | } finally { |
| 4347 | Binder.restoreCallingIdentity(identity); |
| 4348 | } |
| 4349 | } |
| 4350 | |
| 4351 | @Override |
| 4352 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4353 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4354 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4355 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4356 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4357 | final long identity = Binder.clearCallingIdentity(); |
| 4358 | try { |
| 4359 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4360 | int slotId = getSlotIndex(subId); |
| 4361 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4362 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4363 | + subId + "' for key:" + key); |
| 4364 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4365 | } |
| 4366 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4367 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4368 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4369 | + subId + "' for key:" + key); |
| 4370 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4371 | } finally { |
| 4372 | Binder.restoreCallingIdentity(identity); |
| 4373 | } |
| 4374 | } |
| 4375 | |
| 4376 | @Override |
| 4377 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4378 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4379 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4380 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4381 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4382 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4383 | final long identity = Binder.clearCallingIdentity(); |
| 4384 | try { |
| 4385 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4386 | int slotId = getSlotIndex(subId); |
| 4387 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4388 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4389 | + subId + "' for key:" + key); |
| 4390 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4391 | } |
| 4392 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4393 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4394 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4395 | + "' for key:" + key); |
| 4396 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4397 | } finally { |
| 4398 | Binder.restoreCallingIdentity(identity); |
| 4399 | } |
| 4400 | } |
| 4401 | |
| 4402 | @Override |
| 4403 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4404 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4405 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4406 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4407 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4408 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4409 | final long identity = Binder.clearCallingIdentity(); |
| 4410 | try { |
| 4411 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4412 | int slotId = getSlotIndex(subId); |
| 4413 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4414 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4415 | + subId + "' for key:" + key); |
| 4416 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4417 | } |
| 4418 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4419 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4420 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4421 | + "' for key:" + key); |
| 4422 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4423 | } finally { |
| 4424 | Binder.restoreCallingIdentity(identity); |
| 4425 | } |
| 4426 | } |
| 4427 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4428 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4429 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4430 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4431 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4432 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4433 | } |
| 4434 | return slotId; |
| 4435 | } |
| 4436 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4437 | private int getSlotIndex(int subId) { |
| 4438 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4439 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4440 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4441 | } |
| 4442 | return slotId; |
| 4443 | } |
| 4444 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4445 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4446 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4447 | */ |
| 4448 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4449 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4450 | String callingFeatureId) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4451 | final int targetSdk = getTargetSdk(callingPackage); |
| 4452 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4453 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4454 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4455 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4456 | mApp, subId, callingPackage, callingFeatureId, |
| 4457 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4458 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4459 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4460 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4461 | final long identity = Binder.clearCallingIdentity(); |
| 4462 | try { |
| 4463 | final Phone phone = getPhone(subId); |
| 4464 | if (phone != null) { |
| 4465 | return phone.getServiceState().getDataNetworkType(); |
| 4466 | } else { |
| 4467 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4468 | } |
| 4469 | } finally { |
| 4470 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4471 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4472 | } |
| 4473 | |
| 4474 | /** |
| 4475 | * Returns the data network type |
| 4476 | */ |
| 4477 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4478 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4479 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4480 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4481 | } |
| 4482 | |
| 4483 | /** |
| 4484 | * Returns the data network type for a subId |
| 4485 | */ |
| 4486 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4487 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4488 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4489 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4490 | mApp, subId, callingPackage, callingFeatureId, |
| 4491 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4492 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4493 | } |
| 4494 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4495 | final long identity = Binder.clearCallingIdentity(); |
| 4496 | try { |
| 4497 | final Phone phone = getPhone(subId); |
| 4498 | if (phone != null) { |
| 4499 | return phone.getServiceState().getDataNetworkType(); |
| 4500 | } else { |
| 4501 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4502 | } |
| 4503 | } finally { |
| 4504 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4505 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4506 | } |
| 4507 | |
| 4508 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4509 | * Returns the Voice network type for a subId |
| 4510 | */ |
| 4511 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4512 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4513 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4514 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4515 | mApp, subId, callingPackage, callingFeatureId, |
| 4516 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4517 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4518 | } |
| 4519 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4520 | final long identity = Binder.clearCallingIdentity(); |
| 4521 | try { |
| 4522 | final Phone phone = getPhone(subId); |
| 4523 | if (phone != null) { |
| 4524 | return phone.getServiceState().getVoiceNetworkType(); |
| 4525 | } else { |
| 4526 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4527 | } |
| 4528 | } finally { |
| 4529 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4530 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4531 | } |
| 4532 | |
| 4533 | /** |
| 4534 | * @return true if a ICC card is present |
| 4535 | */ |
| 4536 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4537 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4538 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4539 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4540 | } |
| 4541 | |
| 4542 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4543 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4544 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4545 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4546 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4547 | final long identity = Binder.clearCallingIdentity(); |
| 4548 | try { |
| 4549 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4550 | if (phone != null) { |
| 4551 | return phone.getIccCard().hasIccCard(); |
| 4552 | } else { |
| 4553 | return false; |
| 4554 | } |
| 4555 | } finally { |
| 4556 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4557 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4558 | } |
| 4559 | |
| 4560 | /** |
| 4561 | * Return if the current radio is LTE on CDMA. This |
| 4562 | * is a tri-state return value as for a period of time |
| 4563 | * the mode may be unknown. |
| 4564 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4565 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4566 | * @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] | 4567 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4568 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4569 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4570 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4571 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4572 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4573 | } |
| 4574 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4575 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4576 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4577 | String callingFeatureId) { |
Sarah Chin | f6656a6 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4578 | try { |
| 4579 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4580 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4581 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4582 | } |
| 4583 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4584 | final long identity = Binder.clearCallingIdentity(); |
| 4585 | try { |
| 4586 | final Phone phone = getPhone(subId); |
| 4587 | if (phone == null) { |
| 4588 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4589 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 4590 | return TelephonyProperties.lte_on_cdma_device() |
| 4591 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4592 | } |
| 4593 | } finally { |
| 4594 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4595 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4596 | } |
| 4597 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4598 | /** |
| 4599 | * {@hide} |
| 4600 | * Returns Default subId, 0 in the case of single standby. |
| 4601 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4602 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4603 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4604 | } |
| 4605 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4606 | private int getSlotForDefaultSubscription() { |
| 4607 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4608 | } |
| 4609 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4610 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4611 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4612 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4613 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4614 | private boolean isActiveSubscription(int subId) { |
| 4615 | return mSubscriptionController.isActiveSubId(subId); |
| 4616 | } |
| 4617 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4618 | /** |
| 4619 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4620 | */ |
| 4621 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4622 | final long identity = Binder.clearCallingIdentity(); |
| 4623 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4624 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4625 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4626 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4627 | } finally { |
| 4628 | Binder.restoreCallingIdentity(identity); |
| 4629 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4630 | } |
| 4631 | |
| 4632 | /** |
| 4633 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4634 | */ |
| 4635 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4636 | final long identity = Binder.clearCallingIdentity(); |
| 4637 | try { |
| 4638 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4639 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4640 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4641 | } finally { |
| 4642 | Binder.restoreCallingIdentity(identity); |
| 4643 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4644 | } |
| 4645 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4646 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4647 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4648 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4649 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4650 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4651 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4652 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4653 | if (phoneId == -1) { |
| 4654 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4655 | + " does not correspond to an active phone"); |
| 4656 | } |
| 4657 | return PhoneFactory.getPhone(phoneId); |
| 4658 | } |
| 4659 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4660 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4661 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4662 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4663 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4664 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4665 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4666 | if (DBG) { |
| 4667 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4668 | } |
| 4669 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4670 | p2); |
| 4671 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4672 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4673 | |
| 4674 | @Override |
| 4675 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4676 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4677 | enforceModifyPermission(); |
| 4678 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4679 | if (DBG) { |
| 4680 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4681 | } |
| 4682 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4683 | callingPackage, aid, p2); |
| 4684 | } |
| 4685 | |
| 4686 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4687 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4688 | final long identity = Binder.clearCallingIdentity(); |
| 4689 | try { |
| 4690 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4691 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4692 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4693 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4694 | if (bestComponent == null |
| 4695 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4696 | loge("The calling package is not allowed to access ISD-R."); |
| 4697 | throw new SecurityException( |
| 4698 | "The calling package is not allowed to access ISD-R."); |
| 4699 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4700 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4701 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4702 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4703 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4704 | null /* workSource */); |
| 4705 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4706 | return response; |
| 4707 | } finally { |
| 4708 | Binder.restoreCallingIdentity(identity); |
| 4709 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4710 | } |
| 4711 | |
| 4712 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4713 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4714 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4715 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4716 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4717 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4718 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4719 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4720 | @Override |
| 4721 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4722 | enforceModifyPermission(); |
| 4723 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4724 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4725 | channel); |
| 4726 | } |
| 4727 | |
| 4728 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4729 | final long identity = Binder.clearCallingIdentity(); |
| 4730 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4731 | if (channel < 0) { |
| 4732 | return false; |
| 4733 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4734 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4735 | null /* workSource */); |
| 4736 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4737 | return success; |
| 4738 | } finally { |
| 4739 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4740 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4741 | } |
| 4742 | |
| 4743 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4744 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4745 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4746 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4747 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4748 | if (DBG) { |
| 4749 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4750 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4751 | + p3 + " data=" + data); |
| 4752 | } |
| 4753 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4754 | command, p1, p2, p3, data); |
| 4755 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4756 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4757 | @Override |
| 4758 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4759 | int command, int p1, int p2, int p3, String data) { |
| 4760 | enforceModifyPermission(); |
| 4761 | if (DBG) { |
| 4762 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4763 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4764 | + p3 + " data=" + data); |
| 4765 | } |
| 4766 | return iccTransmitApduLogicalChannelWithPermission( |
| 4767 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4768 | data); |
| 4769 | } |
| 4770 | |
| 4771 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4772 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4773 | final long identity = Binder.clearCallingIdentity(); |
| 4774 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4775 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4776 | return ""; |
| 4777 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4778 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4779 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4780 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4781 | null /* workSource */); |
| 4782 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4783 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4784 | // Append the returned status code to the end of the response payload. |
| 4785 | String s = Integer.toHexString( |
| 4786 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4787 | if (response.payload != null) { |
| 4788 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4789 | } |
| 4790 | return s; |
| 4791 | } finally { |
| 4792 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4793 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4794 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4795 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4796 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4797 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4798 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4799 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4800 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4801 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4802 | if (DBG) { |
| 4803 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4804 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4805 | } |
| 4806 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4807 | cla, command, p1, p2, p3, data); |
| 4808 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4809 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4810 | @Override |
| 4811 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4812 | int command, int p1, int p2, int p3, String data) { |
| 4813 | enforceModifyPermission(); |
| 4814 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4815 | if (DBG) { |
| 4816 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4817 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4818 | + " data=" + data); |
| 4819 | } |
| 4820 | |
| 4821 | return iccTransmitApduBasicChannelWithPermission( |
| 4822 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4823 | p2, p3, data); |
| 4824 | } |
| 4825 | |
| 4826 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4827 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4828 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4829 | final long identity = Binder.clearCallingIdentity(); |
| 4830 | try { |
| 4831 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4832 | && TextUtils.equals(ISDR_AID, data)) { |
| 4833 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4834 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4835 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4836 | if (bestComponent == null |
| 4837 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4838 | loge("The calling package is not allowed to select ISD-R."); |
| 4839 | throw new SecurityException( |
| 4840 | "The calling package is not allowed to select ISD-R."); |
| 4841 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4842 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4843 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4844 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4845 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4846 | null /* workSource */); |
| 4847 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4848 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4849 | // Append the returned status code to the end of the response payload. |
| 4850 | String s = Integer.toHexString( |
| 4851 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4852 | if (response.payload != null) { |
| 4853 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4854 | } |
| 4855 | return s; |
| 4856 | } finally { |
| 4857 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4858 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4859 | } |
| 4860 | |
| 4861 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4862 | 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] | 4863 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4864 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4865 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4866 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4867 | final long identity = Binder.clearCallingIdentity(); |
| 4868 | try { |
| 4869 | if (DBG) { |
| 4870 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4871 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4872 | } |
| 4873 | |
| 4874 | IccIoResult response = |
| 4875 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4876 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4877 | subId); |
| 4878 | |
| 4879 | if (DBG) { |
| 4880 | log("Exchange SIM_IO [R]" + response); |
| 4881 | } |
| 4882 | |
| 4883 | byte[] result = null; |
| 4884 | int length = 2; |
| 4885 | if (response.payload != null) { |
| 4886 | length = 2 + response.payload.length; |
| 4887 | result = new byte[length]; |
| 4888 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4889 | } else { |
| 4890 | result = new byte[length]; |
| 4891 | } |
| 4892 | |
| 4893 | result[length - 1] = (byte) response.sw2; |
| 4894 | result[length - 2] = (byte) response.sw1; |
| 4895 | return result; |
| 4896 | } finally { |
| 4897 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4898 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4899 | } |
| 4900 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4901 | /** |
| 4902 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4903 | * on a particular subscription |
| 4904 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4905 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 4906 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4907 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4908 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4909 | return null; |
| 4910 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4911 | |
| 4912 | final long identity = Binder.clearCallingIdentity(); |
| 4913 | try { |
| 4914 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4915 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4916 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4917 | return null; |
| 4918 | } |
| 4919 | Object response = sendRequest( |
| 4920 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4921 | if (response instanceof String[]) { |
| 4922 | return (String[]) response; |
| 4923 | } |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4924 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4925 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4926 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4927 | } finally { |
| 4928 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4929 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4930 | } |
| 4931 | |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4932 | /** |
| 4933 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 4934 | * subscription. |
| 4935 | * |
| 4936 | * @param subId the id of the subscription. |
| 4937 | * @param appType the uicc app type, must be USIM or SIM. |
| 4938 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 4939 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4940 | * @param callingFeatureId the feature in the package. |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4941 | * @return number of fplmns that is successfully written to the SIM. |
| 4942 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4943 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 4944 | String callingFeatureId) { |
| 4945 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 4946 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4947 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 4948 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 4949 | } |
| 4950 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 4951 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4952 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 4953 | } |
| 4954 | if (fplmns == null) { |
| 4955 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 4956 | } |
| 4957 | for (String fplmn : fplmns) { |
| 4958 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 4959 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 4960 | } |
| 4961 | } |
| 4962 | final long identity = Binder.clearCallingIdentity(); |
| 4963 | try { |
| 4964 | Object response = sendRequest( |
| 4965 | CMD_SET_FORBIDDEN_PLMNS, |
| 4966 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 4967 | subId); |
| 4968 | return (int) response; |
| 4969 | } finally { |
| 4970 | Binder.restoreCallingIdentity(identity); |
| 4971 | } |
| 4972 | } |
| 4973 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4974 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4975 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4976 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4977 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4978 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4979 | final long identity = Binder.clearCallingIdentity(); |
| 4980 | try { |
| 4981 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 4982 | if (response.payload == null) { |
| 4983 | return ""; |
| 4984 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4985 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4986 | // Append the returned status code to the end of the response payload. |
| 4987 | String s = Integer.toHexString( |
| 4988 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4989 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4990 | return s; |
| 4991 | } finally { |
| 4992 | Binder.restoreCallingIdentity(identity); |
| 4993 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4994 | } |
| 4995 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4996 | /** |
| 4997 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 4998 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 4999 | * |
| 5000 | * @param itemID the ID of the item to read |
| 5001 | * @return the NV item as a String, or null on error. |
| 5002 | */ |
| 5003 | @Override |
| 5004 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5005 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5006 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5007 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5008 | |
| 5009 | final long identity = Binder.clearCallingIdentity(); |
| 5010 | try { |
| 5011 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5012 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5013 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5014 | return value; |
| 5015 | } finally { |
| 5016 | Binder.restoreCallingIdentity(identity); |
| 5017 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5018 | } |
| 5019 | |
| 5020 | /** |
| 5021 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5022 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5023 | * |
| 5024 | * @param itemID the ID of the item to read |
| 5025 | * @param itemValue the value to write, as a String |
| 5026 | * @return true on success; false on any failure |
| 5027 | */ |
| 5028 | @Override |
| 5029 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5030 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5031 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5032 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5033 | |
| 5034 | final long identity = Binder.clearCallingIdentity(); |
| 5035 | try { |
| 5036 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5037 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5038 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5039 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5040 | return success; |
| 5041 | } finally { |
| 5042 | Binder.restoreCallingIdentity(identity); |
| 5043 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5044 | } |
| 5045 | |
| 5046 | /** |
| 5047 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5048 | * Used for device configuration by some CDMA operators. |
| 5049 | * |
| 5050 | * @param preferredRoamingList byte array containing the new PRL |
| 5051 | * @return true on success; false on any failure |
| 5052 | */ |
| 5053 | @Override |
| 5054 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5055 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5056 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5057 | |
| 5058 | final long identity = Binder.clearCallingIdentity(); |
| 5059 | try { |
| 5060 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5061 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5062 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5063 | return success; |
| 5064 | } finally { |
| 5065 | Binder.restoreCallingIdentity(identity); |
| 5066 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5067 | } |
| 5068 | |
| 5069 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5070 | * 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] | 5071 | * Used for device configuration by some CDMA operators. |
| 5072 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5073 | * @param slotIndex - device slot. |
| 5074 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5075 | * @return true on success; false on any failure |
| 5076 | */ |
| 5077 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5078 | public boolean resetModemConfig(int slotIndex) { |
| 5079 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5080 | if (phone != null) { |
| 5081 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5082 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5083 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5084 | final long identity = Binder.clearCallingIdentity(); |
| 5085 | try { |
| 5086 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5087 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5088 | return success; |
| 5089 | } finally { |
| 5090 | Binder.restoreCallingIdentity(identity); |
| 5091 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5092 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5093 | return false; |
| 5094 | } |
| 5095 | |
| 5096 | /** |
| 5097 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5098 | * |
| 5099 | * @param slotIndex - device slot. |
| 5100 | * |
| 5101 | * @return true on success; false on any failure |
| 5102 | */ |
| 5103 | @Override |
| 5104 | public boolean rebootModem(int slotIndex) { |
| 5105 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5106 | if (phone != null) { |
| 5107 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5108 | mApp, phone.getSubId(), "rebootModem"); |
| 5109 | |
| 5110 | final long identity = Binder.clearCallingIdentity(); |
| 5111 | try { |
| 5112 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5113 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5114 | return success; |
| 5115 | } finally { |
| 5116 | Binder.restoreCallingIdentity(identity); |
| 5117 | } |
| 5118 | } |
| 5119 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5120 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5121 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5122 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5123 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5124 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5125 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5126 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5127 | return new String[0]; |
| 5128 | } |
| 5129 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5130 | final long identity = Binder.clearCallingIdentity(); |
| 5131 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5132 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5133 | } finally { |
| 5134 | Binder.restoreCallingIdentity(identity); |
| 5135 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5136 | } |
| 5137 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5138 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5139 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5140 | * {@link #disableIms(int)}. |
| 5141 | * @param slotIndex device slot. |
| 5142 | */ |
| 5143 | public void resetIms(int slotIndex) { |
| 5144 | enforceModifyPermission(); |
| 5145 | |
| 5146 | final long identity = Binder.clearCallingIdentity(); |
| 5147 | try { |
| 5148 | if (mImsResolver == null) { |
| 5149 | // may happen if the does not support IMS. |
| 5150 | return; |
| 5151 | } |
| 5152 | mImsResolver.disableIms(slotIndex); |
| 5153 | mImsResolver.enableIms(slotIndex); |
| 5154 | } finally { |
| 5155 | Binder.restoreCallingIdentity(identity); |
| 5156 | } |
| 5157 | } |
| 5158 | |
| 5159 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5160 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5161 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5162 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5163 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5164 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5165 | |
| 5166 | final long identity = Binder.clearCallingIdentity(); |
| 5167 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5168 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5169 | // may happen if the device does not support IMS. |
| 5170 | return; |
| 5171 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5172 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5173 | } finally { |
| 5174 | Binder.restoreCallingIdentity(identity); |
| 5175 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5176 | } |
| 5177 | |
| 5178 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5179 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5180 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5181 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5182 | public void disableIms(int slotId) { |
| 5183 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5184 | |
| 5185 | final long identity = Binder.clearCallingIdentity(); |
| 5186 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5187 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5188 | // may happen if the device does not support IMS. |
| 5189 | return; |
| 5190 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5191 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5192 | } finally { |
| 5193 | Binder.restoreCallingIdentity(identity); |
| 5194 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5195 | } |
| 5196 | |
| 5197 | /** |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5198 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5199 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5200 | */ |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5201 | @Override |
Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5202 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5203 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5204 | |
| 5205 | final long identity = Binder.clearCallingIdentity(); |
| 5206 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5207 | if (mImsResolver == null) { |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5208 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5209 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5210 | } |
Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5211 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5212 | } finally { |
| 5213 | Binder.restoreCallingIdentity(identity); |
| 5214 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5215 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5216 | /** |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5217 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5218 | */ |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5219 | @Override |
| 5220 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5221 | enforceModifyPermission(); |
| 5222 | |
| 5223 | final long identity = Binder.clearCallingIdentity(); |
| 5224 | try { |
| 5225 | if (mImsResolver == null) return; |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5226 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5227 | } finally { |
| 5228 | Binder.restoreCallingIdentity(identity); |
| 5229 | } |
| 5230 | } |
| 5231 | |
| 5232 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5233 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5234 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5235 | */ |
| 5236 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5237 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5238 | |
| 5239 | final long identity = Binder.clearCallingIdentity(); |
| 5240 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5241 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5242 | // may happen if the device does not support IMS. |
| 5243 | return null; |
| 5244 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5245 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5246 | } finally { |
| 5247 | Binder.restoreCallingIdentity(identity); |
| 5248 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5249 | } |
| 5250 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5251 | /** |
| 5252 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5253 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5254 | */ |
| 5255 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5256 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5257 | |
| 5258 | final long identity = Binder.clearCallingIdentity(); |
| 5259 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5260 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5261 | // may happen if the device does not support IMS. |
| 5262 | return null; |
| 5263 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5264 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5265 | } finally { |
| 5266 | Binder.restoreCallingIdentity(identity); |
| 5267 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5268 | } |
| 5269 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5270 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5271 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5272 | * |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5273 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5274 | * @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] | 5275 | * ImsService is the device default ImsService. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5276 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5277 | * @param packageName The name of the package that the current configuration will be replaced |
| 5278 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5279 | * @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] | 5280 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5281 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5282 | int[] featureTypes, String packageName) { |
| 5283 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5284 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5285 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5286 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5287 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5288 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5289 | final long identity = Binder.clearCallingIdentity(); |
| 5290 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5291 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5292 | // may happen if the device does not support IMS. |
| 5293 | return false; |
| 5294 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5295 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5296 | for (int featureType : featureTypes) { |
| 5297 | featureConfig.put(featureType, packageName); |
| 5298 | } |
| 5299 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5300 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5301 | } finally { |
| 5302 | Binder.restoreCallingIdentity(identity); |
| 5303 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5304 | } |
| 5305 | |
| 5306 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5307 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5308 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5309 | * |
| 5310 | * This should only be used for testing. |
| 5311 | * |
| 5312 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5313 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5314 | */ |
| 5315 | @Override |
| 5316 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5317 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5318 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5319 | "clearCarrierImsServiceOverride"); |
| 5320 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5321 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5322 | "clearCarrierImsServiceOverride"); |
| 5323 | |
| 5324 | final long identity = Binder.clearCallingIdentity(); |
| 5325 | try { |
| 5326 | if (mImsResolver == null) { |
| 5327 | // may happen if the device does not support IMS. |
| 5328 | return false; |
| 5329 | } |
| 5330 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5331 | } finally { |
| 5332 | Binder.restoreCallingIdentity(identity); |
| 5333 | } |
| 5334 | } |
| 5335 | |
| 5336 | /** |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5337 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5338 | * |
| 5339 | * @param slotId The slot that the ImsService is associated with. |
| 5340 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5341 | * the device default. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5342 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5343 | * @return the package name of the ImsService configuration. |
| 5344 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5345 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5346 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5347 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5348 | TelephonyPermissions |
| 5349 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5350 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5351 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5352 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5353 | final long identity = Binder.clearCallingIdentity(); |
| 5354 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5355 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5356 | // may happen if the device does not support IMS. |
| 5357 | return ""; |
| 5358 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5359 | // TODO: change API to query RCS separately. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5360 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5361 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5362 | } finally { |
| 5363 | Binder.restoreCallingIdentity(identity); |
| 5364 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5365 | } |
| 5366 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5367 | /** |
| 5368 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5369 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5370 | * @param callback A callback with an integer containing the |
| 5371 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5372 | */ |
| 5373 | @Override |
| 5374 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5375 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5376 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5377 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5378 | "IMS not available on device."); |
| 5379 | } |
| 5380 | final long token = Binder.clearCallingIdentity(); |
| 5381 | try { |
| 5382 | int slotId = getSlotIndex(subId); |
| 5383 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5384 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5385 | + subId + "'"); |
| 5386 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5387 | } |
| 5388 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5389 | try { |
| 5390 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5391 | } catch (RemoteException e) { |
| 5392 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5393 | + "Ignore"); |
| 5394 | } |
| 5395 | }); |
| 5396 | } finally { |
| 5397 | Binder.restoreCallingIdentity(token); |
| 5398 | } |
| 5399 | } |
| 5400 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5401 | public void setImsRegistrationState(boolean registered) { |
| 5402 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5403 | |
| 5404 | final long identity = Binder.clearCallingIdentity(); |
| 5405 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5406 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5407 | } finally { |
| 5408 | Binder.restoreCallingIdentity(identity); |
| 5409 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5410 | } |
| 5411 | |
| 5412 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5413 | * Set the network selection mode to automatic. |
| 5414 | * |
| 5415 | */ |
| 5416 | @Override |
| 5417 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5418 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5419 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5420 | |
| 5421 | final long identity = Binder.clearCallingIdentity(); |
| 5422 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5423 | if (!isActiveSubscription(subId)) { |
| 5424 | return; |
| 5425 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5426 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 5427 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 5428 | } finally { |
| 5429 | Binder.restoreCallingIdentity(identity); |
| 5430 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5431 | } |
| 5432 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5433 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5434 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5435 | * |
| 5436 | * @param subId the id of the subscription. |
| 5437 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5438 | * the operator to attach to. |
| 5439 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5440 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5441 | * normal network selection next time. |
| 5442 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5443 | */ |
| 5444 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5445 | public boolean setNetworkSelectionModeManual( |
| 5446 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5447 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5448 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5449 | |
| 5450 | if (!isActiveSubscription(subId)) { |
| 5451 | return false; |
| 5452 | } |
| 5453 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5454 | final long identity = Binder.clearCallingIdentity(); |
| 5455 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5456 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5457 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5458 | if (DBG) { |
| 5459 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5460 | + " operator: " + operatorInfo); |
| 5461 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5462 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5463 | } finally { |
| 5464 | Binder.restoreCallingIdentity(identity); |
| 5465 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5466 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5467 | /** |
| 5468 | * Get the manual network selection |
| 5469 | * |
| 5470 | * @param subId the id of the subscription. |
| 5471 | * |
| 5472 | * @return the previously saved user selected PLMN |
| 5473 | */ |
| 5474 | @Override |
| 5475 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5476 | TelephonyPermissions |
| 5477 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5478 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5479 | |
| 5480 | final long identity = Binder.clearCallingIdentity(); |
| 5481 | try { |
| 5482 | if (!isActiveSubscription(subId)) { |
| 5483 | return ""; |
| 5484 | } |
| 5485 | |
| 5486 | final Phone phone = getPhone(subId); |
| 5487 | if (phone == null) { |
| 5488 | return ""; |
| 5489 | } |
| 5490 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5491 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5492 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5493 | } finally { |
| 5494 | Binder.restoreCallingIdentity(identity); |
| 5495 | } |
| 5496 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5497 | |
| 5498 | /** |
| 5499 | * Scans for available networks. |
| 5500 | */ |
| 5501 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5502 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5503 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5504 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5505 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5506 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5507 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5508 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5509 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5510 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5511 | .setCallingPid(Binder.getCallingPid()) |
| 5512 | .setCallingUid(Binder.getCallingUid()) |
| 5513 | .setMethod("getCellNetworkScanResults") |
| 5514 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5515 | .build()); |
| 5516 | switch (locationResult) { |
| 5517 | case DENIED_HARD: |
| 5518 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5519 | case DENIED_SOFT: |
| 5520 | return null; |
| 5521 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5522 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5523 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5524 | try { |
| 5525 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5526 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5527 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5528 | } finally { |
| 5529 | Binder.restoreCallingIdentity(identity); |
| 5530 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5531 | } |
| 5532 | |
| 5533 | /** |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5534 | * Get the call forwarding info, given the call forwarding reason. |
| 5535 | */ |
| 5536 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5537 | public void getCallForwarding(int subId, int callForwardingReason, |
| 5538 | ICallForwardingInfoCallback callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5539 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5540 | long identity = Binder.clearCallingIdentity(); |
| 5541 | try { |
| 5542 | if (DBG) { |
| 5543 | log("getCallForwarding: subId " + subId |
| 5544 | + " callForwardingReason" + callForwardingReason); |
| 5545 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5546 | |
| 5547 | Phone phone = getPhone(subId); |
| 5548 | if (phone == null) { |
| 5549 | try { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5550 | callback.onError( |
| 5551 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5552 | } catch (RemoteException e) { |
| 5553 | // ignore |
| 5554 | } |
| 5555 | return; |
| 5556 | } |
| 5557 | |
| 5558 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 5559 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 5560 | @Override |
| 5561 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 5562 | try { |
| 5563 | callback.onCallForwardingInfoAvailable(info); |
| 5564 | } catch (RemoteException e) { |
| 5565 | // ignore |
| 5566 | } |
| 5567 | } |
| 5568 | |
| 5569 | @Override |
| 5570 | public void onError(int error) { |
| 5571 | try { |
| 5572 | callback.onError(error); |
| 5573 | } catch (RemoteException e) { |
| 5574 | // ignore |
| 5575 | } |
| 5576 | } |
| 5577 | }); |
| 5578 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5579 | } finally { |
| 5580 | Binder.restoreCallingIdentity(identity); |
| 5581 | } |
| 5582 | } |
| 5583 | |
| 5584 | /** |
| 5585 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5586 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5587 | */ |
| 5588 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5589 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 5590 | IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5591 | enforceModifyPermission(); |
| 5592 | long identity = Binder.clearCallingIdentity(); |
| 5593 | try { |
| 5594 | if (DBG) { |
| 5595 | log("setCallForwarding: subId " + subId |
| 5596 | + " callForwardingInfo" + callForwardingInfo); |
| 5597 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5598 | |
| 5599 | Phone phone = getPhone(subId); |
| 5600 | if (phone == null) { |
| 5601 | try { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5602 | callback.accept( |
| 5603 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5604 | } catch (RemoteException e) { |
| 5605 | // ignore |
| 5606 | } |
| 5607 | return; |
| 5608 | } |
| 5609 | |
| 5610 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 5611 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5612 | |
| 5613 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5614 | } finally { |
| 5615 | Binder.restoreCallingIdentity(identity); |
| 5616 | } |
| 5617 | } |
| 5618 | |
| 5619 | /** |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5620 | * Get the call waiting status for a subId. |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5621 | */ |
| 5622 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5623 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5624 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5625 | long identity = Binder.clearCallingIdentity(); |
| 5626 | try { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5627 | |
| 5628 | Phone phone = getPhone(subId); |
| 5629 | if (phone == null) { |
| 5630 | try { |
| 5631 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5632 | } catch (RemoteException e) { |
| 5633 | // ignore |
| 5634 | } |
| 5635 | return; |
| 5636 | } |
| 5637 | |
| 5638 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 5639 | |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5640 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5641 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5642 | } finally { |
| 5643 | Binder.restoreCallingIdentity(identity); |
| 5644 | } |
| 5645 | } |
| 5646 | |
| 5647 | /** |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5648 | * Sets whether call waiting is enabled for a given subId. |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5649 | */ |
| 5650 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5651 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5652 | enforceModifyPermission(); |
| 5653 | long identity = Binder.clearCallingIdentity(); |
| 5654 | try { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5655 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 5656 | |
| 5657 | Phone phone = getPhone(subId); |
| 5658 | if (phone == null) { |
| 5659 | try { |
| 5660 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5661 | } catch (RemoteException e) { |
| 5662 | // ignore |
| 5663 | } |
| 5664 | return; |
| 5665 | } |
| 5666 | |
| 5667 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 5668 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5669 | |
| 5670 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5671 | } finally { |
| 5672 | Binder.restoreCallingIdentity(identity); |
| 5673 | } |
| 5674 | } |
| 5675 | |
| 5676 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5677 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5678 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5679 | * @param subId id of the subscription |
| 5680 | * @param request contains the radio access networks with bands/channels to scan |
| 5681 | * @param messenger callback messenger for scan results or errors |
| 5682 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5683 | * @return the id of the requested scan which can be used to stop the scan. |
| 5684 | */ |
| 5685 | @Override |
| 5686 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5687 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5688 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5689 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5690 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5691 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5692 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5693 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5694 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5695 | .setCallingPid(Binder.getCallingPid()) |
| 5696 | .setCallingUid(Binder.getCallingUid()) |
| 5697 | .setMethod("requestNetworkScan") |
| 5698 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5699 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5700 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 284aa04 | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5701 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 5702 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5703 | if (e != null) { |
| 5704 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5705 | throw e; |
| 5706 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5707 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5708 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5709 | } |
| 5710 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5711 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5712 | int callingUid = Binder.getCallingUid(); |
| 5713 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5714 | final long identity = Binder.clearCallingIdentity(); |
| 5715 | try { |
| 5716 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5717 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5718 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5719 | } finally { |
| 5720 | Binder.restoreCallingIdentity(identity); |
| 5721 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5722 | } |
| 5723 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5724 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 284aa04 | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5725 | NetworkScanRequest request, int subId, String callingPackage) { |
| 5726 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5727 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5728 | boolean hasNetworkScanPermission = |
| 5729 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5730 | == PERMISSION_GRANTED; |
| 5731 | |
| 5732 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5733 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5734 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5735 | } |
| 5736 | |
| 5737 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5738 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5739 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5740 | return new SecurityException("Specific channels must not be" |
| 5741 | + " scanned without location access."); |
| 5742 | } |
| 5743 | } |
| 5744 | } |
| 5745 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5746 | return null; |
| 5747 | } |
| 5748 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5749 | /** |
| 5750 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5751 | * |
| 5752 | * @param subId id of the subscription |
| 5753 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5754 | */ |
| 5755 | @Override |
| 5756 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5757 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5758 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5759 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5760 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5761 | final long identity = Binder.clearCallingIdentity(); |
| 5762 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5763 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5764 | } finally { |
| 5765 | Binder.restoreCallingIdentity(identity); |
| 5766 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5767 | } |
| 5768 | |
| 5769 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5770 | * Get the calculated preferred network type. |
| 5771 | * Used for debugging incorrect network type. |
| 5772 | * |
| 5773 | * @return the preferred network type, defined in RILConstants.java. |
| 5774 | */ |
| 5775 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5776 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5777 | final Phone defaultPhone = getDefaultPhone(); |
| 5778 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5779 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5780 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5781 | } |
| 5782 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5783 | final long identity = Binder.clearCallingIdentity(); |
| 5784 | try { |
| 5785 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5786 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5787 | } finally { |
| 5788 | Binder.restoreCallingIdentity(identity); |
| 5789 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5790 | } |
| 5791 | |
| 5792 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5793 | * Get the preferred network type. |
| 5794 | * Used for device configuration by some CDMA operators. |
| 5795 | * |
| 5796 | * @return the preferred network type, defined in RILConstants.java. |
| 5797 | */ |
| 5798 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5799 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5800 | TelephonyPermissions |
| 5801 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5802 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5803 | |
| 5804 | final long identity = Binder.clearCallingIdentity(); |
| 5805 | try { |
| 5806 | if (DBG) log("getPreferredNetworkType"); |
| 5807 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5808 | int networkType = (result != null ? result[0] : -1); |
| 5809 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5810 | return networkType; |
| 5811 | } finally { |
| 5812 | Binder.restoreCallingIdentity(identity); |
| 5813 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5814 | } |
| 5815 | |
| 5816 | /** |
| 5817 | * Set the preferred network type. |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5818 | * |
| 5819 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5820 | * @return true on success; false on any failure. |
| 5821 | */ |
| 5822 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5823 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5824 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5825 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5826 | |
| 5827 | final long identity = Binder.clearCallingIdentity(); |
| 5828 | try { |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5829 | Settings.Global.putInt(mApp.getContentResolver(), |
| 5830 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5831 | |
| 5832 | Boolean success = (Boolean) sendRequest( |
| 5833 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 5834 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 5835 | return success; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5836 | } finally { |
| 5837 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5838 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5839 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5840 | |
| 5841 | /** |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5842 | * Get the allowed network types that store in the telephony provider. |
| 5843 | * |
| 5844 | * @param subId the id of the subscription. |
| 5845 | * @return allowedNetworkTypes the allowed network types. |
| 5846 | */ |
| 5847 | @Override |
| 5848 | public long getAllowedNetworkTypes(int subId) { |
| 5849 | TelephonyPermissions |
| 5850 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5851 | mApp, subId, "getAllowedNetworkTypes"); |
| 5852 | |
| 5853 | final long identity = Binder.clearCallingIdentity(); |
| 5854 | try { |
| 5855 | return SubscriptionManager.getLongSubscriptionProperty( |
| 5856 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5857 | } finally { |
| 5858 | Binder.restoreCallingIdentity(identity); |
| 5859 | } |
| 5860 | } |
| 5861 | |
| 5862 | /** |
| 5863 | * Set the allowed network types. |
| 5864 | * |
| 5865 | * @param subId the id of the subscription. |
| 5866 | * @param allowedNetworkTypes the allowed network types. |
| 5867 | * @return true on success; false on any failure. |
| 5868 | */ |
| 5869 | @Override |
| 5870 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 5871 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5872 | mApp, subId, "setAllowedNetworkTypes"); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5873 | |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5874 | SubscriptionManager.setSubscriptionProperty(subId, |
| 5875 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 5876 | String.valueOf(allowedNetworkTypes)); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5877 | |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5878 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 5879 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5880 | RILConstants.PREFERRED_NETWORK_MODE); |
| 5881 | return setPreferredNetworkType(subId, preferredNetworkMode); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5882 | } |
| 5883 | |
| 5884 | /** |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 5885 | * Get the allowed network types for certain reason. |
| 5886 | * |
| 5887 | * @param subId the id of the subscription. |
| 5888 | * @param reason the reason the allowed network type change is taking place |
| 5889 | * @return the allowed network types. |
| 5890 | */ |
| 5891 | @Override |
| 5892 | public long getAllowedNetworkTypesForReason(int subId, |
| 5893 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
| 5894 | TelephonyPermissions |
| 5895 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5896 | mApp, subId, "getAllowedNetworkTypesForReason"); |
| 5897 | final long identity = Binder.clearCallingIdentity(); |
| 5898 | try { |
| 5899 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 5900 | } finally { |
| 5901 | Binder.restoreCallingIdentity(identity); |
| 5902 | } |
| 5903 | } |
| 5904 | |
| 5905 | /** |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 5906 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 5907 | * @param subId subscription id of the sim card |
| 5908 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 5909 | * This can be passed following states |
| 5910 | * <ol> |
| 5911 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 5912 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 5913 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 5914 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 5915 | * </ol> |
| 5916 | * @return operation result. |
| 5917 | */ |
| 5918 | @Override |
| 5919 | public int setNrDualConnectivityState(int subId, |
| 5920 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 5921 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5922 | mApp, subId, "enableNRDualConnectivity"); |
| 5923 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 5924 | final long identity = Binder.clearCallingIdentity(); |
| 5925 | try { |
| 5926 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 5927 | nrDualConnectivityState, subId, |
| 5928 | workSource); |
| 5929 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 5930 | return result; |
| 5931 | } finally { |
| 5932 | Binder.restoreCallingIdentity(identity); |
| 5933 | } |
| 5934 | } |
| 5935 | |
| 5936 | /** |
| 5937 | * Is E-UTRA-NR Dual Connectivity enabled |
| 5938 | * @return true if dual connectivity is enabled else false |
| 5939 | */ |
| 5940 | @Override |
| 5941 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 5942 | TelephonyPermissions |
| 5943 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5944 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 5945 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 5946 | final long identity = Binder.clearCallingIdentity(); |
| 5947 | try { |
| 5948 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 5949 | null, subId, workSource); |
| 5950 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 5951 | return isEnabled; |
| 5952 | } finally { |
| 5953 | Binder.restoreCallingIdentity(identity); |
| 5954 | } |
| 5955 | } |
| 5956 | |
| 5957 | /** |
Sooraj Sasindran | 1f812e0 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 5958 | * get carrier bandwidth per primary and secondary carrier |
| 5959 | * @param subId subscription id of the sim card |
| 5960 | * @return CarrierBandwidth with bandwidth of both primary and secondary carrier.. |
| 5961 | */ |
| 5962 | @Override |
| 5963 | public CarrierBandwidth getCarrierBandwidth(int subId) { |
| 5964 | TelephonyPermissions |
| 5965 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5966 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 5967 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 5968 | final long identity = Binder.clearCallingIdentity(); |
| 5969 | try { |
| 5970 | CarrierBandwidth carrierBandwidth = |
| 5971 | getPhoneFromSubId(subId).getCarrierBandwidth(); |
| 5972 | if (DBG) log("getCarrierBandwidth: " + carrierBandwidth); |
| 5973 | return carrierBandwidth; |
| 5974 | } finally { |
| 5975 | Binder.restoreCallingIdentity(identity); |
| 5976 | } |
| 5977 | } |
| 5978 | |
| 5979 | /** |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 5980 | * Get the effective allowed network types on the device. |
| 5981 | * This API will return an intersection of allowed network types for all reasons, |
| 5982 | * including the configuration done through setAllowedNetworkTypes |
| 5983 | * |
| 5984 | * @param subId the id of the subscription. |
| 5985 | * @return the allowed network types |
| 5986 | */ |
| 5987 | @Override |
| 5988 | public long getEffectiveAllowedNetworkTypes(int subId) { |
| 5989 | TelephonyPermissions |
| 5990 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5991 | mApp, subId, "getEffectiveAllowedNetworkTypes"); |
| 5992 | final long identity = Binder.clearCallingIdentity(); |
| 5993 | try { |
| 5994 | return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes(); |
| 5995 | } finally { |
| 5996 | Binder.restoreCallingIdentity(identity); |
| 5997 | } |
| 5998 | } |
| 5999 | |
| 6000 | /** |
| 6001 | * Set the allowed network types of the device and |
| 6002 | * provide the reason triggering the allowed network change. |
| 6003 | * |
| 6004 | * @param subId the id of the subscription. |
| 6005 | * @param reason the reason the allowed network type change is taking place |
| 6006 | * @param allowedNetworkTypes the allowed network types. |
| 6007 | * @return true on success; false on any failure. |
| 6008 | */ |
| 6009 | @Override |
| 6010 | public boolean setAllowedNetworkTypesForReason(int subId, |
| 6011 | @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) { |
| 6012 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6013 | mApp, subId, "setAllowedNetworkTypesForReason"); |
| 6014 | final long identity = Binder.clearCallingIdentity(); |
| 6015 | try { |
| 6016 | getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes); |
| 6017 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 6018 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 6019 | RILConstants.PREFERRED_NETWORK_MODE); |
| 6020 | return setPreferredNetworkType(subId, preferredNetworkMode); |
| 6021 | } finally { |
| 6022 | Binder.restoreCallingIdentity(identity); |
| 6023 | } |
| 6024 | } |
| 6025 | |
| 6026 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6027 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6028 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6029 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6030 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6031 | * @hide |
| 6032 | */ |
| 6033 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6034 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6035 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6036 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6037 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6038 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6039 | if (phone != null) { |
| 6040 | return phone.hasMatchedTetherApnSetting(); |
| 6041 | } else { |
| 6042 | return false; |
| 6043 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6044 | } finally { |
| 6045 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6046 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6047 | } |
| 6048 | |
| 6049 | /** |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6050 | * Enable or disable always reporting signal strength changes from radio. |
| 6051 | * |
| 6052 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 6053 | */ |
| 6054 | @Override |
| 6055 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 6056 | enforceModifyPermission(); |
| 6057 | enforceSystemCaller(); |
| 6058 | |
| 6059 | final long identity = Binder.clearCallingIdentity(); |
| 6060 | final Phone phone = getPhone(subId); |
| 6061 | try { |
| 6062 | if (phone != null) { |
| 6063 | if (DBG) { |
| 6064 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6065 | + " isEnable=" + isEnable); |
| 6066 | } |
| 6067 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6068 | } else { |
| 6069 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6070 | + subId); |
| 6071 | } |
| 6072 | } finally { |
| 6073 | Binder.restoreCallingIdentity(identity); |
| 6074 | } |
| 6075 | } |
| 6076 | |
| 6077 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6078 | * Get the user enabled state of Mobile Data. |
| 6079 | * |
| 6080 | * TODO: remove and use isUserDataEnabled. |
| 6081 | * This can't be removed now because some vendor codes |
| 6082 | * calls through ITelephony directly while they should |
| 6083 | * use TelephonyManager. |
| 6084 | * |
| 6085 | * @return true on enabled |
| 6086 | */ |
| 6087 | @Override |
| 6088 | public boolean getDataEnabled(int subId) { |
| 6089 | return isUserDataEnabled(subId); |
| 6090 | } |
| 6091 | |
| 6092 | /** |
| 6093 | * Get whether mobile data is enabled per user setting. |
| 6094 | * |
| 6095 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6096 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6097 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6098 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6099 | * |
| 6100 | * @return {@code true} if data is enabled else {@code false} |
| 6101 | */ |
| 6102 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6103 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6104 | try { |
| 6105 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6106 | null); |
| 6107 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6108 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6109 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6110 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6111 | |
| 6112 | final long identity = Binder.clearCallingIdentity(); |
| 6113 | try { |
| 6114 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6115 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6116 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6117 | if (phone != null) { |
| 6118 | boolean retVal = phone.isUserDataEnabled(); |
| 6119 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6120 | return retVal; |
| 6121 | } else { |
| 6122 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6123 | return false; |
| 6124 | } |
| 6125 | } finally { |
| 6126 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6127 | } |
| 6128 | } |
| 6129 | |
| 6130 | /** |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6131 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6132 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6133 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6134 | * |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6135 | * @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] | 6136 | */ |
| 6137 | @Override |
| 6138 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6139 | try { |
| 6140 | try { |
| 6141 | mApp.enforceCallingOrSelfPermission( |
| 6142 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6143 | null); |
| 6144 | } catch (Exception e) { |
| 6145 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6146 | "isDataEnabled"); |
| 6147 | } |
| 6148 | } catch (Exception e) { |
| 6149 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6150 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6151 | |
| 6152 | final long identity = Binder.clearCallingIdentity(); |
| 6153 | try { |
| 6154 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6155 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6156 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6157 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6158 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6159 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6160 | return retVal; |
| 6161 | } else { |
| 6162 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6163 | return false; |
| 6164 | } |
| 6165 | } finally { |
| 6166 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6167 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6168 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6169 | |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6170 | /** |
| 6171 | * Check if data is enabled for a specific reason |
| 6172 | * @param subId Subscription index |
| 6173 | * @param reason the reason the data enable change is taking place |
| 6174 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6175 | */ |
| 6176 | @Override |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6177 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6178 | @TelephonyManager.DataEnabledReason int reason) { |
| 6179 | try { |
| 6180 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6181 | null); |
| 6182 | } catch (Exception e) { |
| 6183 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6184 | "isDataEnabledForReason"); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6185 | } |
| 6186 | |
| 6187 | |
| 6188 | final long identity = Binder.clearCallingIdentity(); |
| 6189 | try { |
| 6190 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6191 | if (DBG) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6192 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6193 | + " reason=" + reason); |
| 6194 | } |
| 6195 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6196 | if (phone != null) { |
| 6197 | boolean retVal; |
| 6198 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6199 | retVal = phone.isUserDataEnabled(); |
| 6200 | } else { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6201 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6202 | } |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6203 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6204 | return retVal; |
| 6205 | } else { |
| 6206 | if (DBG) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6207 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6208 | + subId + " retVal=false"); |
| 6209 | } |
| 6210 | return false; |
| 6211 | } |
| 6212 | } finally { |
| 6213 | Binder.restoreCallingIdentity(identity); |
| 6214 | } |
| 6215 | } |
| 6216 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6217 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6218 | Phone phone) { |
Hall Liu | ce478d2 | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 6219 | if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) { |
| 6220 | // Skip the check if it's one of these special uids |
| 6221 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6222 | } |
| 6223 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6224 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6225 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6226 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6227 | || subController == null) return privilegeFromSim; |
| 6228 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6229 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6230 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6231 | |
| 6232 | final long identity = Binder.clearCallingIdentity(); |
| 6233 | try { |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6234 | int subId = phone.getSubId(); |
| 6235 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6236 | // A test override is in place for the privileges for this subId, so don't try to |
| 6237 | // read the subscription privileges. |
| 6238 | return privilegeFromSim; |
| 6239 | } |
| 6240 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6241 | SubscriptionManager subManager = (SubscriptionManager) |
| 6242 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6243 | for (String pkg : packages) { |
| 6244 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6245 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6246 | } |
| 6247 | } |
| 6248 | return privilegeFromSim; |
| 6249 | } finally { |
| 6250 | Binder.restoreCallingIdentity(identity); |
| 6251 | } |
| 6252 | } |
| 6253 | |
| 6254 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6255 | String pkgName) { |
| 6256 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6257 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6258 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6259 | || subController == null) return privilegeFromSim; |
| 6260 | |
| 6261 | final long identity = Binder.clearCallingIdentity(); |
| 6262 | try { |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6263 | int subId = phone.getSubId(); |
| 6264 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6265 | // A test override is in place for the privileges for this subId, so don't try to |
| 6266 | // read the subscription privileges. |
| 6267 | return privilegeFromSim; |
| 6268 | } |
| 6269 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6270 | SubscriptionManager subManager = (SubscriptionManager) |
| 6271 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6272 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6273 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6274 | } finally { |
| 6275 | Binder.restoreCallingIdentity(identity); |
| 6276 | } |
| 6277 | } |
| 6278 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6279 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6280 | public int getCarrierPrivilegeStatus(int subId) { |
| 6281 | final Phone phone = getPhone(subId); |
| 6282 | if (phone == null) { |
| 6283 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6284 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6285 | } |
| 6286 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6287 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6288 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6289 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6290 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6291 | |
| 6292 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6293 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6294 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6295 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6296 | |
| 6297 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6298 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6299 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6300 | final Phone phone = getPhone(subId); |
| 6301 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6302 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6303 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6304 | } |
| 6305 | UiccProfile profile = |
| 6306 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6307 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6308 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6309 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6310 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6311 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6312 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6313 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6314 | } |
| 6315 | |
| 6316 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6317 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 6318 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6319 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6320 | } |
| 6321 | |
| 6322 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 6323 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6324 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6325 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6326 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6327 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6328 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6329 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6330 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6331 | } |
| 6332 | |
| 6333 | @Override |
| 6334 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6335 | if (TextUtils.isEmpty(pkgName)) |
| 6336 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6337 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6338 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6339 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 6340 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6341 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6342 | continue; |
| 6343 | } |
| 6344 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6345 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6346 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6347 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6348 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6349 | break; |
| 6350 | } |
| 6351 | } |
| 6352 | |
| 6353 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6354 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6355 | |
| 6356 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6357 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 6358 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6359 | loge("phoneId " + phoneId + " is not valid."); |
| 6360 | return null; |
| 6361 | } |
| 6362 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6363 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6364 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6365 | return null ; |
| 6366 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6367 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6368 | } |
| 6369 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6370 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6371 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6372 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6373 | List<String> privilegedPackages = new ArrayList<>(); |
| 6374 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6375 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 6376 | // has UICC in that slot. |
| 6377 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6378 | if (card.hasCarrierPrivilegeRules()) { |
| 6379 | if (packages == null) { |
| 6380 | // Only check packages in user 0 for now |
| 6381 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6382 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6383 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6384 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6385 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6386 | } |
| 6387 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6388 | PackageInfo pkgInfo = packages.get(p); |
| 6389 | if (pkgInfo != null && pkgInfo.packageName != null |
| 6390 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6391 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6392 | privilegedPackages.add(pkgInfo.packageName); |
| 6393 | } |
| 6394 | } |
| 6395 | } |
| 6396 | } |
| 6397 | return privilegedPackages; |
| 6398 | } |
| 6399 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6400 | @Override |
| 6401 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6402 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6403 | |
| 6404 | final long identity = Binder.clearCallingIdentity(); |
| 6405 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6406 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6407 | try { |
| 6408 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6409 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6410 | } |
| 6411 | } finally { |
| 6412 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6413 | } |
| 6414 | return privilegedPackages; |
| 6415 | } |
| 6416 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6417 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6418 | final Phone phone = getPhone(subId); |
| 6419 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6420 | if (card == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6421 | return null; |
| 6422 | } |
| 6423 | String iccId = card.getIccId(); |
| 6424 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6425 | return null; |
| 6426 | } |
| 6427 | return iccId; |
| 6428 | } |
| 6429 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6430 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6431 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6432 | String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6433 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6434 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6435 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6436 | final long identity = Binder.clearCallingIdentity(); |
| 6437 | try { |
| 6438 | final String iccId = getIccId(subId); |
| 6439 | final Phone phone = getPhone(subId); |
| 6440 | if (phone == null) { |
| 6441 | return false; |
| 6442 | } |
| 6443 | final String subscriberId = phone.getSubscriberId(); |
| 6444 | |
| 6445 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6446 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6447 | + subscriberId + " to " + number); |
| 6448 | } |
| 6449 | |
| 6450 | if (TextUtils.isEmpty(iccId)) { |
| 6451 | return false; |
| 6452 | } |
| 6453 | |
| 6454 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6455 | |
| 6456 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6457 | if (alphaTag == null) { |
| 6458 | editor.remove(alphaTagPrefKey); |
| 6459 | } else { |
| 6460 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6461 | } |
| 6462 | |
| 6463 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6464 | // track all merged IMSIs based on line number |
| 6465 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6466 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6467 | if (number == null) { |
| 6468 | editor.remove(numberPrefKey); |
| 6469 | editor.remove(subscriberPrefKey); |
| 6470 | } else { |
| 6471 | editor.putString(numberPrefKey, number); |
| 6472 | editor.putString(subscriberPrefKey, subscriberId); |
| 6473 | } |
| 6474 | |
| 6475 | editor.commit(); |
| 6476 | return true; |
| 6477 | } finally { |
| 6478 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6479 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6480 | } |
| 6481 | |
| 6482 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6483 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6484 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6485 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6486 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6487 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6488 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6489 | return null; |
| 6490 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6491 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6492 | final long identity = Binder.clearCallingIdentity(); |
| 6493 | try { |
| 6494 | String iccId = getIccId(subId); |
| 6495 | if (iccId != null) { |
| 6496 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6497 | if (DBG_MERGE) { |
| 6498 | log("getLine1NumberForDisplay returning " |
| 6499 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6500 | } |
| 6501 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6502 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6503 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6504 | return null; |
| 6505 | } finally { |
| 6506 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6507 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6508 | } |
| 6509 | |
| 6510 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6511 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6512 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6513 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6514 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6515 | return null; |
| 6516 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6517 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6518 | final long identity = Binder.clearCallingIdentity(); |
| 6519 | try { |
| 6520 | String iccId = getIccId(subId); |
| 6521 | if (iccId != null) { |
| 6522 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6523 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6524 | } |
| 6525 | return null; |
| 6526 | } finally { |
| 6527 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6528 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6529 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6530 | |
| 6531 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6532 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6533 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6534 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6535 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6536 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6537 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6538 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6539 | return null; |
| 6540 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6541 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6542 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6543 | // the process, where TelephonyManager was instantiated. |
| 6544 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6545 | final long identity = Binder.clearCallingIdentity(); |
| 6546 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6547 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6548 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6549 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6550 | |
| 6551 | // Figure out what subscribers are currently active |
| 6552 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6553 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6554 | // Only consider subs which match the current subId |
| 6555 | // This logic can be simplified. See b/131189269 for progress. |
| 6556 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6557 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6558 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6559 | |
| 6560 | // First pass, find a number override for an active subscriber |
| 6561 | String mergeNumber = null; |
| 6562 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6563 | for (String key : prefs.keySet()) { |
| 6564 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6565 | final String subscriberId = (String) prefs.get(key); |
| 6566 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6567 | final String iccId = key.substring( |
| 6568 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6569 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6570 | mergeNumber = (String) prefs.get(numberKey); |
| 6571 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6572 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6573 | + " for active subscriber " + subscriberId); |
| 6574 | } |
| 6575 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6576 | break; |
| 6577 | } |
| 6578 | } |
| 6579 | } |
| 6580 | } |
| 6581 | |
| 6582 | // Shortcut when no active merged subscribers |
| 6583 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6584 | return null; |
| 6585 | } |
| 6586 | |
| 6587 | // Second pass, find all subscribers under that line override |
| 6588 | final ArraySet<String> result = new ArraySet<>(); |
| 6589 | for (String key : prefs.keySet()) { |
| 6590 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6591 | final String number = (String) prefs.get(key); |
| 6592 | if (mergeNumber.equals(number)) { |
| 6593 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6594 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6595 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6596 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6597 | result.add(subscriberId); |
| 6598 | } |
| 6599 | } |
| 6600 | } |
| 6601 | } |
| 6602 | |
| 6603 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6604 | Arrays.sort(resultArray); |
| 6605 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6606 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6607 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6608 | } |
| 6609 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6610 | } finally { |
| 6611 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6612 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6613 | } |
| 6614 | |
| 6615 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6616 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6617 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6618 | |
| 6619 | final long identity = Binder.clearCallingIdentity(); |
| 6620 | try { |
| 6621 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6622 | TelephonyManager.class); |
| 6623 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6624 | if (subscriberId == null) { |
| 6625 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6626 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6627 | + subId); |
| 6628 | } |
| 6629 | return null; |
| 6630 | } |
| 6631 | |
| 6632 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6633 | .getSubscriptionInfo(subId); |
| 6634 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6635 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6636 | if (groupUuid == null) { |
| 6637 | return new String[]{subscriberId}; |
| 6638 | } |
| 6639 | |
| 6640 | // Get all subscriberIds from the group. |
| 6641 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6642 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6643 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6644 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6645 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6646 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6647 | if (subscriberId != null) { |
| 6648 | mergedSubscriberIds.add(subscriberId); |
| 6649 | } |
| 6650 | } |
| 6651 | |
| 6652 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6653 | } finally { |
| 6654 | Binder.restoreCallingIdentity(identity); |
| 6655 | |
| 6656 | } |
| 6657 | } |
| 6658 | |
| 6659 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6660 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6661 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6662 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6663 | |
| 6664 | final long identity = Binder.clearCallingIdentity(); |
| 6665 | try { |
| 6666 | final Phone phone = getPhone(subId); |
| 6667 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6668 | } finally { |
| 6669 | Binder.restoreCallingIdentity(identity); |
| 6670 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6671 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6672 | |
| 6673 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6674 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6675 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6676 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6677 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6678 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6679 | |
| 6680 | final long identity = Binder.clearCallingIdentity(); |
| 6681 | try { |
| 6682 | final Phone phone = getPhone(subId); |
| 6683 | if (phone == null) { |
| 6684 | return false; |
| 6685 | } |
| 6686 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6687 | cdmaNonRoamingList); |
| 6688 | } finally { |
| 6689 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6690 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6691 | } |
| 6692 | |
| 6693 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6694 | @Deprecated |
| 6695 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6696 | enforceModifyPermission(); |
| 6697 | |
| 6698 | int returnValue = 0; |
| 6699 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6700 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6701 | if(result.exception == null) { |
| 6702 | if (result.result != null) { |
| 6703 | byte[] responseData = (byte[])(result.result); |
| 6704 | if(responseData.length > oemResp.length) { |
| 6705 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6706 | responseData.length + "bytes. Buffer Size is " + |
| 6707 | oemResp.length + "bytes."); |
| 6708 | } |
| 6709 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6710 | returnValue = responseData.length; |
| 6711 | } |
| 6712 | } else { |
| 6713 | CommandException ex = (CommandException) result.exception; |
| 6714 | returnValue = ex.getCommandError().ordinal(); |
| 6715 | if(returnValue > 0) returnValue *= -1; |
| 6716 | } |
| 6717 | } catch (RuntimeException e) { |
| 6718 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6719 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6720 | if(returnValue > 0) returnValue *= -1; |
| 6721 | } |
| 6722 | |
| 6723 | return returnValue; |
| 6724 | } |
| 6725 | |
| 6726 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6727 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6728 | try { |
| 6729 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6730 | } catch (RuntimeException e) { |
| 6731 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6732 | } |
| 6733 | } |
| 6734 | |
| 6735 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6736 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6737 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6738 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6739 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6740 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6741 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6742 | final long identity = Binder.clearCallingIdentity(); |
| 6743 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6744 | TelephonyPermissions |
| 6745 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6746 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6747 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6748 | } finally { |
| 6749 | Binder.restoreCallingIdentity(identity); |
| 6750 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6751 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6752 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6753 | |
| 6754 | @Override |
| 6755 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6756 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6757 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6758 | |
| 6759 | final long identity = Binder.clearCallingIdentity(); |
| 6760 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6761 | ImsManager.getInstance(defaultPhone.getContext(), |
| 6762 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6763 | } finally { |
| 6764 | Binder.restoreCallingIdentity(identity); |
| 6765 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6766 | } |
| 6767 | |
| 6768 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6769 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6770 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6771 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 6772 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6773 | return false; |
| 6774 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6775 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6776 | final long identity = Binder.clearCallingIdentity(); |
| 6777 | try { |
| 6778 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 6779 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 6780 | // In the long run, we may instead need to check if there exists a connection service |
| 6781 | // which can support video calling. |
| 6782 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6783 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6784 | return imsManager.isVtEnabledByPlatform() |
| 6785 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 6786 | && imsManager.isVtEnabledByUser(); |
| 6787 | } finally { |
| 6788 | Binder.restoreCallingIdentity(identity); |
| 6789 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6790 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 6791 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6792 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6793 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 6794 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6795 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6796 | mApp, subId, callingPackage, callingFeatureId, |
| 6797 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6798 | return false; |
| 6799 | } |
| 6800 | |
| 6801 | final long identity = Binder.clearCallingIdentity(); |
| 6802 | try { |
| 6803 | CarrierConfigManager configManager = |
| 6804 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6805 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6806 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 6807 | } finally { |
| 6808 | Binder.restoreCallingIdentity(identity); |
| 6809 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6810 | } |
| 6811 | |
| 6812 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6813 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6814 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6815 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6816 | return false; |
| 6817 | } |
| 6818 | |
| 6819 | final long identity = Binder.clearCallingIdentity(); |
| 6820 | try { |
| 6821 | CarrierConfigManager configManager = |
| 6822 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6823 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6824 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 6825 | } finally { |
| 6826 | Binder.restoreCallingIdentity(identity); |
| 6827 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6828 | } |
| 6829 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6830 | @Override |
| 6831 | public boolean isTtyModeSupported() { |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6832 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 6833 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6834 | } |
| 6835 | |
| 6836 | @Override |
| 6837 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6838 | final long identity = Binder.clearCallingIdentity(); |
| 6839 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6840 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6841 | } finally { |
| 6842 | Binder.restoreCallingIdentity(identity); |
| 6843 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6844 | } |
| 6845 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6846 | /** |
| 6847 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 6848 | * support for the feature and device firmware support. |
| 6849 | * |
| 6850 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 6851 | */ |
| 6852 | @Override |
| 6853 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6854 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6855 | final Phone phone = getPhone(subscriptionId); |
| 6856 | if (phone == null) { |
| 6857 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 6858 | return false; |
| 6859 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6860 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6861 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6862 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 6863 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6864 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6865 | return isCarrierSupported && isDeviceSupported; |
| 6866 | } finally { |
| 6867 | Binder.restoreCallingIdentity(identity); |
| 6868 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 6869 | } |
| 6870 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6871 | /** |
Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 6872 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 6873 | * RTT setting, will return true if the device and carrier both support RTT. |
| 6874 | * 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] | 6875 | */ |
| 6876 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6877 | final long identity = Binder.clearCallingIdentity(); |
| 6878 | try { |
Hall Liu | 63767ec | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 6879 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 6880 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 6881 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 6882 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 6883 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 6884 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6885 | } finally { |
| 6886 | Binder.restoreCallingIdentity(identity); |
| 6887 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 6888 | } |
| 6889 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6890 | @Deprecated |
| 6891 | @Override |
| 6892 | public String getDeviceId(String callingPackage) { |
| 6893 | return getDeviceIdWithFeature(callingPackage, null); |
| 6894 | } |
| 6895 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6896 | /** |
| 6897 | * Returns the unique device ID of phone, for example, the IMEI for |
| 6898 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 6899 | * |
| 6900 | * <p>Requires Permission: |
| 6901 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 6902 | */ |
| 6903 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6904 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6905 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6906 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6907 | return null; |
| 6908 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6909 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 6910 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6911 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6912 | return null; |
| 6913 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6914 | |
| 6915 | final long identity = Binder.clearCallingIdentity(); |
| 6916 | try { |
| 6917 | return phone.getDeviceId(); |
| 6918 | } finally { |
| 6919 | Binder.restoreCallingIdentity(identity); |
| 6920 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6921 | } |
| 6922 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6923 | /** |
| 6924 | * {@hide} |
| 6925 | * Returns the IMS Registration Status on a particular subid |
| 6926 | * |
| 6927 | * @param subId |
| 6928 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6929 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6930 | Phone phone = getPhone(subId); |
| 6931 | if (phone != null) { |
| 6932 | return phone.isImsRegistered(); |
| 6933 | } else { |
| 6934 | return false; |
| 6935 | } |
| 6936 | } |
| 6937 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6938 | @Override |
| 6939 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6940 | final long identity = Binder.clearCallingIdentity(); |
| 6941 | try { |
| 6942 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 6943 | } finally { |
| 6944 | Binder.restoreCallingIdentity(identity); |
| 6945 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6946 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 6947 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6948 | @Override |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6949 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6950 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6951 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6952 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 6953 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 6954 | } |
| 6955 | final long identity = Binder.clearCallingIdentity(); |
| 6956 | try { |
| 6957 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 6958 | } finally { |
| 6959 | Binder.restoreCallingIdentity(identity); |
| 6960 | } |
| 6961 | } |
| 6962 | |
| 6963 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6964 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
duki.hong | fd96bde | 2020-07-22 17:32:19 +0900 | [diff] [blame] | 6965 | enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, " |
| 6966 | + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 6967 | final long identity = Binder.clearCallingIdentity(); |
| 6968 | try { |
| 6969 | Phone phone = getPhone(subscriptionId); |
| 6970 | if (phone == null) { |
| 6971 | return null; |
| 6972 | } |
| 6973 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 6974 | } finally { |
| 6975 | Binder.restoreCallingIdentity(identity); |
| 6976 | } |
| 6977 | } |
| 6978 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6979 | /** |
| 6980 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6981 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6982 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6983 | final long identity = Binder.clearCallingIdentity(); |
| 6984 | try { |
| 6985 | Phone phone = getPhone(subId); |
| 6986 | if (phone != null) { |
| 6987 | return phone.isWifiCallingEnabled(); |
| 6988 | } else { |
| 6989 | return false; |
| 6990 | } |
| 6991 | } finally { |
| 6992 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6993 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 6994 | } |
| 6995 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6996 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6997 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 6998 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6999 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7000 | final long identity = Binder.clearCallingIdentity(); |
| 7001 | try { |
| 7002 | Phone phone = getPhone(subId); |
| 7003 | if (phone != null) { |
| 7004 | return phone.isVideoEnabled(); |
| 7005 | } else { |
| 7006 | return false; |
| 7007 | } |
| 7008 | } finally { |
| 7009 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7010 | } |
| 7011 | } |
| 7012 | |
| 7013 | /** |
| 7014 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7015 | * defined in {@link ImsRegistrationImplBase}. |
| 7016 | */ |
| 7017 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7018 | final long identity = Binder.clearCallingIdentity(); |
| 7019 | try { |
| 7020 | Phone phone = getPhone(subId); |
| 7021 | if (phone != null) { |
| 7022 | return phone.getImsRegistrationTech(); |
| 7023 | } else { |
| 7024 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7025 | } |
| 7026 | } finally { |
| 7027 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7028 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7029 | } |
| 7030 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7031 | @Override |
| 7032 | public void factoryReset(int subId) { |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7033 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7034 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7035 | return; |
| 7036 | } |
| 7037 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7038 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7039 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7040 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7041 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7042 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7043 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7044 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7045 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7046 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7047 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 7048 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7049 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7050 | // There has been issues when Sms raw table somehow stores orphan |
| 7051 | // fragments. They lead to garbled message when new fragments come |
| 7052 | // in and combined with those stale ones. In case this happens again, |
| 7053 | // user can reset all network settings which will clean up this table. |
| 7054 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7055 | // Clean up IMS settings as well here. |
| 7056 | int slotId = getSlotIndex(subId); |
| 7057 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7058 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7059 | } |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7060 | |
| 7061 | // Erase modem config if erase modem on network setting is enabled. |
| 7062 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7063 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7064 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 7065 | sendEraseModemConfig(getDefaultPhone()); |
| 7066 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7067 | } finally { |
| 7068 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7069 | } |
| 7070 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7071 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7072 | private void cleanUpSmsRawTable(Context context) { |
| 7073 | ContentResolver resolver = context.getContentResolver(); |
| 7074 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7075 | resolver.delete(uri, null, null); |
| 7076 | } |
| 7077 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7078 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7079 | public String getSimLocaleForSubscriber(int subId) { |
| 7080 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7081 | final Phone phone = getPhone(subId); |
| 7082 | if (phone == null) { |
| 7083 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7084 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7085 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7086 | final long identity = Binder.clearCallingIdentity(); |
| 7087 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7088 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7089 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7090 | if (info == null) { |
| 7091 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7092 | return null; |
| 7093 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7094 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7095 | // preferences (EF-PL and EF-LI)... |
| 7096 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7097 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7098 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7099 | if (localeFromDefaultSim != null) { |
| 7100 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7101 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7102 | + localeFromDefaultSim); |
| 7103 | return localeFromDefaultSim.toLanguageTag(); |
| 7104 | } else { |
| 7105 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7106 | } |
| 7107 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7108 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7109 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7110 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7111 | // the SIM and carrier preferences does not include a country we add the country |
| 7112 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7113 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7114 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7115 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7116 | return mccLocale.toLanguageTag(); |
| 7117 | } |
| 7118 | |
| 7119 | if (DBG) log("No locale found - returning null"); |
| 7120 | return null; |
| 7121 | } finally { |
| 7122 | Binder.restoreCallingIdentity(identity); |
| 7123 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7124 | } |
| 7125 | |
| 7126 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7127 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7128 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7129 | } |
| 7130 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7131 | /** |
| 7132 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7133 | */ |
| 7134 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7135 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7136 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7137 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7138 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7139 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7140 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7141 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7142 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7143 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7144 | * representing the state of the modem. |
| 7145 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7146 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7147 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7148 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7149 | */ |
| 7150 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7151 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7152 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7153 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7154 | |
| 7155 | final long identity = Binder.clearCallingIdentity(); |
| 7156 | try { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 7157 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7158 | } finally { |
| 7159 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7160 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7161 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7162 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7163 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7164 | // less than total activity duration. |
| 7165 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7166 | if (info == null) { |
| 7167 | return false; |
| 7168 | } |
| 7169 | int activityDurationMs = |
| 7170 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 7171 | int totalTxTimeMs = 0; |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7172 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 7173 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 7174 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7175 | } |
| 7176 | return (info.isValid() |
| 7177 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7178 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7179 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7180 | && (totalTxTimeMs <= activityDurationMs)); |
| 7181 | } |
| 7182 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7183 | /** |
| 7184 | * {@hide} |
| 7185 | * Returns the service state information on specified subscription. |
| 7186 | */ |
| 7187 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7188 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7189 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7190 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7191 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7192 | return null; |
| 7193 | } |
| 7194 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7195 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7196 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7197 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7198 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7199 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7200 | .setCallingPid(Binder.getCallingPid()) |
| 7201 | .setCallingUid(Binder.getCallingUid()) |
| 7202 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7203 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7204 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7205 | .build()); |
| 7206 | |
| 7207 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7208 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7209 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7210 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7211 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7212 | .setCallingPid(Binder.getCallingPid()) |
| 7213 | .setCallingUid(Binder.getCallingUid()) |
| 7214 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7215 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7216 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7217 | .build()); |
| 7218 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7219 | boolean hasFinePermission = |
| 7220 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7221 | boolean hasCoarsePermission = |
| 7222 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7223 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7224 | final long identity = Binder.clearCallingIdentity(); |
| 7225 | try { |
| 7226 | final Phone phone = getPhone(subId); |
| 7227 | if (phone == null) { |
| 7228 | return null; |
| 7229 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7230 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7231 | ServiceState ss = phone.getServiceState(); |
| 7232 | |
| 7233 | // Scrub out the location info in ServiceState depending on what level of access |
| 7234 | // the caller has. |
| 7235 | if (hasFinePermission) return ss; |
Malcolm Chen | db33797 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7236 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7237 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7238 | } finally { |
| 7239 | Binder.restoreCallingIdentity(identity); |
| 7240 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7241 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7242 | |
| 7243 | /** |
| 7244 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7245 | * |
| 7246 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7247 | * voicemail ringtone. |
| 7248 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7249 | * PhoneAccount. |
| 7250 | */ |
| 7251 | @Override |
| 7252 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7253 | final long identity = Binder.clearCallingIdentity(); |
| 7254 | try { |
| 7255 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7256 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7257 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7258 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7259 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7260 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7261 | } finally { |
| 7262 | Binder.restoreCallingIdentity(identity); |
| 7263 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7264 | } |
| 7265 | |
| 7266 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7267 | * Sets the per-account voicemail ringtone. |
| 7268 | * |
| 7269 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7270 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7271 | * |
| 7272 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7273 | * voicemail ringtone. |
| 7274 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7275 | * PhoneAccount. |
| 7276 | */ |
| 7277 | @Override |
| 7278 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7279 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7280 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7281 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7282 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7283 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7284 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7285 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7286 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7287 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7288 | |
| 7289 | final long identity = Binder.clearCallingIdentity(); |
| 7290 | try { |
| 7291 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7292 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7293 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7294 | } |
| 7295 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7296 | } finally { |
| 7297 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7298 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7299 | } |
| 7300 | |
| 7301 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7302 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7303 | * |
| 7304 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7305 | * voicemail vibration setting. |
| 7306 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7307 | */ |
| 7308 | @Override |
| 7309 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7310 | final long identity = Binder.clearCallingIdentity(); |
| 7311 | try { |
| 7312 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7313 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7314 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7315 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7316 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7317 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7318 | } finally { |
| 7319 | Binder.restoreCallingIdentity(identity); |
| 7320 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7321 | } |
| 7322 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7323 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7324 | * Sets the per-account voicemail vibration. |
| 7325 | * |
| 7326 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7327 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7328 | * |
| 7329 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7330 | * voicemail vibration setting. |
| 7331 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7332 | * specific PhoneAccount. |
| 7333 | */ |
| 7334 | @Override |
| 7335 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7336 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7337 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7338 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7339 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7340 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7341 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7342 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7343 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7344 | } |
| 7345 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7346 | final long identity = Binder.clearCallingIdentity(); |
| 7347 | try { |
| 7348 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7349 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7350 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7351 | } |
| 7352 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7353 | } finally { |
| 7354 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7355 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7356 | } |
| 7357 | |
| 7358 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7359 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 7360 | * |
| 7361 | * @throws SecurityException if the caller does not have the required permission |
| 7362 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7363 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7364 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7365 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7366 | } |
| 7367 | |
| 7368 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7369 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 7370 | * permission. |
| 7371 | * |
| 7372 | * @throws SecurityException if the caller does not have the required permission |
| 7373 | */ |
| 7374 | private void enforceSendSmsPermission() { |
| 7375 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 7376 | } |
| 7377 | |
| 7378 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7379 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7380 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7381 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7382 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7383 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7384 | final long identity = Binder.clearCallingIdentity(); |
| 7385 | try { |
| 7386 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7387 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7388 | if (componentName == null) { |
| 7389 | throw new SecurityException( |
| 7390 | "Caller not current active visual voicemail package[null]"); |
| 7391 | } |
| 7392 | String vvmPackage = componentName.getPackageName(); |
| 7393 | if (!callingPackage.equals(vvmPackage)) { |
| 7394 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 7395 | + vvmPackage + "]"); |
| 7396 | } |
| 7397 | } finally { |
| 7398 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7399 | } |
| 7400 | } |
| 7401 | |
| 7402 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7403 | * Return the application ID for the app type. |
| 7404 | * |
| 7405 | * @param subId the subscription ID that this request applies to. |
| 7406 | * @param appType the uicc app type. |
| 7407 | * @return Application ID for specificied app type, or null if no uicc. |
| 7408 | */ |
| 7409 | @Override |
| 7410 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7411 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7412 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7413 | |
| 7414 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7415 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7416 | if (phone == null) { |
| 7417 | return null; |
| 7418 | } |
| 7419 | String aid = null; |
| 7420 | try { |
| 7421 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 7422 | .getApplicationByType(appType).getAid(); |
| 7423 | } catch (Exception e) { |
| 7424 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 7425 | } |
| 7426 | return aid; |
| 7427 | } finally { |
| 7428 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7429 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7430 | } |
| 7431 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7432 | /** |
| 7433 | * Return the Electronic Serial Number. |
| 7434 | * |
| 7435 | * @param subId the subscription ID that this request applies to. |
| 7436 | * @return ESN or null if error. |
| 7437 | */ |
| 7438 | @Override |
| 7439 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7440 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7441 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7442 | |
| 7443 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7444 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7445 | if (phone == null) { |
| 7446 | return null; |
| 7447 | } |
| 7448 | String esn = null; |
| 7449 | try { |
| 7450 | esn = phone.getEsn(); |
| 7451 | } catch (Exception e) { |
| 7452 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 7453 | } |
| 7454 | return esn; |
| 7455 | } finally { |
| 7456 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7457 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7458 | } |
| 7459 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7460 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7461 | * Return the Preferred Roaming List Version. |
| 7462 | * |
| 7463 | * @param subId the subscription ID that this request applies to. |
| 7464 | * @return PRLVersion or null if error. |
| 7465 | */ |
| 7466 | @Override |
| 7467 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7468 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7469 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7470 | |
| 7471 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7472 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7473 | if (phone == null) { |
| 7474 | return null; |
| 7475 | } |
| 7476 | String cdmaPrlVersion = null; |
| 7477 | try { |
| 7478 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7479 | } catch (Exception e) { |
| 7480 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7481 | } |
| 7482 | return cdmaPrlVersion; |
| 7483 | } finally { |
| 7484 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7485 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7486 | } |
| 7487 | |
| 7488 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7489 | * Get snapshot of Telephony histograms |
| 7490 | * @return List of Telephony histograms |
| 7491 | * @hide |
| 7492 | */ |
| 7493 | @Override |
| 7494 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7495 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7496 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7497 | |
| 7498 | final long identity = Binder.clearCallingIdentity(); |
| 7499 | try { |
| 7500 | return RIL.getTelephonyRILTimingHistograms(); |
| 7501 | } finally { |
| 7502 | Binder.restoreCallingIdentity(identity); |
| 7503 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7504 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7505 | |
| 7506 | /** |
| 7507 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7508 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7509 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7510 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7511 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7512 | * @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] | 7513 | */ |
| 7514 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7515 | @TelephonyManager.SetCarrierRestrictionResult |
| 7516 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7517 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7518 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7519 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7520 | if (carrierRestrictionRules == null) { |
| 7521 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7522 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7523 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7524 | final long identity = Binder.clearCallingIdentity(); |
| 7525 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7526 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7527 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7528 | } finally { |
| 7529 | Binder.restoreCallingIdentity(identity); |
| 7530 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7531 | } |
| 7532 | |
| 7533 | /** |
| 7534 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7535 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7536 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7537 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7538 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7539 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7540 | */ |
| 7541 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7542 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7543 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7544 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7545 | |
| 7546 | final long identity = Binder.clearCallingIdentity(); |
| 7547 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7548 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7549 | if (response instanceof CarrierRestrictionRules) { |
| 7550 | return (CarrierRestrictionRules) response; |
| 7551 | } |
| 7552 | // Response is an Exception of some kind, |
| 7553 | // which is signalled to the user as a NULL retval |
| 7554 | return null; |
| 7555 | } catch (Exception e) { |
| 7556 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7557 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7558 | } finally { |
| 7559 | Binder.restoreCallingIdentity(identity); |
| 7560 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7561 | } |
| 7562 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7563 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7564 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7565 | * @param subId the subscription ID that this action applies to. |
| 7566 | * @param enabled control enable or disable radio. |
| 7567 | * {@hide} |
| 7568 | */ |
| 7569 | @Override |
| 7570 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7571 | enforceModifyPermission(); |
| 7572 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7573 | |
| 7574 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7575 | if (phone == null) { |
| 7576 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7577 | return; |
| 7578 | } |
| 7579 | try { |
| 7580 | phone.carrierActionSetRadioEnabled(enabled); |
| 7581 | } catch (Exception e) { |
| 7582 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7583 | } finally { |
| 7584 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7585 | } |
| 7586 | } |
| 7587 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7588 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7589 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7590 | * network status based on which carrier apps could apply actions accordingly, |
| 7591 | * enable/disable default url handler for example. |
| 7592 | * |
| 7593 | * @param subId the subscription ID that this action applies to. |
| 7594 | * @param report control start/stop reporting the default network status. |
| 7595 | * {@hide} |
| 7596 | */ |
| 7597 | @Override |
| 7598 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7599 | enforceModifyPermission(); |
| 7600 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7601 | |
| 7602 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7603 | if (phone == null) { |
| 7604 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7605 | return; |
| 7606 | } |
| 7607 | try { |
| 7608 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7609 | } catch (Exception e) { |
| 7610 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7611 | } finally { |
| 7612 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7613 | } |
| 7614 | } |
| 7615 | |
| 7616 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7617 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7618 | * @param subId the subscription ID that this action applies to. |
| 7619 | * {@hide} |
| 7620 | */ |
| 7621 | @Override |
| 7622 | public void carrierActionResetAll(int subId) { |
| 7623 | enforceModifyPermission(); |
| 7624 | final Phone phone = getPhone(subId); |
| 7625 | if (phone == null) { |
| 7626 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7627 | return; |
| 7628 | } |
| 7629 | try { |
| 7630 | phone.carrierActionResetAll(); |
| 7631 | } catch (Exception e) { |
| 7632 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7633 | } |
| 7634 | } |
| 7635 | |
| 7636 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7637 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7638 | * bug report is being generated. |
| 7639 | */ |
| 7640 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7641 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7642 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7643 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7644 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7645 | + Binder.getCallingPid() |
| 7646 | + ", uid=" + Binder.getCallingUid() |
| 7647 | + "without permission " |
| 7648 | + android.Manifest.permission.DUMP); |
| 7649 | return; |
| 7650 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7651 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7652 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7653 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7654 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 7655 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 7656 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 7657 | @NonNull String[] args) { |
| 7658 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 7659 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 7660 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7661 | } |
| 7662 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7663 | /** |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7664 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7665 | * @param subId Subscription index |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7666 | * @param reason the reason the data enable change is taking place |
| 7667 | * @param enabled True if enabling the data, otherwise disabling. |
| 7668 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7669 | */ |
| 7670 | @Override |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7671 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7672 | boolean enabled) { |
| 7673 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 7674 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7675 | try { |
| 7676 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7677 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7678 | } catch (SecurityException se) { |
| 7679 | enforceModifyPermission(); |
| 7680 | } |
| 7681 | } else { |
| 7682 | enforceModifyPermission(); |
| 7683 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7684 | |
| 7685 | final long identity = Binder.clearCallingIdentity(); |
| 7686 | try { |
| 7687 | Phone phone = getPhone(subId); |
| 7688 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7689 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7690 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7691 | } else { |
| 7692 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 7693 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7694 | } |
| 7695 | } finally { |
| 7696 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7697 | } |
| 7698 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7699 | |
| 7700 | /** |
| 7701 | * Get Client request stats |
| 7702 | * @return List of Client Request Stats |
| 7703 | * @hide |
| 7704 | */ |
| 7705 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7706 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7707 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7708 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7709 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7710 | return null; |
| 7711 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7712 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7713 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7714 | final long identity = Binder.clearCallingIdentity(); |
| 7715 | try { |
| 7716 | if (phone != null) { |
| 7717 | return phone.getClientRequestStats(); |
| 7718 | } |
| 7719 | |
| 7720 | return null; |
| 7721 | } finally { |
| 7722 | Binder.restoreCallingIdentity(identity); |
| 7723 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7724 | } |
| 7725 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7726 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7727 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7728 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7729 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7730 | |
| 7731 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7732 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7733 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7734 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7735 | * @param state State of SIM (power down, power up, pass through) |
| 7736 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7737 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7738 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7739 | * |
| 7740 | **/ |
| 7741 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7742 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7743 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7744 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7745 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7746 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7747 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7748 | final long identity = Binder.clearCallingIdentity(); |
| 7749 | try { |
| 7750 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7751 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7752 | } |
| 7753 | } finally { |
| 7754 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7755 | } |
| 7756 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7757 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7758 | private boolean isUssdApiAllowed(int subId) { |
| 7759 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7760 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7761 | if (configManager == null) { |
| 7762 | return false; |
| 7763 | } |
| 7764 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 7765 | if (pb == null) { |
| 7766 | return false; |
| 7767 | } |
| 7768 | return pb.getBoolean( |
| 7769 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 7770 | } |
| 7771 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7772 | /** |
| 7773 | * Check if phone is in emergency callback mode |
| 7774 | * @return true if phone is in emergency callback mode |
| 7775 | * @param subId sub id |
| 7776 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 7777 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7778 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7779 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7780 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7781 | |
| 7782 | final long identity = Binder.clearCallingIdentity(); |
| 7783 | try { |
| 7784 | if (phone != null) { |
| 7785 | return phone.isInEcm(); |
| 7786 | } else { |
| 7787 | return false; |
| 7788 | } |
| 7789 | } finally { |
| 7790 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7791 | } |
| 7792 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7793 | |
| 7794 | /** |
| 7795 | * Get the current signal strength information for the given subscription. |
| 7796 | * Because this information is not updated when the device is in a low power state |
| 7797 | * it should not be relied-upon to be current. |
| 7798 | * @param subId Subscription index |
| 7799 | * @return the most recent cached signal strength info from the modem |
| 7800 | */ |
| 7801 | @Override |
| 7802 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7803 | final long identity = Binder.clearCallingIdentity(); |
| 7804 | try { |
| 7805 | Phone p = getPhone(subId); |
| 7806 | if (p == null) { |
| 7807 | return null; |
| 7808 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7809 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7810 | return p.getSignalStrength(); |
| 7811 | } finally { |
| 7812 | Binder.restoreCallingIdentity(identity); |
| 7813 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7814 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7815 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7816 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7817 | * Get the current modem radio state for the given slot. |
| 7818 | * @param slotIndex slot index. |
| 7819 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7820 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7821 | * @return the current radio power state from the modem |
| 7822 | */ |
| 7823 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7824 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7825 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7826 | if (phone != null) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7827 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 7828 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7829 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7830 | } |
| 7831 | |
| 7832 | final long identity = Binder.clearCallingIdentity(); |
| 7833 | try { |
| 7834 | return phone.getRadioPowerState(); |
| 7835 | } finally { |
| 7836 | Binder.restoreCallingIdentity(identity); |
| 7837 | } |
| 7838 | } |
| 7839 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7840 | } |
| 7841 | |
| 7842 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7843 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 7844 | * |
| 7845 | * <p>Requires one of the following permissions: |
| 7846 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 7847 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 7848 | * privileges. |
| 7849 | * |
| 7850 | * @param subId subscription id |
| 7851 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 7852 | * {@code false}. |
| 7853 | */ |
| 7854 | @Override |
| 7855 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 11263f3 | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 7856 | try { |
| 7857 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7858 | null); |
| 7859 | } catch (Exception e) { |
| 7860 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 7861 | mApp, subId, "isDataRoamingEnabled"); |
| 7862 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7863 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7864 | boolean isEnabled = false; |
| 7865 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7866 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7867 | Phone phone = getPhone(subId); |
| 7868 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7869 | } finally { |
| 7870 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7871 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7872 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7873 | } |
| 7874 | |
| 7875 | |
| 7876 | /** |
| 7877 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 7878 | * |
| 7879 | * <p> Requires permission: |
| 7880 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 7881 | * privileges. |
| 7882 | * |
| 7883 | * @param subId subscription id |
| 7884 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 7885 | */ |
| 7886 | @Override |
| 7887 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7888 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7889 | mApp, subId, "setDataRoamingEnabled"); |
| 7890 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7891 | final long identity = Binder.clearCallingIdentity(); |
| 7892 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7893 | Phone phone = getPhone(subId); |
| 7894 | if (phone != null) { |
| 7895 | phone.setDataRoamingEnabled(isEnabled); |
| 7896 | } |
| 7897 | } finally { |
| 7898 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7899 | } |
| 7900 | } |
| 7901 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7902 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7903 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 7904 | TelephonyPermissions |
| 7905 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7906 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 7907 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7908 | boolean isAllowed = true; |
| 7909 | final long identity = Binder.clearCallingIdentity(); |
| 7910 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7911 | Phone phone = getPhone(subId); |
| 7912 | if (phone != null) { |
| 7913 | isAllowed = phone.isCspPlmnEnabled(); |
| 7914 | } |
| 7915 | } finally { |
| 7916 | Binder.restoreCallingIdentity(identity); |
| 7917 | } |
| 7918 | return isAllowed; |
| 7919 | } |
| 7920 | |
| 7921 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7922 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | cfdfe3a | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 7923 | // Verify that tha callingPackage belongs to the calling UID |
| 7924 | mApp.getSystemService(AppOpsManager.class) |
| 7925 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 7926 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7927 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7928 | try { |
| 7929 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7930 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7931 | } catch (SecurityException e) { |
| 7932 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 7933 | // has carrier privileges on an active UICC |
| 7934 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 7935 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7936 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7937 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7938 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7939 | |
| 7940 | final long identity = Binder.clearCallingIdentity(); |
| 7941 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7942 | UiccController uiccController = UiccController.getInstance(); |
| 7943 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7944 | if (hasReadPermission) { |
| 7945 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7946 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7947 | |
| 7948 | // Remove private info if the caller doesn't have access |
| 7949 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 7950 | for (UiccCardInfo cardInfo : cardInfos) { |
| 7951 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 7952 | // is available |
| 7953 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 7954 | if (card == null || card.getUiccProfile() == null) { |
| 7955 | // assume no access if the card or profile is unavailable |
| 7956 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7957 | continue; |
| 7958 | } |
| 7959 | UiccProfile profile = card.getUiccProfile(); |
| 7960 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 7961 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 7962 | filteredInfos.add(cardInfo); |
| 7963 | } else { |
| 7964 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 7965 | } |
| 7966 | } |
| 7967 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7968 | } finally { |
| 7969 | Binder.restoreCallingIdentity(identity); |
| 7970 | } |
| 7971 | } |
| 7972 | |
| 7973 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7974 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7975 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7976 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7977 | final long identity = Binder.clearCallingIdentity(); |
| 7978 | try { |
| 7979 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 7980 | if (slots == null) { |
| 7981 | Rlog.i(LOG_TAG, "slots is null."); |
| 7982 | return null; |
| 7983 | } |
| 7984 | |
| 7985 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 7986 | for (int i = 0; i < slots.length; i++) { |
| 7987 | UiccSlot slot = slots[i]; |
| 7988 | if (slot == null) { |
| 7989 | continue; |
| 7990 | } |
| 7991 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7992 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7993 | UiccCard card = slot.getUiccCard(); |
| 7994 | if (card != null) { |
| 7995 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 7996 | } else { |
Jordan Liu | d96b529 | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 7997 | cardId = slot.getEid(); |
| 7998 | if (TextUtils.isEmpty(cardId)) { |
| 7999 | cardId = slot.getIccId(); |
| 8000 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8001 | } |
| 8002 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8003 | if (cardId != null) { |
| 8004 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8005 | // if cardId is an EID, it's all digits so this is fine |
| 8006 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8007 | } |
| 8008 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8009 | int cardState = 0; |
| 8010 | switch (slot.getCardState()) { |
| 8011 | case CARDSTATE_ABSENT: |
| 8012 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8013 | break; |
| 8014 | case CARDSTATE_PRESENT: |
| 8015 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8016 | break; |
| 8017 | case CARDSTATE_ERROR: |
| 8018 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8019 | break; |
| 8020 | case CARDSTATE_RESTRICTED: |
| 8021 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8022 | break; |
| 8023 | default: |
| 8024 | break; |
| 8025 | |
| 8026 | } |
| 8027 | |
| 8028 | infos[i] = new UiccSlotInfo( |
| 8029 | slot.isActive(), |
| 8030 | slot.isEuicc(), |
| 8031 | cardId, |
| 8032 | cardState, |
| 8033 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8034 | slot.isExtendedApduSupported(), |
| 8035 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8036 | } |
| 8037 | return infos; |
| 8038 | } finally { |
| 8039 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8040 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8041 | } |
| 8042 | |
| 8043 | @Override |
| 8044 | public boolean switchSlots(int[] physicalSlots) { |
| 8045 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8046 | |
| 8047 | final long identity = Binder.clearCallingIdentity(); |
| 8048 | try { |
| 8049 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8050 | } finally { |
| 8051 | Binder.restoreCallingIdentity(identity); |
| 8052 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8053 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8054 | |
| 8055 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8056 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8057 | final long identity = Binder.clearCallingIdentity(); |
| 8058 | try { |
| 8059 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8060 | } finally { |
| 8061 | Binder.restoreCallingIdentity(identity); |
| 8062 | } |
| 8063 | } |
| 8064 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8065 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8066 | * A test API to reload the UICC profile. |
| 8067 | * |
| 8068 | * <p>Requires that the calling app has permission |
| 8069 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8070 | * @hide |
| 8071 | */ |
| 8072 | @Override |
| 8073 | public void refreshUiccProfile(int subId) { |
| 8074 | enforceModifyPermission(); |
| 8075 | |
| 8076 | final long identity = Binder.clearCallingIdentity(); |
| 8077 | try { |
| 8078 | Phone phone = getPhone(subId); |
| 8079 | if (phone == null) { |
| 8080 | return; |
| 8081 | } |
| 8082 | UiccCard uiccCard = phone.getUiccCard(); |
| 8083 | if (uiccCard == null) { |
| 8084 | return; |
| 8085 | } |
| 8086 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8087 | if (uiccProfile == null) { |
| 8088 | return; |
| 8089 | } |
| 8090 | uiccProfile.refresh(); |
| 8091 | } finally { |
| 8092 | Binder.restoreCallingIdentity(identity); |
| 8093 | } |
| 8094 | } |
| 8095 | |
| 8096 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8097 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8098 | */ |
| 8099 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8100 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8101 | } |
| 8102 | |
| 8103 | /** |
| 8104 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8105 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8106 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8107 | */ |
| 8108 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8109 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8110 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | faaa63d | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8111 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8112 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8113 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8114 | return isDataRoamingEnabled; |
| 8115 | } |
| 8116 | |
| 8117 | /** |
| 8118 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8119 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8120 | */ |
| 8121 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8122 | List<Integer> list = TelephonyProperties.default_network(); |
| 8123 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8124 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8125 | return list.get(phoneId); |
| 8126 | } |
| 8127 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8128 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8129 | |
| 8130 | @Override |
| 8131 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8132 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8133 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8134 | |
| 8135 | final long identity = Binder.clearCallingIdentity(); |
| 8136 | try { |
| 8137 | final Phone phone = getPhone(subId); |
| 8138 | if (phone == null) { |
| 8139 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8140 | return; |
| 8141 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8142 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8143 | carrierPrivilegeRules, apn); |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8144 | if (carrierPrivilegeRules == null) { |
| 8145 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8146 | } else { |
| 8147 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8148 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8149 | } finally { |
| 8150 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8151 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8152 | } |
| 8153 | |
| 8154 | @Override |
| 8155 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8156 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8157 | |
| 8158 | final long identity = Binder.clearCallingIdentity(); |
| 8159 | try { |
| 8160 | final Phone phone = getPhone(subId); |
| 8161 | if (phone == null) { |
| 8162 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 8163 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 8164 | } |
| 8165 | return phone.getCarrierIdListVersion(); |
| 8166 | } finally { |
| 8167 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8168 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8169 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8170 | |
| 8171 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8172 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 8173 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8174 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8175 | mApp, subId, callingPackage, callingFeatureId, |
| 8176 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8177 | return -1; |
| 8178 | } |
| 8179 | |
| 8180 | final long identity = Binder.clearCallingIdentity(); |
| 8181 | try { |
| 8182 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 8183 | } finally { |
| 8184 | Binder.restoreCallingIdentity(identity); |
| 8185 | } |
| 8186 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8187 | |
| 8188 | @Override |
| 8189 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 0723870 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 8190 | TelephonyPermissions |
| 8191 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8192 | mApp, subId, "getCdmaRoamingMode"); |
| 8193 | |
| 8194 | final long identity = Binder.clearCallingIdentity(); |
| 8195 | try { |
| 8196 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 8197 | } finally { |
| 8198 | Binder.restoreCallingIdentity(identity); |
| 8199 | } |
| 8200 | } |
| 8201 | |
| 8202 | @Override |
| 8203 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 8204 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8205 | mApp, subId, "setCdmaRoamingMode"); |
| 8206 | |
| 8207 | final long identity = Binder.clearCallingIdentity(); |
| 8208 | try { |
| 8209 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 8210 | } finally { |
| 8211 | Binder.restoreCallingIdentity(identity); |
| 8212 | } |
| 8213 | } |
| 8214 | |
| 8215 | @Override |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8216 | public int getCdmaSubscriptionMode(int subId) { |
| 8217 | TelephonyPermissions |
| 8218 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8219 | mApp, subId, "getCdmaSubscriptionMode"); |
| 8220 | |
| 8221 | final long identity = Binder.clearCallingIdentity(); |
| 8222 | try { |
| 8223 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 8224 | } finally { |
| 8225 | Binder.restoreCallingIdentity(identity); |
| 8226 | } |
| 8227 | } |
| 8228 | |
| 8229 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8230 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 8231 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8232 | mApp, subId, "setCdmaSubscriptionMode"); |
| 8233 | |
| 8234 | final long identity = Binder.clearCallingIdentity(); |
| 8235 | try { |
| 8236 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 8237 | } finally { |
| 8238 | Binder.restoreCallingIdentity(identity); |
| 8239 | } |
| 8240 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8241 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8242 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8243 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8244 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8245 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8246 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 8247 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8248 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8249 | } |
| 8250 | final long identity = Binder.clearCallingIdentity(); |
| 8251 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8252 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 8253 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8254 | if (phone.getEmergencyNumberTracker() != null |
| 8255 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 8256 | emergencyNumberListInternal.put( |
| 8257 | phone.getSubId(), |
| 8258 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 8259 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8260 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8261 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8262 | } finally { |
| 8263 | Binder.restoreCallingIdentity(identity); |
| 8264 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8265 | } |
| 8266 | |
| 8267 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8268 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8269 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8270 | if (!exactMatch) { |
| 8271 | TelephonyPermissions |
| 8272 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8273 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8274 | } |
| 8275 | final long identity = Binder.clearCallingIdentity(); |
| 8276 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8277 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8278 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8279 | && phone.getEmergencyNumberTracker() |
| 8280 | .isEmergencyNumber(number, exactMatch)) { |
| 8281 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8282 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8283 | } |
| 8284 | return false; |
| 8285 | } finally { |
| 8286 | Binder.restoreCallingIdentity(identity); |
| 8287 | } |
| 8288 | } |
| 8289 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8290 | /** |
| 8291 | * Update emergency number list for test mode. |
| 8292 | */ |
| 8293 | @Override |
| 8294 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 8295 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8296 | "updateEmergencyNumberListTestMode"); |
| 8297 | |
| 8298 | final long identity = Binder.clearCallingIdentity(); |
| 8299 | try { |
| 8300 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8301 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8302 | if (tracker != null) { |
| 8303 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 8304 | } |
| 8305 | } |
| 8306 | } finally { |
| 8307 | Binder.restoreCallingIdentity(identity); |
| 8308 | } |
| 8309 | } |
| 8310 | |
| 8311 | /** |
| 8312 | * Get the full emergency number list for test mode. |
| 8313 | */ |
| 8314 | @Override |
| 8315 | public List<String> getEmergencyNumberListTestMode() { |
| 8316 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8317 | "getEmergencyNumberListTestMode"); |
| 8318 | |
| 8319 | final long identity = Binder.clearCallingIdentity(); |
| 8320 | try { |
| 8321 | Set<String> emergencyNumbers = new HashSet<>(); |
| 8322 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8323 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8324 | if (tracker != null) { |
| 8325 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 8326 | emergencyNumbers.add(num.getNumber()); |
| 8327 | } |
| 8328 | } |
| 8329 | } |
| 8330 | return new ArrayList<>(emergencyNumbers); |
| 8331 | } finally { |
| 8332 | Binder.restoreCallingIdentity(identity); |
| 8333 | } |
| 8334 | } |
| 8335 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8336 | @Override |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8337 | public int getEmergencyNumberDbVersion(int subId) { |
| 8338 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 8339 | |
| 8340 | final long identity = Binder.clearCallingIdentity(); |
| 8341 | try { |
| 8342 | final Phone phone = getPhone(subId); |
| 8343 | if (phone == null) { |
| 8344 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 8345 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 8346 | } |
| 8347 | return phone.getEmergencyNumberDbVersion(); |
| 8348 | } finally { |
| 8349 | Binder.restoreCallingIdentity(identity); |
| 8350 | } |
| 8351 | } |
| 8352 | |
| 8353 | @Override |
| 8354 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 8355 | enforceModifyPermission(); |
| 8356 | |
| 8357 | final long identity = Binder.clearCallingIdentity(); |
| 8358 | try { |
| 8359 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8360 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8361 | if (tracker != null) { |
| 8362 | tracker.updateOtaEmergencyNumberDatabase(); |
| 8363 | } |
| 8364 | } |
| 8365 | } finally { |
| 8366 | Binder.restoreCallingIdentity(identity); |
| 8367 | } |
| 8368 | } |
| 8369 | |
| 8370 | @Override |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8371 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8372 | enforceActiveEmergencySessionPermission(); |
| 8373 | |
| 8374 | final long identity = Binder.clearCallingIdentity(); |
| 8375 | try { |
| 8376 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8377 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8378 | if (tracker != null) { |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8379 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 8380 | } |
| 8381 | } |
| 8382 | } finally { |
| 8383 | Binder.restoreCallingIdentity(identity); |
| 8384 | } |
| 8385 | } |
| 8386 | |
| 8387 | @Override |
| 8388 | public void resetOtaEmergencyNumberDbFilePath() { |
| 8389 | enforceActiveEmergencySessionPermission(); |
| 8390 | |
| 8391 | final long identity = Binder.clearCallingIdentity(); |
| 8392 | try { |
| 8393 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8394 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8395 | if (tracker != null) { |
| 8396 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8397 | } |
| 8398 | } |
| 8399 | } finally { |
| 8400 | Binder.restoreCallingIdentity(identity); |
| 8401 | } |
| 8402 | } |
| 8403 | |
| 8404 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8405 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 8406 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 8407 | Phone phone = getPhone(subId); |
| 8408 | if (phone == null) { |
| 8409 | return null; |
| 8410 | } |
| 8411 | final long identity = Binder.clearCallingIdentity(); |
| 8412 | try { |
| 8413 | UiccProfile profile = UiccController.getInstance() |
| 8414 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 8415 | if (profile != null) { |
| 8416 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 8417 | } |
| 8418 | } finally { |
| 8419 | Binder.restoreCallingIdentity(identity); |
| 8420 | } |
| 8421 | return null; |
| 8422 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 8423 | |
| 8424 | /** |
| 8425 | * Enable or disable a modem stack. |
| 8426 | */ |
| 8427 | @Override |
| 8428 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 8429 | enforceModifyPermission(); |
| 8430 | |
| 8431 | final long identity = Binder.clearCallingIdentity(); |
| 8432 | try { |
| 8433 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8434 | if (phone == null) { |
| 8435 | return false; |
| 8436 | } else { |
| 8437 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 8438 | } |
| 8439 | } finally { |
| 8440 | Binder.restoreCallingIdentity(identity); |
| 8441 | } |
| 8442 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8443 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8444 | /** |
| 8445 | * Whether a modem stack is enabled or not. |
| 8446 | */ |
| 8447 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8448 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 8449 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8450 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8451 | if (phone == null) return false; |
| 8452 | |
| 8453 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8454 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 8455 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8456 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8457 | } |
| 8458 | |
| 8459 | final long identity = Binder.clearCallingIdentity(); |
| 8460 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8461 | try { |
| 8462 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 8463 | } catch (NoSuchElementException ex) { |
| 8464 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 8465 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8466 | } finally { |
| 8467 | Binder.restoreCallingIdentity(identity); |
| 8468 | } |
| 8469 | } |
| 8470 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8471 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8472 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8473 | enforceModifyPermission(); |
| 8474 | |
| 8475 | final long identity = Binder.clearCallingIdentity(); |
| 8476 | try { |
| 8477 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8478 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8479 | .commit(); |
| 8480 | } finally { |
| 8481 | Binder.restoreCallingIdentity(identity); |
| 8482 | } |
| 8483 | } |
| 8484 | |
| 8485 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8486 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8487 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8488 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8489 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8490 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8491 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8492 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8493 | |
| 8494 | final long identity = Binder.clearCallingIdentity(); |
| 8495 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8496 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8497 | } finally { |
| 8498 | Binder.restoreCallingIdentity(identity); |
| 8499 | } |
| 8500 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8501 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8502 | @TelephonyManager.IsMultiSimSupportedResult |
| 8503 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8504 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8505 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8506 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8507 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8508 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8509 | } |
| 8510 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8511 | // supported by the modem, indicate that it is restricted. |
| 8512 | PhoneCapability staticCapability = |
| 8513 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8514 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8515 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8516 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8517 | } |
Sarah Chin | 09f38ee | 2020-02-25 00:13:10 +0000 | [diff] [blame] | 8518 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8519 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8520 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8521 | } |
| 8522 | // Check if support of multiple SIMs is restricted by carrier |
| 8523 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8524 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8525 | } |
| 8526 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8527 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8528 | } |
| 8529 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8530 | /** |
| 8531 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8532 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8533 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8534 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8535 | * @param numOfSims number of active sims we want to switch to |
| 8536 | */ |
| 8537 | @Override |
| 8538 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8539 | if (numOfSims == 1) { |
| 8540 | enforceModifyPermission(); |
| 8541 | } else { |
| 8542 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8543 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8544 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8545 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8546 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8547 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8548 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8549 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8550 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8551 | return; |
| 8552 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8553 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8554 | } finally { |
| 8555 | Binder.restoreCallingIdentity(identity); |
| 8556 | } |
| 8557 | } |
| 8558 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8559 | @Override |
| 8560 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8561 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8562 | Phone phone = getPhone(subId); |
| 8563 | if (phone == null) { |
| 8564 | return false; |
| 8565 | } |
| 8566 | final long identity = Binder.clearCallingIdentity(); |
| 8567 | try { |
| 8568 | UiccCard uiccCard = phone.getUiccCard(); |
| 8569 | if (uiccCard == null) { |
| 8570 | return false; |
| 8571 | } |
| 8572 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8573 | if (uiccProfile == null) { |
| 8574 | return false; |
| 8575 | } |
| 8576 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8577 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8578 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8579 | } |
| 8580 | return false; |
| 8581 | } finally { |
| 8582 | Binder.restoreCallingIdentity(identity); |
| 8583 | } |
| 8584 | } |
| 8585 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8586 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8587 | * Get whether making changes to modem configurations will trigger reboot. |
| 8588 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8589 | */ |
| 8590 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8591 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8592 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8593 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8594 | mApp, subId, callingPackage, callingFeatureId, |
| 8595 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8596 | return false; |
| 8597 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8598 | final long identity = Binder.clearCallingIdentity(); |
| 8599 | try { |
| 8600 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8601 | } finally { |
| 8602 | Binder.restoreCallingIdentity(identity); |
| 8603 | } |
| 8604 | } |
| 8605 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8606 | private void updateModemStateMetrics() { |
| 8607 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8608 | // TODO: check the state for each modem if the api is ready. |
| 8609 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8610 | } |
| 8611 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8612 | @Override |
| 8613 | public int[] getSlotsMapping() { |
| 8614 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8615 | |
| 8616 | final long identity = Binder.clearCallingIdentity(); |
| 8617 | try { |
| 8618 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8619 | // All logical slots should have a mapping to a physical slot. |
| 8620 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8621 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8622 | for (int i = 0; i < slotInfos.length; i++) { |
| 8623 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8624 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8625 | } |
| 8626 | } |
| 8627 | return logicalSlotsMapping; |
| 8628 | } finally { |
| 8629 | Binder.restoreCallingIdentity(identity); |
| 8630 | } |
| 8631 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8632 | |
| 8633 | /** |
| 8634 | * Get the IRadio HAL Version |
| 8635 | */ |
| 8636 | @Override |
| 8637 | public int getRadioHalVersion() { |
| 8638 | Phone phone = getDefaultPhone(); |
| 8639 | if (phone == null) return -1; |
| 8640 | HalVersion hv = phone.getHalVersion(); |
| 8641 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8642 | return hv.major * 100 + hv.minor; |
| 8643 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8644 | |
| 8645 | /** |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8646 | * Get the current calling package name. |
| 8647 | * @return the current calling package name |
| 8648 | */ |
| 8649 | @Override |
| 8650 | public String getCurrentPackageName() { |
| 8651 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8652 | } |
| 8653 | |
| 8654 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8655 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8656 | * corresponding network requests on a subId. |
| 8657 | * |
| 8658 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8659 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8660 | * 2) APN is un-metered for this subscription, or |
| 8661 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | b48cf45 | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 8662 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8663 | * |
| 8664 | * @return whether data is allowed for a apn type. |
| 8665 | * |
| 8666 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8667 | */ |
| 8668 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8669 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | f250974 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8670 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8671 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8672 | |
| 8673 | // Now that all security checks passes, perform the operation as ourselves. |
| 8674 | final long identity = Binder.clearCallingIdentity(); |
| 8675 | try { |
| 8676 | Phone phone = getPhone(subId); |
| 8677 | if (phone == null) return false; |
| 8678 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8679 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8680 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8681 | } finally { |
| 8682 | Binder.restoreCallingIdentity(identity); |
| 8683 | } |
| 8684 | } |
| 8685 | |
| 8686 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8687 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8688 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8689 | |
| 8690 | // Now that all security checks passes, perform the operation as ourselves. |
| 8691 | final long identity = Binder.clearCallingIdentity(); |
| 8692 | try { |
| 8693 | Phone phone = getPhone(subId); |
| 8694 | if (phone == null) return true; // By default return true. |
| 8695 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8696 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8697 | } finally { |
| 8698 | Binder.restoreCallingIdentity(identity); |
| 8699 | } |
| 8700 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8701 | |
| 8702 | @Override |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 8703 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 8704 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 8705 | enforceModifyPermission(); |
| 8706 | long token = Binder.clearCallingIdentity(); |
| 8707 | try { |
| 8708 | Phone phone = getPhone(subscriptionId); |
| 8709 | if (phone == null) { |
| 8710 | try { |
| 8711 | if (resultCallback != null) { |
| 8712 | resultCallback.accept(false); |
| 8713 | } |
| 8714 | } catch (RemoteException e) { |
| 8715 | // ignore |
| 8716 | } |
| 8717 | return; |
| 8718 | } |
| 8719 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 8720 | Pair.create(specifiers, (x) -> { |
| 8721 | try { |
| 8722 | if (resultCallback != null) { |
| 8723 | resultCallback.accept(x); |
| 8724 | } |
| 8725 | } catch (RemoteException e) { |
| 8726 | // ignore |
| 8727 | } |
| 8728 | }); |
| 8729 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 8730 | } finally { |
| 8731 | Binder.restoreCallingIdentity(token); |
| 8732 | } |
| 8733 | } |
| 8734 | |
| 8735 | @Override |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 8736 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 8737 | TelephonyPermissions |
| 8738 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8739 | mApp, subId, "getSystemSelectionChannels"); |
| 8740 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8741 | final long identity = Binder.clearCallingIdentity(); |
| 8742 | try { |
| 8743 | List<RadioAccessSpecifier> specifiers = |
| 8744 | (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, |
| 8745 | null, subId, workSource); |
| 8746 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 8747 | return specifiers; |
| 8748 | } finally { |
| 8749 | Binder.restoreCallingIdentity(identity); |
| 8750 | } |
| 8751 | } |
| 8752 | |
| 8753 | @Override |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8754 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 8755 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8756 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 8757 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 8758 | if (iccRecords == null) { |
| 8759 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 8760 | return false; |
| 8761 | } |
| 8762 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 8763 | } |
| 8764 | |
| 8765 | @Override |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8766 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 8767 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8768 | if (callingPackage == null) { |
| 8769 | callingPackage = getCurrentPackageName(); |
| 8770 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8771 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 8772 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8773 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 8774 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8775 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 8776 | } |
| 8777 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 8778 | Intent intent = new Intent(); |
| 8779 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 8780 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 8781 | // Bring up choose default SMS subscription dialog right now |
| 8782 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 8783 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 8784 | mApp.startActivity(intent); |
| 8785 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8786 | |
| 8787 | @Override |
| 8788 | public String getMmsUAProfUrl(int subId) { |
| 8789 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8790 | final long identity = Binder.clearCallingIdentity(); |
| 8791 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 8792 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 8793 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 8794 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 8795 | return carrierUAProfUrl; |
| 8796 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8797 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8798 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 8799 | } finally { |
| 8800 | Binder.restoreCallingIdentity(identity); |
| 8801 | } |
| 8802 | } |
| 8803 | |
| 8804 | @Override |
| 8805 | public String getMmsUserAgent(int subId) { |
| 8806 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8807 | final long identity = Binder.clearCallingIdentity(); |
| 8808 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 8809 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 8810 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 8811 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 8812 | return carrierUserAgent; |
| 8813 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8814 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8815 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 8816 | } finally { |
| 8817 | Binder.restoreCallingIdentity(identity); |
| 8818 | } |
| 8819 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8820 | |
| 8821 | @Override |
Hall Liu | c041a55 | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 8822 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 8823 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
| 8824 | |
| 8825 | final long identity = Binder.clearCallingIdentity(); |
| 8826 | try { |
| 8827 | Phone phone = getPhone(subscriptionId); |
| 8828 | if (phone == null) return false; |
| 8829 | |
| 8830 | switch (policy) { |
| 8831 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 8832 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 8833 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 8834 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 8835 | default: |
| 8836 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 8837 | } |
| 8838 | } finally { |
| 8839 | Binder.restoreCallingIdentity(identity); |
| 8840 | } |
| 8841 | } |
| 8842 | |
| 8843 | @Override |
| 8844 | public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy, |
| 8845 | boolean enabled) { |
| 8846 | enforceModifyPermission(); |
| 8847 | |
| 8848 | final long identity = Binder.clearCallingIdentity(); |
| 8849 | try { |
| 8850 | Phone phone = getPhone(subscriptionId); |
| 8851 | if (phone == null) return; |
| 8852 | |
| 8853 | switch (policy) { |
| 8854 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 8855 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 8856 | break; |
| 8857 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 8858 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 8859 | break; |
| 8860 | default: |
| 8861 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 8862 | } |
| 8863 | } finally { |
| 8864 | Binder.restoreCallingIdentity(identity); |
| 8865 | } |
| 8866 | } |
| 8867 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8868 | /** |
Hall Liu | b48cf45 | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 8869 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8870 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 8871 | * otherwise. |
| 8872 | */ |
| 8873 | @Override |
| 8874 | public void setCepEnabled(boolean isCepEnabled) { |
| 8875 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 8876 | |
| 8877 | final long identity = Binder.clearCallingIdentity(); |
| 8878 | try { |
| 8879 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 8880 | for (Phone phone : PhoneFactory.getPhones()) { |
| 8881 | Phone defaultPhone = phone.getImsPhone(); |
| 8882 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 8883 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 8884 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 8885 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 8886 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 8887 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 8888 | + imsPhone.getMsisdn()); |
| 8889 | } |
| 8890 | } |
| 8891 | } finally { |
| 8892 | Binder.restoreCallingIdentity(identity); |
| 8893 | } |
| 8894 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 8895 | |
| 8896 | /** |
| 8897 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 8898 | * |
| 8899 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 8900 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 8901 | * before being read. |
| 8902 | */ |
| 8903 | @Override |
| 8904 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 8905 | isCompressed) { |
| 8906 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8907 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
| 8908 | try { |
| 8909 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 8910 | if (configBinder == null) { |
| 8911 | Rlog.e(LOG_TAG, "null result for getImsConfig"); |
| 8912 | } else { |
| 8913 | configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed); |
| 8914 | } |
| 8915 | } catch (RemoteException e) { |
| 8916 | Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage()); |
| 8917 | } |
| 8918 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8919 | |
| 8920 | @Override |
| 8921 | public boolean isIccLockEnabled(int subId) { |
| 8922 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 8923 | |
| 8924 | // Now that all security checks passes, perform the operation as ourselves. |
| 8925 | final long identity = Binder.clearCallingIdentity(); |
| 8926 | try { |
| 8927 | Phone phone = getPhone(subId); |
| 8928 | if (phone != null && phone.getIccCard() != null) { |
| 8929 | return phone.getIccCard().getIccLockEnabled(); |
| 8930 | } else { |
| 8931 | return false; |
| 8932 | } |
| 8933 | } finally { |
| 8934 | Binder.restoreCallingIdentity(identity); |
| 8935 | } |
| 8936 | } |
| 8937 | |
| 8938 | /** |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8939 | * Set the ICC pin lock enabled or disabled. |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8940 | * |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8941 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 8942 | * three cases: |
| 8943 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 8944 | * successfully. |
| 8945 | * - Positive number and zero for remaining password attempts. |
| 8946 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8947 | * |
| 8948 | */ |
| 8949 | @Override |
| 8950 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 8951 | enforceModifyPermission(); |
| 8952 | |
| 8953 | Phone phone = getPhone(subId); |
| 8954 | if (phone == null) { |
| 8955 | return 0; |
| 8956 | } |
| 8957 | // Now that all security checks passes, perform the operation as ourselves. |
| 8958 | final long identity = Binder.clearCallingIdentity(); |
| 8959 | try { |
| 8960 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 8961 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 8962 | return attemptsRemaining; |
| 8963 | |
| 8964 | } catch (Exception e) { |
| 8965 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 8966 | } finally { |
| 8967 | Binder.restoreCallingIdentity(identity); |
| 8968 | } |
| 8969 | return 0; |
| 8970 | } |
| 8971 | |
| 8972 | /** |
| 8973 | * Change the ICC password used in ICC pin lock. |
| 8974 | * |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8975 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 8976 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 8977 | * - Positive number and zero for remaining password attempts. |
| 8978 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8979 | * |
| 8980 | */ |
| 8981 | @Override |
| 8982 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 8983 | enforceModifyPermission(); |
| 8984 | |
| 8985 | Phone phone = getPhone(subId); |
| 8986 | if (phone == null) { |
| 8987 | return 0; |
| 8988 | } |
| 8989 | // Now that all security checks passes, perform the operation as ourselves. |
| 8990 | final long identity = Binder.clearCallingIdentity(); |
| 8991 | try { |
| 8992 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 8993 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 8994 | return attemptsRemaining; |
| 8995 | |
| 8996 | } catch (Exception e) { |
| 8997 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 8998 | } finally { |
| 8999 | Binder.restoreCallingIdentity(identity); |
| 9000 | } |
| 9001 | return 0; |
| 9002 | } |
Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9003 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9004 | /** |
| 9005 | * Request for receiving user activity notification |
| 9006 | */ |
| 9007 | @Override |
| 9008 | public void requestUserActivityNotification() { |
| 9009 | if (!mNotifyUserActivity.get() |
| 9010 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9011 | mNotifyUserActivity.set(true); |
| 9012 | } |
| 9013 | } |
| 9014 | |
| 9015 | /** |
| 9016 | * Called when userActivity is signalled in the power manager. |
| 9017 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9018 | */ |
| 9019 | @Override |
| 9020 | public void userActivity() { |
| 9021 | // *************************************** |
| 9022 | // * Inherited from PhoneWindowManager * |
| 9023 | // *************************************** |
| 9024 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9025 | // WITH ITS LOCKS HELD. |
| 9026 | // |
| 9027 | // This code must be VERY careful about the locks |
| 9028 | // it acquires. |
| 9029 | // In fact, the current code acquires way too many, |
| 9030 | // and probably has lurking deadlocks. |
| 9031 | |
| 9032 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9033 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9034 | } |
| 9035 | |
| 9036 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9037 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9038 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9039 | } |
| 9040 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9041 | |
Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9042 | @Override |
| 9043 | public boolean canConnectTo5GInDsdsMode() { |
| 9044 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9045 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9046 | |
| 9047 | @Override |
| 9048 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 9049 | String callingFeatureId) { |
| 9050 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 9051 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 9052 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9053 | } |
| 9054 | |
| 9055 | Phone phone = getPhone(subId); |
| 9056 | if (phone == null) { |
| 9057 | throw new RuntimeException("phone is not available"); |
| 9058 | } |
| 9059 | // Now that all security checks passes, perform the operation as ourselves. |
| 9060 | final long identity = Binder.clearCallingIdentity(); |
| 9061 | try { |
| 9062 | return phone.getEquivalentHomePlmns(); |
| 9063 | } finally { |
| 9064 | Binder.restoreCallingIdentity(identity); |
| 9065 | } |
| 9066 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 9067 | } |