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; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame^] | 67 | import android.telephony.Annotation.ThermalMitigationResult; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 68 | import android.telephony.CallForwardingInfo; |
Sooraj Sasindran | 1f812e0 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 69 | import android.telephony.CarrierBandwidth; |
Junda Liu | 12f7d80 | 2015-05-01 12:06:44 -0700 | [diff] [blame] | 70 | import android.telephony.CarrierConfigManager; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 71 | import android.telephony.CarrierRestrictionRules; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 72 | import android.telephony.CellIdentity; |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 73 | import android.telephony.CellIdentityCdma; |
| 74 | import android.telephony.CellIdentityGsm; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 75 | import android.telephony.CellInfo; |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 76 | import android.telephony.CellInfoGsm; |
| 77 | import android.telephony.CellInfoWcdma; |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 78 | import android.telephony.ClientRequestStats; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame^] | 79 | import android.telephony.DataThrottlingRequest; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 80 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 81 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 82 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 83 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 84 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 85 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 86 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 87 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 88 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 89 | import android.telephony.RadioAccessSpecifier; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 90 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 91 | import android.telephony.SignalStrength; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 92 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 93 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 94 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 95 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 96 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 97 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame^] | 98 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 99 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 100 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 101 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 102 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 103 | import android.telephony.data.ApnSetting; |
| 104 | import android.telephony.emergency.EmergencyNumber; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 105 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 106 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 107 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 108 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 109 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 110 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 111 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 112 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 113 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 114 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 115 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 116 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 117 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 118 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 119 | import android.util.ArraySet; |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 120 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 121 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 122 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 123 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 124 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 125 | import com.android.ims.internal.IImsServiceFeatureCallback; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 126 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 127 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 130 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 131 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 132 | import com.android.internal.telephony.CommandException; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 133 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 134 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 135 | import com.android.internal.telephony.HalVersion; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 136 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 139 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 141 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 147 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 148 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 156 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 157 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 158 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 160 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 162 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 164 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 165 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 166 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 168 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 170 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 172 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 173 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 174 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 175 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 176 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 177 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 178 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 179 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 180 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 181 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 182 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 183 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 184 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame^] | 185 | import com.android.services.telephony.TelecomAccountRegistry; |
| 186 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 187 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 188 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 189 | import java.io.FileDescriptor; |
| 190 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 191 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 192 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 193 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 194 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 195 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 196 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 197 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 198 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 199 | import java.util.Set; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 200 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 201 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 202 | |
| 203 | /** |
| 204 | * Implementation of the ITelephony interface. |
| 205 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 206 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 207 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 208 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 209 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 210 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 211 | |
| 212 | // Message codes used with mMainThreadHandler |
| 213 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 214 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 215 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 216 | private static final int CMD_OPEN_CHANNEL = 9; |
| 217 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 218 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 219 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 220 | private static final int CMD_NV_READ_ITEM = 13; |
| 221 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 222 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 223 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 224 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 225 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 226 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 227 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 228 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 229 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 230 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 231 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 232 | private static final int CMD_SEND_ENVELOPE = 25; |
| 233 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 234 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 235 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 236 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 237 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 238 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 239 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 240 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 241 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 242 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 243 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 244 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 245 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 246 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 247 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 248 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 249 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 250 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 251 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 252 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 253 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 254 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 255 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 256 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 257 | private static final int CMD_SWITCH_SLOTS = 50; |
| 258 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 259 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 260 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 261 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 262 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 263 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 264 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 265 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 266 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 267 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 268 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 269 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 270 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 271 | private static final int CMD_MODEM_REBOOT = 64; |
| 272 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 273 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 274 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 275 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 276 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 277 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 278 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 279 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 280 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 281 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 282 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 283 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 284 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 285 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 286 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 287 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 288 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 289 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 290 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 291 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 292 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 293 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 294 | private static final int CMD_GET_CALL_WAITING = 87; |
| 295 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 296 | private static final int CMD_SET_CALL_WAITING = 89; |
| 297 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 298 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 299 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 300 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 301 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 302 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 303 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 304 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 305 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame^] | 306 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 307 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 308 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 309 | // Parameters of select command. |
| 310 | private static final int SELECT_COMMAND = 0xA4; |
| 311 | private static final int SELECT_P1 = 0x04; |
| 312 | private static final int SELECT_P2 = 0; |
| 313 | private static final int SELECT_P3 = 0x10; |
| 314 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 315 | /** The singleton instance. */ |
| 316 | private static PhoneInterfaceManager sInstance; |
| 317 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 318 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 319 | private CallManager mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 320 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 321 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 322 | private AppOpsManager mAppOps; |
| 323 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 324 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 325 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 326 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 327 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 328 | /** User Activity */ |
| 329 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 330 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 331 | |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 332 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 333 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 334 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 335 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 336 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 337 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 338 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 339 | // String to store multi SIM allowed |
| 340 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 341 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 342 | // The AID of ISD-R. |
| 343 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 344 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 345 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 346 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 347 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 348 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 349 | |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame^] | 350 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
| 351 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 352 | /** |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 353 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 354 | */ |
| 355 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 356 | "reset_network_erase_modem_config_enabled"; |
| 357 | |
| 358 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 359 | * A request object to use for transmitting data to an ICC. |
| 360 | */ |
| 361 | private static final class IccAPDUArgument { |
| 362 | public int channel, cla, command, p1, p2, p3; |
| 363 | public String data; |
| 364 | |
| 365 | public IccAPDUArgument(int channel, int cla, int command, |
| 366 | int p1, int p2, int p3, String data) { |
| 367 | this.channel = channel; |
| 368 | this.cla = cla; |
| 369 | this.command = command; |
| 370 | this.p1 = p1; |
| 371 | this.p2 = p2; |
| 372 | this.p3 = p3; |
| 373 | this.data = data; |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 378 | * A request object to use for transmitting data to an ICC. |
| 379 | */ |
| 380 | private static final class ManualNetworkSelectionArgument { |
| 381 | public OperatorInfo operatorInfo; |
| 382 | public boolean persistSelection; |
| 383 | |
| 384 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 385 | this.operatorInfo = operatorInfo; |
| 386 | this.persistSelection = persistSelection; |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 391 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 392 | * request after sending. The main thread will notify the request when it is complete. |
| 393 | */ |
| 394 | private static final class MainThreadRequest { |
| 395 | /** The argument to use for the request */ |
| 396 | public Object argument; |
| 397 | /** The result of the request that is run on the main thread */ |
| 398 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 399 | // The subscriber id that this request applies to. Defaults to |
| 400 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 401 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 402 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 403 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 404 | public Phone phone; |
| 405 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 406 | public WorkSource workSource; |
| 407 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 408 | public MainThreadRequest(Object argument) { |
| 409 | this.argument = argument; |
| 410 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 411 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 412 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 413 | this.argument = argument; |
| 414 | if (phone != null) { |
| 415 | this.phone = phone; |
| 416 | } |
| 417 | this.workSource = workSource; |
| 418 | } |
| 419 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 420 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 421 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 422 | if (subId != null) { |
| 423 | this.subId = subId; |
| 424 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 425 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 426 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 427 | } |
| 428 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 429 | private static final class IncomingThirdPartyCallArgs { |
| 430 | public final ComponentName component; |
| 431 | public final String callId; |
| 432 | public final String callerDisplayName; |
| 433 | |
| 434 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 435 | String callerDisplayName) { |
| 436 | this.component = component; |
| 437 | this.callId = callId; |
| 438 | this.callerDisplayName = callerDisplayName; |
| 439 | } |
| 440 | } |
| 441 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 442 | /** |
| 443 | * A handler that processes messages on the main thread in the phone process. Since many |
| 444 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 445 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 446 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 447 | * on, which will be notified when the operation completes and will contain the result of the |
| 448 | * request. |
| 449 | * |
| 450 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 451 | * note that request.result must be set to something non-null for the calling thread to |
| 452 | * unblock. |
| 453 | */ |
| 454 | private final class MainThreadHandler extends Handler { |
| 455 | @Override |
| 456 | public void handleMessage(Message msg) { |
| 457 | MainThreadRequest request; |
| 458 | Message onCompleted; |
| 459 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 460 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 461 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 462 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 463 | |
| 464 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 465 | case CMD_HANDLE_USSD_REQUEST: { |
| 466 | request = (MainThreadRequest) msg.obj; |
| 467 | final Phone phone = getPhoneFromRequest(request); |
| 468 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 469 | String ussdRequest = ussdObject.first; |
| 470 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 471 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 472 | if (!isUssdApiAllowed(request.subId)) { |
| 473 | // Carrier does not support use of this API, return failure. |
| 474 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 475 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 476 | Bundle returnData = new Bundle(); |
| 477 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 478 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 479 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 480 | request.result = true; |
| 481 | notifyRequester(request); |
| 482 | return; |
| 483 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 484 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 485 | try { |
| 486 | request.result = phone != null |
| 487 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 488 | } catch (CallStateException cse) { |
| 489 | request.result = false; |
| 490 | } |
| 491 | // Wake up the requesting thread |
| 492 | notifyRequester(request); |
| 493 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 494 | } |
| 495 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 496 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 497 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 498 | final Phone phone = getPhoneFromRequest(request); |
| 499 | request.result = phone != null ? |
| 500 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 501 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 502 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 503 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 504 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 505 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 506 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 507 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 508 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 509 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 510 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 511 | if (uiccCard == null) { |
| 512 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 513 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 514 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 515 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 516 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 517 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 518 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 519 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 520 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 521 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 522 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 523 | break; |
| 524 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 525 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 526 | ar = (AsyncResult) msg.obj; |
| 527 | request = (MainThreadRequest) ar.userObj; |
| 528 | if (ar.exception == null && ar.result != null) { |
| 529 | request.result = ar.result; |
| 530 | } else { |
| 531 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 532 | if (ar.result == null) { |
| 533 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 534 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 535 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 536 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 537 | } else { |
| 538 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 539 | } |
| 540 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 541 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 542 | break; |
| 543 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 544 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 545 | request = (MainThreadRequest) msg.obj; |
| 546 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 547 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 548 | if (uiccCard == null) { |
| 549 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 550 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 551 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 552 | } else { |
| 553 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 554 | request); |
| 555 | uiccCard.iccTransmitApduBasicChannel( |
| 556 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 557 | iccArgument.p3, iccArgument.data, onCompleted); |
| 558 | } |
| 559 | break; |
| 560 | |
| 561 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 562 | ar = (AsyncResult) msg.obj; |
| 563 | request = (MainThreadRequest) ar.userObj; |
| 564 | if (ar.exception == null && ar.result != null) { |
| 565 | request.result = ar.result; |
| 566 | } else { |
| 567 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 568 | if (ar.result == null) { |
| 569 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 570 | } else if (ar.exception instanceof CommandException) { |
| 571 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 572 | ar.exception); |
| 573 | } else { |
| 574 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 575 | } |
| 576 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 577 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 578 | break; |
| 579 | |
| 580 | case CMD_EXCHANGE_SIM_IO: |
| 581 | request = (MainThreadRequest) msg.obj; |
| 582 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 583 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 584 | if (uiccCard == null) { |
| 585 | loge("iccExchangeSimIO: No UICC"); |
| 586 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 587 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 588 | } else { |
| 589 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 590 | request); |
| 591 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 592 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 593 | iccArgument.data, onCompleted); |
| 594 | } |
| 595 | break; |
| 596 | |
| 597 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 598 | ar = (AsyncResult) msg.obj; |
| 599 | request = (MainThreadRequest) ar.userObj; |
| 600 | if (ar.exception == null && ar.result != null) { |
| 601 | request.result = ar.result; |
| 602 | } else { |
| 603 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 604 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 605 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 606 | break; |
| 607 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 608 | case CMD_SEND_ENVELOPE: |
| 609 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 610 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 611 | if (uiccCard == null) { |
| 612 | loge("sendEnvelopeWithStatus: No UICC"); |
| 613 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 614 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 615 | } else { |
| 616 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 617 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 618 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 619 | break; |
| 620 | |
| 621 | case EVENT_SEND_ENVELOPE_DONE: |
| 622 | ar = (AsyncResult) msg.obj; |
| 623 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 624 | if (ar.exception == null && ar.result != null) { |
| 625 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 626 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 627 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 628 | if (ar.result == null) { |
| 629 | loge("sendEnvelopeWithStatus: Empty response"); |
| 630 | } else if (ar.exception instanceof CommandException) { |
| 631 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 632 | ar.exception); |
| 633 | } else { |
| 634 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 635 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 636 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 637 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 638 | break; |
| 639 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 640 | case CMD_OPEN_CHANNEL: |
| 641 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 642 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 643 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 644 | if (uiccCard == null) { |
| 645 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 646 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 647 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 648 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 649 | } else { |
| 650 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 651 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 652 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 653 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 654 | break; |
| 655 | |
| 656 | case EVENT_OPEN_CHANNEL_DONE: |
| 657 | ar = (AsyncResult) msg.obj; |
| 658 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 659 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 660 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 661 | int[] result = (int[]) ar.result; |
| 662 | int channelId = result[0]; |
| 663 | byte[] selectResponse = null; |
| 664 | if (result.length > 1) { |
| 665 | selectResponse = new byte[result.length - 1]; |
| 666 | for (int i = 1; i < result.length; ++i) { |
| 667 | selectResponse[i - 1] = (byte) result[i]; |
| 668 | } |
| 669 | } |
| 670 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 671 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 672 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 673 | if (ar.result == null) { |
| 674 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 675 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 676 | if (ar.exception != null) { |
| 677 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 678 | } |
| 679 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 680 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 681 | if (ar.exception instanceof CommandException) { |
| 682 | CommandException.Error error = |
| 683 | ((CommandException) (ar.exception)).getCommandError(); |
| 684 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 685 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 686 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 687 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 688 | } |
| 689 | } |
| 690 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 691 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 692 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 693 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 694 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 695 | break; |
| 696 | |
| 697 | case CMD_CLOSE_CHANNEL: |
| 698 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 699 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 700 | if (uiccCard == null) { |
| 701 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 702 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 703 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 704 | } else { |
| 705 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 706 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 707 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 708 | break; |
| 709 | |
| 710 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 711 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 712 | break; |
| 713 | |
| 714 | case CMD_NV_READ_ITEM: |
| 715 | request = (MainThreadRequest) msg.obj; |
| 716 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 717 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 718 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 719 | break; |
| 720 | |
| 721 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 722 | ar = (AsyncResult) msg.obj; |
| 723 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 724 | if (ar.exception == null && ar.result != null) { |
| 725 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 726 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 727 | request.result = ""; |
| 728 | if (ar.result == null) { |
| 729 | loge("nvReadItem: Empty response"); |
| 730 | } else if (ar.exception instanceof CommandException) { |
| 731 | loge("nvReadItem: CommandException: " + |
| 732 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 733 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 734 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 735 | } |
| 736 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 737 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 738 | break; |
| 739 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 740 | case CMD_NV_WRITE_ITEM: |
| 741 | request = (MainThreadRequest) msg.obj; |
| 742 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 743 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 744 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 745 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 746 | break; |
| 747 | |
| 748 | case EVENT_NV_WRITE_ITEM_DONE: |
| 749 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 750 | break; |
| 751 | |
| 752 | case CMD_NV_WRITE_CDMA_PRL: |
| 753 | request = (MainThreadRequest) msg.obj; |
| 754 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 755 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 756 | break; |
| 757 | |
| 758 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 759 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 760 | break; |
| 761 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 762 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 763 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 764 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 765 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 766 | break; |
| 767 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 768 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 769 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 770 | break; |
| 771 | |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 772 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 773 | request = (MainThreadRequest) msg.obj; |
| 774 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 775 | request); |
| 776 | Phone phone = getPhoneFromRequest(request); |
| 777 | if (phone != null) { |
| 778 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 779 | } else { |
| 780 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 781 | request.result = false; |
| 782 | notifyRequester(request); |
| 783 | } |
| 784 | break; |
| 785 | } |
| 786 | |
| 787 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 788 | ar = (AsyncResult) msg.obj; |
| 789 | request = (MainThreadRequest) ar.userObj; |
| 790 | if (ar.exception == null && ar.result != null) { |
| 791 | request.result = ar.result; |
| 792 | } else { |
| 793 | // request.result must be set to something non-null |
| 794 | // for the calling thread to unblock |
| 795 | if (request.result != null) { |
| 796 | request.result = ar.result; |
| 797 | } else { |
| 798 | request.result = false; |
| 799 | } |
| 800 | if (ar.result == null) { |
| 801 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 802 | } else if (ar.exception instanceof CommandException) { |
| 803 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 804 | + ar.exception); |
| 805 | } else { |
| 806 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 807 | } |
| 808 | } |
| 809 | notifyRequester(request); |
| 810 | break; |
| 811 | |
| 812 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 813 | request = (MainThreadRequest) msg.obj; |
| 814 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 815 | Phone phone = getPhoneFromRequest(request); |
| 816 | if (phone != null) { |
| 817 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 818 | request.workSource); |
| 819 | } else { |
| 820 | loge("enableNrDualConnectivity: No phone object"); |
| 821 | request.result = |
| 822 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 823 | notifyRequester(request); |
| 824 | } |
| 825 | break; |
| 826 | } |
| 827 | |
| 828 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 829 | ar = (AsyncResult) msg.obj; |
| 830 | request = (MainThreadRequest) ar.userObj; |
| 831 | if (ar.exception == null) { |
| 832 | request.result = |
| 833 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 834 | } else { |
| 835 | request.result = |
| 836 | TelephonyManager |
| 837 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 838 | if (ar.exception instanceof CommandException) { |
| 839 | CommandException.Error error = |
| 840 | ((CommandException) (ar.exception)).getCommandError(); |
| 841 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 842 | request.result = |
| 843 | TelephonyManager |
| 844 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 845 | } |
| 846 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 847 | + ar.exception); |
| 848 | } else { |
| 849 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 850 | } |
| 851 | } |
| 852 | notifyRequester(request); |
| 853 | break; |
| 854 | } |
| 855 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 856 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 857 | request = (MainThreadRequest) msg.obj; |
| 858 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 859 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 860 | break; |
| 861 | |
| 862 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 863 | ar = (AsyncResult) msg.obj; |
| 864 | request = (MainThreadRequest) ar.userObj; |
| 865 | if (ar.exception == null && ar.result != null) { |
| 866 | request.result = ar.result; // Integer |
| 867 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 868 | // request.result must be set to something non-null |
| 869 | // for the calling thread to unblock |
| 870 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 871 | if (ar.result == null) { |
| 872 | loge("getPreferredNetworkType: Empty response"); |
| 873 | } else if (ar.exception instanceof CommandException) { |
| 874 | loge("getPreferredNetworkType: CommandException: " + |
| 875 | ar.exception); |
| 876 | } else { |
| 877 | loge("getPreferredNetworkType: Unknown exception"); |
| 878 | } |
| 879 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 880 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 881 | break; |
| 882 | |
| 883 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 884 | request = (MainThreadRequest) msg.obj; |
| 885 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 886 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 887 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 888 | break; |
| 889 | |
| 890 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 891 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 892 | break; |
| 893 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 894 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 895 | request = (MainThreadRequest)msg.obj; |
| 896 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 897 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 898 | break; |
| 899 | |
| 900 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 901 | ar = (AsyncResult)msg.obj; |
| 902 | request = (MainThreadRequest)ar.userObj; |
| 903 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 904 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 905 | break; |
| 906 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 907 | case CMD_SET_VOICEMAIL_NUMBER: |
| 908 | request = (MainThreadRequest) msg.obj; |
| 909 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 910 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 911 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 912 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 913 | break; |
| 914 | |
| 915 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 916 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 917 | break; |
| 918 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 919 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 920 | request = (MainThreadRequest) msg.obj; |
| 921 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 922 | request); |
| 923 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 924 | break; |
| 925 | |
| 926 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 927 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 928 | break; |
| 929 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 930 | case CMD_PERFORM_NETWORK_SCAN: |
| 931 | request = (MainThreadRequest) msg.obj; |
| 932 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 933 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 934 | break; |
| 935 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 936 | case CMD_GET_CALL_FORWARDING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 937 | request = (MainThreadRequest) msg.obj; |
| 938 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 939 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 940 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 941 | request.argument; |
| 942 | int callForwardingReason = args.first; |
| 943 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 944 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 945 | } |
| 946 | case EVENT_GET_CALL_FORWARDING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 947 | ar = (AsyncResult) msg.obj; |
| 948 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 949 | TelephonyManager.CallForwardingInfoCallback callback = |
| 950 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 951 | request.argument).second; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 952 | if (ar.exception == null && ar.result != null) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 953 | CallForwardingInfo callForwardingInfo = null; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 954 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 955 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 956 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 957 | // any service for voice call. |
| 958 | if ((callForwardInfo.serviceClass |
| 959 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 960 | callForwardingInfo = new CallForwardingInfo(true, |
| 961 | callForwardInfo.reason, |
| 962 | callForwardInfo.number, |
| 963 | callForwardInfo.timeSeconds); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 964 | break; |
| 965 | } |
| 966 | } |
| 967 | // Didn't find a call forward info for voice call. |
| 968 | if (callForwardingInfo == null) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 969 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 970 | 0 /* reason */, null /* number */, 0 /* timeout */); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 971 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 972 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 973 | } else { |
| 974 | if (ar.result == null) { |
| 975 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 976 | } |
| 977 | if (ar.exception != null) { |
| 978 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 979 | } |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 980 | int errorCode = TelephonyManager |
| 981 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 982 | if (ar.exception instanceof CommandException) { |
| 983 | CommandException.Error error = |
| 984 | ((CommandException) (ar.exception)).getCommandError(); |
| 985 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 986 | errorCode = TelephonyManager |
| 987 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 988 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 989 | errorCode = TelephonyManager |
| 990 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 991 | } |
| 992 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 993 | callback.onError(errorCode); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 994 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 995 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 996 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 997 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 998 | case CMD_SET_CALL_FORWARDING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 999 | request = (MainThreadRequest) msg.obj; |
| 1000 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1001 | request = (MainThreadRequest) msg.obj; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1002 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1003 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1004 | request.argument).first; |
| 1005 | request.phone.setCallForwardingOption( |
| 1006 | callForwardingInfoToSet.isEnabled() |
| 1007 | ? CommandsInterface.CF_ACTION_ENABLE |
| 1008 | : CommandsInterface.CF_ACTION_DISABLE, |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1009 | callForwardingInfoToSet.getReason(), |
| 1010 | callForwardingInfoToSet.getNumber(), |
| 1011 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1012 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1013 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1014 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1015 | case EVENT_SET_CALL_FORWARDING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1016 | ar = (AsyncResult) msg.obj; |
| 1017 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1018 | Consumer<Integer> callback = |
| 1019 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1020 | request.argument).second; |
| 1021 | if (ar.exception != null) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1022 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1023 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1024 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1025 | if (ar.exception instanceof CommandException) { |
| 1026 | CommandException.Error error = |
| 1027 | ((CommandException) (ar.exception)).getCommandError(); |
| 1028 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1029 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1030 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1031 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1032 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1033 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1034 | } |
| 1035 | } |
| 1036 | callback.accept(errorCode); |
| 1037 | } else { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1038 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1039 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1040 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1041 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1042 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1043 | case CMD_GET_CALL_WAITING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1044 | request = (MainThreadRequest) msg.obj; |
| 1045 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1046 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1047 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1048 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1049 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1050 | case EVENT_GET_CALL_WAITING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1051 | ar = (AsyncResult) msg.obj; |
| 1052 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1053 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1054 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1055 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1056 | int[] callForwardResults = (int[]) ar.result; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1057 | // Service Class is a bit mask per 3gpp 27.007. |
| 1058 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1059 | if (callForwardResults.length > 1 |
| 1060 | && ((callForwardResults[1] |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1061 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1062 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1063 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1064 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1065 | } else { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1066 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1067 | } |
| 1068 | } else { |
| 1069 | if (ar.result == null) { |
| 1070 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1071 | } |
| 1072 | if (ar.exception != null) { |
| 1073 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1074 | } |
| 1075 | if (ar.exception instanceof CommandException) { |
| 1076 | CommandException.Error error = |
| 1077 | ((CommandException) (ar.exception)).getCommandError(); |
| 1078 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1079 | callForwardingStatus = |
| 1080 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1081 | } |
| 1082 | } |
| 1083 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1084 | callback.accept(callForwardingStatus); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1085 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1086 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1087 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1088 | case CMD_SET_CALL_WAITING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1089 | request = (MainThreadRequest) msg.obj; |
| 1090 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1091 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1092 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1093 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1094 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1095 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1096 | case EVENT_SET_CALL_WAITING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1097 | ar = (AsyncResult) msg.obj; |
| 1098 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1099 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1100 | Consumer<Integer> callback = |
| 1101 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1102 | if (ar.exception != null) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1103 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1104 | if (ar.exception instanceof CommandException) { |
| 1105 | CommandException.Error error = |
| 1106 | ((CommandException) (ar.exception)).getCommandError(); |
| 1107 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1108 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1109 | } else { |
| 1110 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1111 | } |
| 1112 | } else { |
| 1113 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1114 | } |
| 1115 | } else { |
| 1116 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1117 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1118 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1119 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1120 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1121 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1122 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1123 | ar = (AsyncResult) msg.obj; |
| 1124 | request = (MainThreadRequest) ar.userObj; |
| 1125 | CellNetworkScanResult cellScanResult; |
| 1126 | if (ar.exception == null && ar.result != null) { |
| 1127 | cellScanResult = new CellNetworkScanResult( |
| 1128 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1129 | (List<OperatorInfo>) ar.result); |
| 1130 | } else { |
| 1131 | if (ar.result == null) { |
| 1132 | loge("getCellNetworkScanResults: Empty response"); |
| 1133 | } |
| 1134 | if (ar.exception != null) { |
| 1135 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1136 | } |
| 1137 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1138 | if (ar.exception instanceof CommandException) { |
| 1139 | CommandException.Error error = |
| 1140 | ((CommandException) (ar.exception)).getCommandError(); |
| 1141 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1142 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1143 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1144 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1145 | } |
| 1146 | } |
| 1147 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1148 | } |
| 1149 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1150 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1151 | break; |
| 1152 | |
| 1153 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1154 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1155 | ManualNetworkSelectionArgument selArg = |
| 1156 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1157 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1158 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1159 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1160 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1161 | break; |
| 1162 | |
| 1163 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1164 | ar = (AsyncResult) msg.obj; |
| 1165 | request = (MainThreadRequest) ar.userObj; |
| 1166 | if (ar.exception == null) { |
| 1167 | request.result = true; |
| 1168 | } else { |
| 1169 | request.result = false; |
| 1170 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1171 | } |
| 1172 | notifyRequester(request); |
| 1173 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1174 | break; |
| 1175 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1176 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1177 | request = (MainThreadRequest) msg.obj; |
| 1178 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1179 | if (defaultPhone != null) { |
| 1180 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1181 | } else { |
| 1182 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1183 | Bundle bundle = new Bundle(); |
| 1184 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
| 1185 | new ModemActivityInfo(0, 0, 0, new int[0], 0)); |
| 1186 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1187 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1188 | break; |
| 1189 | |
| 1190 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 1191 | ar = (AsyncResult) msg.obj; |
| 1192 | request = (MainThreadRequest) ar.userObj; |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1193 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1194 | |
| 1195 | ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1196 | if (ar.exception == null && ar.result != null) { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1197 | // Update the last modem activity info and the result of the request. |
| 1198 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1199 | if (isModemActivityInfoValid(info)) { |
| 1200 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 1201 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1202 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1203 | .getTransmitTimeMillis(); |
| 1204 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1205 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1206 | } |
| 1207 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 1208 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1209 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1210 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1211 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1212 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1213 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1214 | info.getReceiveTimeMillis() |
| 1215 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1216 | } |
| 1217 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 1218 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1219 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1220 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1221 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1222 | } else { |
| 1223 | if (ar.result == null) { |
| 1224 | loge("queryModemActivityInfo: Empty response"); |
| 1225 | } else if (ar.exception instanceof CommandException) { |
| 1226 | loge("queryModemActivityInfo: CommandException: " + |
| 1227 | ar.exception); |
| 1228 | } else { |
| 1229 | loge("queryModemActivityInfo: Unknown exception"); |
| 1230 | } |
| 1231 | } |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1232 | Bundle bundle = new Bundle(); |
| 1233 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1234 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1235 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1236 | break; |
| 1237 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1238 | case CMD_SET_ALLOWED_CARRIERS: |
| 1239 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1240 | CarrierRestrictionRules argument = |
| 1241 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1242 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1243 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1244 | break; |
| 1245 | |
| 1246 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1247 | ar = (AsyncResult) msg.obj; |
| 1248 | request = (MainThreadRequest) ar.userObj; |
| 1249 | if (ar.exception == null && ar.result != null) { |
| 1250 | request.result = ar.result; |
| 1251 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1252 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1253 | if (ar.exception instanceof CommandException) { |
| 1254 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1255 | CommandException.Error error = |
| 1256 | ((CommandException) (ar.exception)).getCommandError(); |
| 1257 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1258 | request.result = |
| 1259 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1260 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1261 | } else { |
| 1262 | loge("setAllowedCarriers: Unknown exception"); |
| 1263 | } |
| 1264 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1265 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1266 | break; |
| 1267 | |
| 1268 | case CMD_GET_ALLOWED_CARRIERS: |
| 1269 | request = (MainThreadRequest) msg.obj; |
| 1270 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1271 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1272 | break; |
| 1273 | |
| 1274 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1275 | ar = (AsyncResult) msg.obj; |
| 1276 | request = (MainThreadRequest) ar.userObj; |
| 1277 | if (ar.exception == null && ar.result != null) { |
| 1278 | request.result = ar.result; |
| 1279 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1280 | request.result = new IllegalStateException( |
| 1281 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1282 | if (ar.result == null) { |
| 1283 | loge("getAllowedCarriers: Empty response"); |
| 1284 | } else if (ar.exception instanceof CommandException) { |
| 1285 | loge("getAllowedCarriers: CommandException: " + |
| 1286 | ar.exception); |
| 1287 | } else { |
| 1288 | loge("getAllowedCarriers: Unknown exception"); |
| 1289 | } |
| 1290 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1291 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1292 | break; |
| 1293 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1294 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1295 | ar = (AsyncResult) msg.obj; |
| 1296 | request = (MainThreadRequest) ar.userObj; |
| 1297 | if (ar.exception == null && ar.result != null) { |
| 1298 | request.result = ar.result; |
| 1299 | } else { |
| 1300 | request.result = new IllegalArgumentException( |
| 1301 | "Failed to retrieve Forbidden Plmns"); |
| 1302 | if (ar.result == null) { |
| 1303 | loge("getForbiddenPlmns: Empty response"); |
| 1304 | } else { |
| 1305 | loge("getForbiddenPlmns: Unknown exception"); |
| 1306 | } |
| 1307 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1308 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1309 | break; |
| 1310 | |
| 1311 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1312 | request = (MainThreadRequest) msg.obj; |
| 1313 | uiccCard = getUiccCardFromRequest(request); |
| 1314 | if (uiccCard == null) { |
| 1315 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1316 | request.result = new IllegalArgumentException( |
| 1317 | "getForbiddenPlmns() UiccCard is null"); |
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 | } |
| 1321 | Integer appType = (Integer) request.argument; |
| 1322 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1323 | if (uiccApp == null) { |
| 1324 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1325 | + appType); |
| 1326 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1327 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1328 | break; |
| 1329 | } else { |
| 1330 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1331 | + " specified type -- " + appType); |
| 1332 | } |
| 1333 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1334 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1335 | onCompleted); |
| 1336 | break; |
| 1337 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1338 | case CMD_SWITCH_SLOTS: |
| 1339 | request = (MainThreadRequest) msg.obj; |
| 1340 | int[] physicalSlots = (int[]) request.argument; |
| 1341 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1342 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1343 | break; |
| 1344 | |
| 1345 | case EVENT_SWITCH_SLOTS_DONE: |
| 1346 | ar = (AsyncResult) msg.obj; |
| 1347 | request = (MainThreadRequest) ar.userObj; |
| 1348 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1349 | notifyRequester(request); |
| 1350 | break; |
| 1351 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1352 | request = (MainThreadRequest) msg.obj; |
| 1353 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1354 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1355 | break; |
| 1356 | |
| 1357 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1358 | ar = (AsyncResult) msg.obj; |
| 1359 | request = (MainThreadRequest) ar.userObj; |
| 1360 | if (ar.exception != null) { |
| 1361 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1362 | } else { |
| 1363 | int mode = ((int[]) ar.result)[0]; |
| 1364 | if (mode == 0) { |
| 1365 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1366 | } else { |
| 1367 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1368 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1369 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1370 | notifyRequester(request); |
| 1371 | break; |
| 1372 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1373 | request = (MainThreadRequest) msg.obj; |
| 1374 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1375 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1376 | break; |
| 1377 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1378 | ar = (AsyncResult) msg.obj; |
| 1379 | request = (MainThreadRequest) ar.userObj; |
| 1380 | if (ar.exception != null) { |
| 1381 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1382 | } else { |
| 1383 | request.result = ((int[]) ar.result)[0]; |
| 1384 | } |
| 1385 | notifyRequester(request); |
| 1386 | break; |
| 1387 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1388 | request = (MainThreadRequest) msg.obj; |
| 1389 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1390 | int mode = (int) request.argument; |
| 1391 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1392 | break; |
| 1393 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1394 | ar = (AsyncResult) msg.obj; |
| 1395 | request = (MainThreadRequest) ar.userObj; |
| 1396 | request.result = ar.exception == null; |
| 1397 | notifyRequester(request); |
| 1398 | break; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1399 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1400 | request = (MainThreadRequest) msg.obj; |
| 1401 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1402 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1403 | break; |
| 1404 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1405 | ar = (AsyncResult) msg.obj; |
| 1406 | request = (MainThreadRequest) ar.userObj; |
| 1407 | if (ar.exception != null) { |
| 1408 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1409 | } else { |
| 1410 | request.result = ((int[]) ar.result)[0]; |
| 1411 | } |
| 1412 | notifyRequester(request); |
| 1413 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1414 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1415 | request = (MainThreadRequest) msg.obj; |
| 1416 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1417 | int subscriptionMode = (int) request.argument; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1418 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1419 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1420 | break; |
| 1421 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1422 | ar = (AsyncResult) msg.obj; |
| 1423 | request = (MainThreadRequest) ar.userObj; |
| 1424 | request.result = ar.exception == null; |
| 1425 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1426 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1427 | case CMD_GET_ALL_CELL_INFO: |
| 1428 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1429 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1430 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1431 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1432 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1433 | ar = (AsyncResult) msg.obj; |
| 1434 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1435 | // If a timeout occurs, the response will be null |
| 1436 | request.result = (ar.exception == null && ar.result != null) |
| 1437 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1438 | synchronized (request) { |
| 1439 | request.notifyAll(); |
| 1440 | } |
| 1441 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1442 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1443 | request = (MainThreadRequest) msg.obj; |
| 1444 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1445 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1446 | break; |
| 1447 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1448 | ar = (AsyncResult) msg.obj; |
| 1449 | request = (MainThreadRequest) ar.userObj; |
| 1450 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1451 | try { |
| 1452 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1453 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1454 | cb.onError( |
| 1455 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1456 | ar.exception.getClass().getName(), |
| 1457 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1458 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1459 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1460 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1461 | } else { |
| 1462 | // use the result as returned |
| 1463 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1464 | } |
| 1465 | } catch (RemoteException re) { |
| 1466 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1467 | } |
| 1468 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1469 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1470 | request = (MainThreadRequest) msg.obj; |
| 1471 | WorkSource ws = (WorkSource) request.argument; |
| 1472 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1473 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1474 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1475 | } |
| 1476 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1477 | ar = (AsyncResult) msg.obj; |
| 1478 | request = (MainThreadRequest) ar.userObj; |
| 1479 | if (ar.exception == null) { |
| 1480 | request.result = ar.result; |
| 1481 | } else { |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1482 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1483 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1484 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1485 | } |
| 1486 | |
| 1487 | synchronized (request) { |
| 1488 | request.notifyAll(); |
| 1489 | } |
| 1490 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1491 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1492 | case CMD_MODEM_REBOOT: |
| 1493 | request = (MainThreadRequest) msg.obj; |
| 1494 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1495 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1496 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1497 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1498 | handleNullReturnEvent(msg, "rebootModem"); |
| 1499 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1500 | case CMD_REQUEST_ENABLE_MODEM: |
| 1501 | request = (MainThreadRequest) msg.obj; |
| 1502 | boolean enable = (boolean) request.argument; |
| 1503 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1504 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1505 | PhoneConfigurationManager.getInstance() |
| 1506 | .enablePhone(request.phone, enable, onCompleted); |
| 1507 | break; |
| 1508 | case EVENT_ENABLE_MODEM_DONE: |
| 1509 | ar = (AsyncResult) msg.obj; |
| 1510 | request = (MainThreadRequest) ar.userObj; |
| 1511 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1512 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1513 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1514 | if ((boolean) request.result) { |
| 1515 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1516 | updateModemStateMetrics(); |
| 1517 | } else { |
| 1518 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1519 | + ar.exception); |
| 1520 | } |
| 1521 | notifyRequester(request); |
| 1522 | break; |
| 1523 | case CMD_GET_MODEM_STATUS: |
| 1524 | request = (MainThreadRequest) msg.obj; |
| 1525 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1526 | PhoneConfigurationManager.getInstance() |
| 1527 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1528 | break; |
| 1529 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1530 | ar = (AsyncResult) msg.obj; |
| 1531 | request = (MainThreadRequest) ar.userObj; |
| 1532 | int id = request.phone.getPhoneId(); |
| 1533 | if (ar.exception == null && ar.result != null) { |
| 1534 | request.result = ar.result; |
| 1535 | //update the cache as modem status has changed |
| 1536 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1537 | (boolean) request.result); |
| 1538 | } else { |
| 1539 | // Return true if modem status cannot be retrieved. For most cases, |
| 1540 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1541 | // and disable modem are not supported. Modem is always on. |
| 1542 | // TODO: this should be fixed in R to support a third |
| 1543 | // status UNKNOWN b/131631629 |
| 1544 | request.result = true; |
| 1545 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1546 | + ar.exception); |
| 1547 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1548 | notifyRequester(request); |
| 1549 | break; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1550 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1551 | request = (MainThreadRequest) msg.obj; |
| 1552 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1553 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1554 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1555 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1556 | break; |
| 1557 | } |
| 1558 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1559 | ar = (AsyncResult) msg.obj; |
| 1560 | request = (MainThreadRequest) ar.userObj; |
| 1561 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1562 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1563 | args.second.accept(ar.exception == null); |
| 1564 | notifyRequester(request); |
| 1565 | break; |
| 1566 | } |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1567 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1568 | request = (MainThreadRequest) msg.obj; |
| 1569 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1570 | Phone phone = getPhoneFromRequest(request); |
| 1571 | if (phone != null) { |
| 1572 | phone.getSystemSelectionChannels(onCompleted); |
| 1573 | } else { |
| 1574 | loge("getSystemSelectionChannels: No phone object"); |
| 1575 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1576 | notifyRequester(request); |
| 1577 | } |
| 1578 | break; |
| 1579 | } |
| 1580 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1581 | ar = (AsyncResult) msg.obj; |
| 1582 | request = (MainThreadRequest) ar.userObj; |
| 1583 | if (ar.exception == null && ar.result != null) { |
| 1584 | request.result = ar.result; |
| 1585 | } else { |
| 1586 | request.result = new IllegalArgumentException( |
| 1587 | "Failed to retrieve system selection channels"); |
| 1588 | if (ar.result == null) { |
| 1589 | loge("getSystemSelectionChannels: Empty response"); |
| 1590 | } else { |
| 1591 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1592 | } |
| 1593 | } |
| 1594 | notifyRequester(request); |
| 1595 | break; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1596 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1597 | ar = (AsyncResult) msg.obj; |
| 1598 | request = (MainThreadRequest) ar.userObj; |
| 1599 | if (ar.exception == null && ar.result != null) { |
| 1600 | request.result = ar.result; |
| 1601 | } else { |
| 1602 | request.result = -1; |
| 1603 | loge("Failed to set Forbidden Plmns"); |
| 1604 | if (ar.result == null) { |
| 1605 | loge("setForbidenPlmns: Empty response"); |
| 1606 | } else if (ar.exception != null) { |
| 1607 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1608 | request.result = -1; |
| 1609 | } else { |
| 1610 | loge("setForbiddenPlmns: Unknown exception"); |
| 1611 | } |
| 1612 | } |
| 1613 | notifyRequester(request); |
| 1614 | break; |
| 1615 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1616 | request = (MainThreadRequest) msg.obj; |
| 1617 | uiccCard = getUiccCardFromRequest(request); |
| 1618 | if (uiccCard == null) { |
| 1619 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1620 | request.result = -1; |
| 1621 | notifyRequester(request); |
| 1622 | break; |
| 1623 | } |
| 1624 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1625 | (Pair<Integer, List<String>>) request.argument; |
| 1626 | appType = setFplmnsArgs.first; |
| 1627 | List<String> fplmns = setFplmnsArgs.second; |
| 1628 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1629 | if (uiccApp == null) { |
| 1630 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1631 | request.result = -1; |
| 1632 | loge("Failed to get UICC App"); |
| 1633 | notifyRequester(request); |
| 1634 | } else { |
| 1635 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1636 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1637 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1638 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1639 | break; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1640 | case CMD_ERASE_MODEM_CONFIG: |
| 1641 | request = (MainThreadRequest) msg.obj; |
| 1642 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1643 | defaultPhone.eraseModemConfig(onCompleted); |
| 1644 | break; |
| 1645 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1646 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1647 | break; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1648 | |
| 1649 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1650 | request = (MainThreadRequest) msg.obj; |
| 1651 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1652 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1653 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1654 | changed.first, changed.second, onCompleted); |
| 1655 | break; |
| 1656 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1657 | ar = (AsyncResult) msg.obj; |
| 1658 | request = (MainThreadRequest) ar.userObj; |
| 1659 | if (ar.exception == null) { |
| 1660 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1661 | } else { |
| 1662 | request.result = msg.arg1; |
| 1663 | } |
| 1664 | notifyRequester(request); |
| 1665 | break; |
| 1666 | |
| 1667 | case CMD_SET_ICC_LOCK_ENABLED: |
| 1668 | request = (MainThreadRequest) msg.obj; |
| 1669 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1670 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1671 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1672 | enabled.first, enabled.second, onCompleted); |
| 1673 | break; |
| 1674 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1675 | ar = (AsyncResult) msg.obj; |
| 1676 | request = (MainThreadRequest) ar.userObj; |
| 1677 | if (ar.exception == null) { |
| 1678 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1679 | } else { |
| 1680 | request.result = msg.arg1; |
| 1681 | } |
| 1682 | notifyRequester(request); |
| 1683 | break; |
| 1684 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1685 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1686 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1687 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1688 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1689 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1690 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1691 | break; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame^] | 1692 | |
| 1693 | case CMD_SET_DATA_THROTTLING: { |
| 1694 | request = (MainThreadRequest) msg.obj; |
| 1695 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1696 | DataThrottlingRequest dataThrottlingRequest = |
| 1697 | (DataThrottlingRequest) request.argument; |
| 1698 | Phone phone = getPhoneFromRequest(request); |
| 1699 | if (phone != null) { |
| 1700 | phone.setDataThrottling(onCompleted, |
| 1701 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1702 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1703 | } else { |
| 1704 | loge("setDataThrottling: No phone object"); |
| 1705 | request.result = |
| 1706 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1707 | notifyRequester(request); |
| 1708 | } |
| 1709 | |
| 1710 | break; |
| 1711 | } |
| 1712 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1713 | ar = (AsyncResult) msg.obj; |
| 1714 | request = (MainThreadRequest) ar.userObj; |
| 1715 | |
| 1716 | if (ar.exception == null) { |
| 1717 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1718 | } else if (ar.exception instanceof CommandException) { |
| 1719 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1720 | CommandException.Error error = |
| 1721 | ((CommandException) (ar.exception)).getCommandError(); |
| 1722 | |
| 1723 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1724 | request.result = TelephonyManager |
| 1725 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1726 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1727 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
| 1728 | } else { |
| 1729 | request.result = |
| 1730 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1731 | } |
| 1732 | } else { |
| 1733 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1734 | } |
| 1735 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1736 | notifyRequester(request); |
| 1737 | break; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1738 | default: |
| 1739 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1740 | break; |
| 1741 | } |
| 1742 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1743 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1744 | private void notifyRequester(MainThreadRequest request) { |
| 1745 | synchronized (request) { |
| 1746 | request.notifyAll(); |
| 1747 | } |
| 1748 | } |
| 1749 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1750 | private void handleNullReturnEvent(Message msg, String command) { |
| 1751 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1752 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1753 | if (ar.exception == null) { |
| 1754 | request.result = true; |
| 1755 | } else { |
| 1756 | request.result = false; |
| 1757 | if (ar.exception instanceof CommandException) { |
| 1758 | loge(command + ": CommandException: " + ar.exception); |
| 1759 | } else { |
| 1760 | loge(command + ": Unknown exception"); |
| 1761 | } |
| 1762 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1763 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1764 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1765 | } |
| 1766 | |
| 1767 | /** |
| 1768 | * Posts the specified command to be executed on the main thread, |
| 1769 | * waits for the request to complete, and returns the result. |
| 1770 | * @see #sendRequestAsync |
| 1771 | */ |
| 1772 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1773 | return sendRequest( |
| 1774 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1775 | } |
| 1776 | |
| 1777 | /** |
| 1778 | * Posts the specified command to be executed on the main thread, |
| 1779 | * waits for the request to complete, and returns the result. |
| 1780 | * @see #sendRequestAsync |
| 1781 | */ |
| 1782 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1783 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1784 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1785 | } |
| 1786 | |
| 1787 | /** |
| 1788 | * Posts the specified command to be executed on the main thread, |
| 1789 | * waits for the request to complete, and returns the result. |
| 1790 | * @see #sendRequestAsync |
| 1791 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1792 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1793 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1794 | } |
| 1795 | |
| 1796 | /** |
| 1797 | * Posts the specified command to be executed on the main thread, |
| 1798 | * waits for the request to complete, and returns the result. |
| 1799 | * @see #sendRequestAsync |
| 1800 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1801 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1802 | return sendRequest(command, argument, subId, null, workSource); |
| 1803 | } |
| 1804 | |
| 1805 | /** |
| 1806 | * Posts the specified command to be executed on the main thread, |
| 1807 | * waits for the request to complete, and returns the result. |
| 1808 | * @see #sendRequestAsync |
| 1809 | */ |
| 1810 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1811 | return sendRequest( |
| 1812 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1813 | } |
| 1814 | |
| 1815 | /** |
| 1816 | * Posts the specified command to be executed on the main thread, |
| 1817 | * waits for the request to complete, and returns the result. |
| 1818 | * @see #sendRequestAsync |
| 1819 | */ |
| 1820 | private Object sendRequest( |
| 1821 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1822 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1823 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1824 | } |
| 1825 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1826 | MainThreadRequest request = null; |
| 1827 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1828 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1829 | } else if (phone != null) { |
| 1830 | request = new MainThreadRequest(argument, phone, workSource); |
| 1831 | } else { |
| 1832 | request = new MainThreadRequest(argument, subId, workSource); |
| 1833 | } |
| 1834 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1835 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1836 | msg.sendToTarget(); |
| 1837 | |
| 1838 | // Wait for the request to complete |
| 1839 | synchronized (request) { |
| 1840 | while (request.result == null) { |
| 1841 | try { |
| 1842 | request.wait(); |
| 1843 | } catch (InterruptedException e) { |
| 1844 | // Do nothing, go back and wait until the request is complete |
| 1845 | } |
| 1846 | } |
| 1847 | } |
| 1848 | return request.result; |
| 1849 | } |
| 1850 | |
| 1851 | /** |
| 1852 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1853 | * Posts the specified command to be executed on the main thread, and |
| 1854 | * returns immediately. |
| 1855 | * @see #sendRequest |
| 1856 | */ |
| 1857 | private void sendRequestAsync(int command) { |
| 1858 | mMainThreadHandler.sendEmptyMessage(command); |
| 1859 | } |
| 1860 | |
| 1861 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1862 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1863 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1864 | */ |
| 1865 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1866 | sendRequestAsync(command, argument, null, null); |
| 1867 | } |
| 1868 | |
| 1869 | /** |
| 1870 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1871 | * @see {@link #sendRequest(int,Object)} |
| 1872 | */ |
| 1873 | private void sendRequestAsync( |
| 1874 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1875 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1876 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1877 | msg.sendToTarget(); |
| 1878 | } |
| 1879 | |
| 1880 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1881 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1882 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1883 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1884 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1885 | synchronized (PhoneInterfaceManager.class) { |
| 1886 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1887 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1888 | } else { |
| 1889 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1890 | } |
| 1891 | return sInstance; |
| 1892 | } |
| 1893 | } |
| 1894 | |
| 1895 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 1896 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1897 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1898 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1899 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1900 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1901 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1902 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1903 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1904 | mTelephonySharedPreferences = |
| 1905 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1906 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1907 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 1908 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1909 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1910 | publish(); |
| 1911 | } |
| 1912 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1913 | private Phone getDefaultPhone() { |
| 1914 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1915 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1916 | } |
| 1917 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1918 | private void publish() { |
| 1919 | if (DBG) log("publish: " + this); |
| 1920 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 1921 | TelephonyFrameworkInitializer |
| 1922 | .getTelephonyServiceManager() |
| 1923 | .getTelephonyServiceRegisterer() |
| 1924 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1925 | } |
| 1926 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1927 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1928 | if (request.phone != null) { |
| 1929 | return request.phone; |
| 1930 | } else { |
| 1931 | return getPhoneFromSubId(request.subId); |
| 1932 | } |
| 1933 | } |
| 1934 | |
| 1935 | private Phone getPhoneFromSubId(int subId) { |
| 1936 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 1937 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1938 | } |
| 1939 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 1940 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 1941 | Phone phone = getPhoneFromRequest(request); |
| 1942 | return phone == null ? null : |
| 1943 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 1944 | } |
| 1945 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1946 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1947 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 1948 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1949 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1950 | |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1951 | private void sendEraseModemConfig(Phone phone) { |
| 1952 | if (phone != null) { |
| 1953 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 1954 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 1955 | final long identity = Binder.clearCallingIdentity(); |
| 1956 | try { |
| 1957 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 1958 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 1959 | } finally { |
| 1960 | Binder.restoreCallingIdentity(identity); |
| 1961 | } |
| 1962 | } |
| 1963 | } |
| 1964 | |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 1965 | private boolean isImsAvailableOnDevice() { |
| 1966 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 1967 | if (pm == null) { |
| 1968 | // For some reason package manger is not available.. This will fail internally anyway, |
| 1969 | // so do not throw error and allow. |
| 1970 | return true; |
| 1971 | } |
| 1972 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 1973 | } |
| 1974 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1975 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 1976 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1977 | } |
| 1978 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 1979 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1980 | if (DBG) log("dial: " + number); |
| 1981 | // No permission check needed here: This is just a wrapper around the |
| 1982 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 1983 | // the UI before it does anything. |
| 1984 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1985 | final long identity = Binder.clearCallingIdentity(); |
| 1986 | try { |
| 1987 | String url = createTelUrl(number); |
| 1988 | if (url == null) { |
| 1989 | return; |
| 1990 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1991 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 1992 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 1993 | PhoneConstants.State state = mCM.getState(subId); |
| 1994 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 1995 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 1996 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1997 | mApp.startActivity(intent); |
| 1998 | } |
| 1999 | } finally { |
| 2000 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2001 | } |
| 2002 | } |
| 2003 | |
| 2004 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2005 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2006 | } |
| 2007 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2008 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2009 | if (DBG) log("call: " + number); |
| 2010 | |
| 2011 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2012 | // need to do a permission check since we're calling startActivity() |
| 2013 | // from the context of the phone app. |
| 2014 | enforceCallPermission(); |
| 2015 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2016 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2017 | != AppOpsManager.MODE_ALLOWED) { |
| 2018 | return; |
| 2019 | } |
| 2020 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2021 | final long identity = Binder.clearCallingIdentity(); |
| 2022 | try { |
| 2023 | String url = createTelUrl(number); |
| 2024 | if (url == null) { |
| 2025 | return; |
| 2026 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2027 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2028 | boolean isValid = false; |
| 2029 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2030 | if (slist != null) { |
| 2031 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2032 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2033 | isValid = true; |
| 2034 | break; |
| 2035 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2036 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2037 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2038 | if (!isValid) { |
| 2039 | return; |
| 2040 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2041 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2042 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2043 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2044 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2045 | mApp.startActivity(intent); |
| 2046 | } finally { |
| 2047 | Binder.restoreCallingIdentity(identity); |
| 2048 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2049 | } |
| 2050 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2051 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2052 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2053 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2054 | } |
| 2055 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2056 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2057 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2058 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2059 | } |
| 2060 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2061 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2062 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2063 | |
| 2064 | final long identity = Binder.clearCallingIdentity(); |
| 2065 | try { |
| 2066 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 2067 | checkSimPin.start(); |
| 2068 | return checkSimPin.unlockSim(null, pin); |
| 2069 | } finally { |
| 2070 | Binder.restoreCallingIdentity(identity); |
| 2071 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2072 | } |
| 2073 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2074 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2075 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2076 | |
| 2077 | final long identity = Binder.clearCallingIdentity(); |
| 2078 | try { |
| 2079 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 2080 | checkSimPuk.start(); |
| 2081 | return checkSimPuk.unlockSim(puk, pin); |
| 2082 | } finally { |
| 2083 | Binder.restoreCallingIdentity(identity); |
| 2084 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2085 | } |
| 2086 | |
| 2087 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2088 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2089 | * a synchronous one. |
| 2090 | */ |
| 2091 | private static class UnlockSim extends Thread { |
| 2092 | |
| 2093 | private final IccCard mSimCard; |
| 2094 | |
| 2095 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2096 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2097 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2098 | |
| 2099 | // For replies from SimCard interface |
| 2100 | private Handler mHandler; |
| 2101 | |
| 2102 | // For async handler to identify request type |
| 2103 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2104 | |
| 2105 | public UnlockSim(IccCard simCard) { |
| 2106 | mSimCard = simCard; |
| 2107 | } |
| 2108 | |
| 2109 | @Override |
| 2110 | public void run() { |
| 2111 | Looper.prepare(); |
| 2112 | synchronized (UnlockSim.this) { |
| 2113 | mHandler = new Handler() { |
| 2114 | @Override |
| 2115 | public void handleMessage(Message msg) { |
| 2116 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2117 | switch (msg.what) { |
| 2118 | case SUPPLY_PIN_COMPLETE: |
| 2119 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2120 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2121 | mRetryCount = msg.arg1; |
| 2122 | if (ar.exception != null) { |
| 2123 | if (ar.exception instanceof CommandException && |
| 2124 | ((CommandException)(ar.exception)).getCommandError() |
| 2125 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2126 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2127 | } //When UiccCardApp dispose,handle message and return exception |
| 2128 | else if (ar.exception instanceof CommandException && |
| 2129 | ((CommandException) (ar.exception)).getCommandError() |
| 2130 | == CommandException.Error.ABORTED) { |
| 2131 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2132 | } else { |
| 2133 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2134 | } |
| 2135 | } else { |
| 2136 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2137 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2138 | mDone = true; |
| 2139 | UnlockSim.this.notifyAll(); |
| 2140 | } |
| 2141 | break; |
| 2142 | } |
| 2143 | } |
| 2144 | }; |
| 2145 | UnlockSim.this.notifyAll(); |
| 2146 | } |
| 2147 | Looper.loop(); |
| 2148 | } |
| 2149 | |
| 2150 | /* |
| 2151 | * Use PIN or PUK to unlock SIM card |
| 2152 | * |
| 2153 | * If PUK is null, unlock SIM card with PIN |
| 2154 | * |
| 2155 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2156 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2157 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2158 | |
| 2159 | while (mHandler == null) { |
| 2160 | try { |
| 2161 | wait(); |
| 2162 | } catch (InterruptedException e) { |
| 2163 | Thread.currentThread().interrupt(); |
| 2164 | } |
| 2165 | } |
| 2166 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2167 | |
| 2168 | if (puk == null) { |
| 2169 | mSimCard.supplyPin(pin, callback); |
| 2170 | } else { |
| 2171 | mSimCard.supplyPuk(puk, pin, callback); |
| 2172 | } |
| 2173 | |
| 2174 | while (!mDone) { |
| 2175 | try { |
| 2176 | Log.d(LOG_TAG, "wait for done"); |
| 2177 | wait(); |
| 2178 | } catch (InterruptedException e) { |
| 2179 | // Restore the interrupted status |
| 2180 | Thread.currentThread().interrupt(); |
| 2181 | } |
| 2182 | } |
| 2183 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2184 | int[] resultArray = new int[2]; |
| 2185 | resultArray[0] = mResult; |
| 2186 | resultArray[1] = mRetryCount; |
| 2187 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2188 | } |
| 2189 | } |
| 2190 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2191 | /** |
| 2192 | * This method has been removed due to privacy and stability concerns. |
| 2193 | */ |
| 2194 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2195 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2196 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2197 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2198 | } |
| 2199 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2200 | @Override |
| 2201 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2202 | mApp.getSystemService(AppOpsManager.class) |
| 2203 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2204 | |
| 2205 | final int targetSdk = getTargetSdk(callingPackage); |
| 2206 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2207 | // Callers targeting S have no business invoking this method. |
| 2208 | return; |
| 2209 | } |
| 2210 | |
| 2211 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2212 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2213 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2214 | .setCallingPackage(callingPackage) |
| 2215 | .setCallingFeatureId(null) |
| 2216 | .setCallingPid(Binder.getCallingPid()) |
| 2217 | .setCallingUid(Binder.getCallingUid()) |
| 2218 | .setMethod("updateServiceLocation") |
| 2219 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2220 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2221 | .build()); |
| 2222 | // Apps that lack location permission have no business calling this method; |
| 2223 | // however, because no permission was declared in the public API, denials must |
| 2224 | // all be "soft". |
| 2225 | switch (locationResult) { |
| 2226 | case DENIED_HARD: /* fall through */ |
| 2227 | case DENIED_SOFT: |
| 2228 | return; |
| 2229 | } |
| 2230 | |
| 2231 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2232 | final long identity = Binder.clearCallingIdentity(); |
| 2233 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2234 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2235 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2236 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2237 | } |
| 2238 | } finally { |
| 2239 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2240 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2241 | } |
| 2242 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2243 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2244 | @Override |
| 2245 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2246 | return isRadioOnWithFeature(callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2247 | } |
| 2248 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2249 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2250 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2251 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2252 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2253 | callingFeatureId); |
| 2254 | } |
| 2255 | |
| 2256 | @Deprecated |
| 2257 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2258 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2259 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
| 2260 | } |
| 2261 | |
| 2262 | @Override |
| 2263 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2264 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2265 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2266 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2267 | return false; |
| 2268 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2269 | |
| 2270 | final long identity = Binder.clearCallingIdentity(); |
| 2271 | try { |
| 2272 | return isRadioOnForSubscriber(subId); |
| 2273 | } finally { |
| 2274 | Binder.restoreCallingIdentity(identity); |
| 2275 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2276 | } |
| 2277 | |
| 2278 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2279 | final long identity = Binder.clearCallingIdentity(); |
| 2280 | try { |
| 2281 | final Phone phone = getPhone(subId); |
| 2282 | if (phone != null) { |
| 2283 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2284 | } else { |
| 2285 | return false; |
| 2286 | } |
| 2287 | } finally { |
| 2288 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2289 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2290 | } |
| 2291 | |
| 2292 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2293 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2294 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2295 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2296 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2297 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2298 | |
| 2299 | final long identity = Binder.clearCallingIdentity(); |
| 2300 | try { |
| 2301 | final Phone phone = getPhone(subId); |
| 2302 | if (phone != null) { |
| 2303 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2304 | } |
| 2305 | } finally { |
| 2306 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2307 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2308 | } |
| 2309 | |
| 2310 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2311 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2312 | } |
| 2313 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2314 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2315 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2316 | |
| 2317 | final long identity = Binder.clearCallingIdentity(); |
| 2318 | try { |
| 2319 | final Phone phone = getPhone(subId); |
| 2320 | if (phone == null) { |
| 2321 | return false; |
| 2322 | } |
| 2323 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2324 | toggleRadioOnOffForSubscriber(subId); |
| 2325 | } |
| 2326 | return true; |
| 2327 | } finally { |
| 2328 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2329 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2330 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2331 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2332 | public boolean needMobileRadioShutdown() { |
Shuo Qian | afeaf7d | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2333 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2334 | /* |
| 2335 | * If any of the Radios are available, it will need to be |
| 2336 | * shutdown. So return true if any Radio is available. |
| 2337 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2338 | final long identity = Binder.clearCallingIdentity(); |
| 2339 | try { |
| 2340 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2341 | Phone phone = PhoneFactory.getPhone(i); |
| 2342 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2343 | } |
| 2344 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2345 | return false; |
| 2346 | } finally { |
| 2347 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2348 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2349 | } |
| 2350 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2351 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2352 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2353 | enforceModifyPermission(); |
| 2354 | |
| 2355 | final long identity = Binder.clearCallingIdentity(); |
| 2356 | try { |
| 2357 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2358 | logv("Shutting down Phone " + i); |
| 2359 | shutdownRadioUsingPhoneId(i); |
| 2360 | } |
| 2361 | } finally { |
| 2362 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2363 | } |
| 2364 | } |
| 2365 | |
| 2366 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2367 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2368 | if (phone != null && phone.isRadioAvailable()) { |
| 2369 | phone.shutdownRadio(); |
| 2370 | } |
| 2371 | } |
| 2372 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2373 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2374 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2375 | |
| 2376 | final long identity = Binder.clearCallingIdentity(); |
| 2377 | try { |
| 2378 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2379 | if (defaultPhone != null) { |
| 2380 | defaultPhone.setRadioPower(turnOn); |
| 2381 | return true; |
| 2382 | } else { |
| 2383 | loge("There's no default phone."); |
| 2384 | return false; |
| 2385 | } |
| 2386 | } finally { |
| 2387 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2388 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2389 | } |
| 2390 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2391 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2392 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2393 | |
| 2394 | final long identity = Binder.clearCallingIdentity(); |
| 2395 | try { |
| 2396 | final Phone phone = getPhone(subId); |
| 2397 | if (phone != null) { |
| 2398 | phone.setRadioPower(turnOn); |
| 2399 | return true; |
| 2400 | } else { |
| 2401 | return false; |
| 2402 | } |
| 2403 | } finally { |
| 2404 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2405 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2406 | } |
| 2407 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2408 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2409 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2410 | public boolean enableDataConnectivity() { |
| 2411 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2412 | |
| 2413 | final long identity = Binder.clearCallingIdentity(); |
| 2414 | try { |
| 2415 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2416 | final Phone phone = getPhone(subId); |
| 2417 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 2418 | phone.getDataEnabledSettings().setDataEnabled( |
| 2419 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2420 | return true; |
| 2421 | } else { |
| 2422 | return false; |
| 2423 | } |
| 2424 | } finally { |
| 2425 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2426 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2427 | } |
| 2428 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2429 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2430 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2431 | public boolean disableDataConnectivity() { |
| 2432 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2433 | |
| 2434 | final long identity = Binder.clearCallingIdentity(); |
| 2435 | try { |
| 2436 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2437 | final Phone phone = getPhone(subId); |
| 2438 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 2439 | phone.getDataEnabledSettings().setDataEnabled( |
| 2440 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2441 | return true; |
| 2442 | } else { |
| 2443 | return false; |
| 2444 | } |
| 2445 | } finally { |
| 2446 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2447 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2448 | } |
| 2449 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2450 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2451 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2452 | final long identity = Binder.clearCallingIdentity(); |
| 2453 | try { |
| 2454 | final Phone phone = getPhone(subId); |
| 2455 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2456 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2457 | } else { |
| 2458 | return false; |
| 2459 | } |
| 2460 | } finally { |
| 2461 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2462 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2463 | } |
| 2464 | |
| 2465 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2466 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2467 | } |
| 2468 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2469 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2470 | enforceCallPermission(); |
| 2471 | |
| 2472 | final long identity = Binder.clearCallingIdentity(); |
| 2473 | try { |
| 2474 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2475 | return; |
| 2476 | } |
| 2477 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2478 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2479 | } finally { |
| 2480 | Binder.restoreCallingIdentity(identity); |
| 2481 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2482 | }; |
| 2483 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2484 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2485 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2486 | |
| 2487 | final long identity = Binder.clearCallingIdentity(); |
| 2488 | try { |
| 2489 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2490 | return false; |
| 2491 | } |
| 2492 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2493 | } finally { |
| 2494 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2495 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2496 | } |
| 2497 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2498 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2499 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2500 | } |
| 2501 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2502 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2503 | final long identity = Binder.clearCallingIdentity(); |
| 2504 | try { |
| 2505 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2506 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2507 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2508 | } finally { |
| 2509 | Binder.restoreCallingIdentity(identity); |
| 2510 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2511 | } |
| 2512 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2513 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2514 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2515 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2516 | } |
| 2517 | |
| 2518 | @Override |
| 2519 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2520 | final long identity = Binder.clearCallingIdentity(); |
| 2521 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2522 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2523 | if (phone != null) { |
| 2524 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2525 | } else { |
| 2526 | return PhoneConstantConversions.convertDataState( |
| 2527 | PhoneConstants.DataState.DISCONNECTED); |
| 2528 | } |
| 2529 | } finally { |
| 2530 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2531 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2532 | } |
| 2533 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2534 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2535 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2536 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2537 | } |
| 2538 | |
| 2539 | @Override |
| 2540 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2541 | final long identity = Binder.clearCallingIdentity(); |
| 2542 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2543 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2544 | if (phone != null) { |
| 2545 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2546 | } else { |
| 2547 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2548 | } |
| 2549 | } finally { |
| 2550 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2551 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2552 | } |
| 2553 | |
| 2554 | @Override |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2555 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2556 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2557 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2558 | |
| 2559 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2560 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2561 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2562 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2563 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2564 | .setCallingPid(Binder.getCallingPid()) |
| 2565 | .setCallingUid(Binder.getCallingUid()) |
| 2566 | .setMethod("getCellLocation") |
Hall Liu | c3f8eb6 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2567 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2568 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2569 | .build()); |
| 2570 | switch (locationResult) { |
| 2571 | case DENIED_HARD: |
| 2572 | throw new SecurityException("Not allowed to access cell location"); |
| 2573 | case DENIED_SOFT: |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2574 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2575 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2576 | } |
| 2577 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2578 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2579 | final long identity = Binder.clearCallingIdentity(); |
| 2580 | try { |
| 2581 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2582 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2583 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2584 | } finally { |
| 2585 | Binder.restoreCallingIdentity(identity); |
| 2586 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2587 | } |
| 2588 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2589 | @Override |
Jack Yu | 0142503 | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2590 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2591 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2592 | // registered cell info, so return a NULL country instead. |
| 2593 | final long identity = Binder.clearCallingIdentity(); |
| 2594 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2595 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2596 | // Get default phone in this case. |
| 2597 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2598 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2599 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2600 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | cf38ed9 | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2601 | if (phone == null) return ""; |
| 2602 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2603 | if (sst == null) return ""; |
| 2604 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2605 | if (lt == null) return ""; |
| 2606 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry(); |
| 2607 | EmergencyNumberTracker ent = phone.getEmergencyNumberTracker(); |
| 2608 | return (ent == null) ? "" : ent.getEmergencyCountryIso(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2609 | } finally { |
| 2610 | Binder.restoreCallingIdentity(identity); |
| 2611 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2612 | } |
| 2613 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2614 | /** |
| 2615 | * This method was removed due to potential issues caused by performing partial |
| 2616 | * updates of service state, and lack of a credible use case. |
| 2617 | * |
| 2618 | * This has the ability to break the telephony implementation by disabling notification of |
| 2619 | * changes in device connectivity. DO NOT USE THIS! |
| 2620 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2621 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2622 | public void enableLocationUpdates() { |
| 2623 | mApp.enforceCallingOrSelfPermission( |
| 2624 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2625 | } |
| 2626 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2627 | /** |
| 2628 | * This method was removed due to potential issues caused by performing partial |
| 2629 | * updates of service state, and lack of a credible use case. |
| 2630 | * |
| 2631 | * This has the ability to break the telephony implementation by disabling notification of |
| 2632 | * changes in device connectivity. DO NOT USE THIS! |
| 2633 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2634 | @Override |
| 2635 | public void disableLocationUpdates() { |
| 2636 | mApp.enforceCallingOrSelfPermission( |
| 2637 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2638 | } |
| 2639 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2640 | /** |
| 2641 | * Returns the target SDK version number for a given package name. |
| 2642 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2643 | * This call MUST be invoked before clearing the calling UID. |
| 2644 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2645 | * @return target SDK if the package is found or INT_MAX. |
| 2646 | */ |
| 2647 | private int getTargetSdk(String packageName) { |
| 2648 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2649 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 54d2030 | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2650 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2651 | if (ai != null) return ai.targetSdkVersion; |
| 2652 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2653 | loge("Failed to get package info for pkg=" |
| 2654 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2655 | } |
| 2656 | return Integer.MAX_VALUE; |
| 2657 | } |
| 2658 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2659 | @Override |
| 2660 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2661 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2662 | String callingFeatureId) { |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2663 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2664 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2665 | throw new SecurityException( |
| 2666 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2667 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2668 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2669 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2670 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2671 | return null; |
| 2672 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2673 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2674 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2675 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2676 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2677 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2678 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2679 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2680 | for (CellInfo ci : info) { |
| 2681 | if (ci instanceof CellInfoGsm) { |
| 2682 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2683 | } else if (ci instanceof CellInfoWcdma) { |
| 2684 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2685 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2686 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2687 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2688 | } |
| 2689 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2690 | private List<CellInfo> getCachedCellInfo() { |
| 2691 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2692 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2693 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2694 | if (info != null) cellInfos.addAll(info); |
| 2695 | } |
| 2696 | return cellInfos; |
| 2697 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2698 | |
| 2699 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2700 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2701 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2702 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2703 | |
| 2704 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2705 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2706 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2707 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2708 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2709 | .setCallingPid(Binder.getCallingPid()) |
| 2710 | .setCallingUid(Binder.getCallingUid()) |
| 2711 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2712 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2713 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2714 | .build()); |
| 2715 | switch (locationResult) { |
| 2716 | case DENIED_HARD: |
| 2717 | throw new SecurityException("Not allowed to access cell info"); |
| 2718 | case DENIED_SOFT: |
| 2719 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2720 | } |
| 2721 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2722 | final int targetSdk = getTargetSdk(callingPackage); |
| 2723 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2724 | return getCachedCellInfo(); |
| 2725 | } |
| 2726 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2727 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2728 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2729 | final long identity = Binder.clearCallingIdentity(); |
| 2730 | try { |
| 2731 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2732 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2733 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2734 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2735 | if (info != null) cellInfos.addAll(info); |
| 2736 | } |
| 2737 | return cellInfos; |
| 2738 | } finally { |
| 2739 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2740 | } |
| 2741 | } |
| 2742 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2743 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2744 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2745 | String callingFeatureId) { |
| 2746 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2747 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2748 | } |
| 2749 | |
| 2750 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2751 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2752 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2753 | enforceModifyPermission(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2754 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2755 | } |
| 2756 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2757 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2758 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2759 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2760 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2761 | |
| 2762 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2763 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2764 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2765 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2766 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2767 | .setCallingPid(Binder.getCallingPid()) |
| 2768 | .setCallingUid(Binder.getCallingUid()) |
| 2769 | .setMethod("requestCellInfoUpdate") |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2770 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2771 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2772 | .build()); |
| 2773 | switch (locationResult) { |
| 2774 | case DENIED_HARD: |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2775 | if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) { |
| 2776 | // Safetynet logging for b/154934934 |
| 2777 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2778 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2779 | throw new SecurityException("Not allowed to access cell info"); |
| 2780 | case DENIED_SOFT: |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2781 | if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) { |
| 2782 | // Safetynet logging for b/154934934 |
| 2783 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2784 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2785 | try { |
| 2786 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2787 | } catch (RemoteException re) { |
| 2788 | // Drop without consequences |
| 2789 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2790 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2791 | } |
| 2792 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2793 | |
| 2794 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2795 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2796 | |
| 2797 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2798 | } |
| 2799 | |
| 2800 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2801 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2802 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2803 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2804 | |
| 2805 | final long identity = Binder.clearCallingIdentity(); |
| 2806 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2807 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2808 | } finally { |
| 2809 | Binder.restoreCallingIdentity(identity); |
| 2810 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2811 | } |
| 2812 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2813 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2814 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2815 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2816 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2817 | return null; |
| 2818 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2819 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2820 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2821 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2822 | return null; |
| 2823 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2824 | |
| 2825 | final long identity = Binder.clearCallingIdentity(); |
| 2826 | try { |
| 2827 | return phone.getImei(); |
| 2828 | } finally { |
| 2829 | Binder.restoreCallingIdentity(identity); |
| 2830 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2831 | } |
| 2832 | |
| 2833 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2834 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2835 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2836 | String tac = null; |
| 2837 | if (phone != null) { |
| 2838 | String imei = phone.getImei(); |
| 2839 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2840 | } |
| 2841 | return tac; |
| 2842 | } |
| 2843 | |
| 2844 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2845 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2846 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2847 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2848 | return null; |
| 2849 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2850 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2851 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2852 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2853 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2854 | return null; |
| 2855 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2856 | |
| 2857 | final long identity = Binder.clearCallingIdentity(); |
| 2858 | try { |
| 2859 | return phone.getMeid(); |
| 2860 | } finally { |
| 2861 | Binder.restoreCallingIdentity(identity); |
| 2862 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2863 | } |
| 2864 | |
| 2865 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2866 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2867 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2868 | String manufacturerCode = null; |
| 2869 | if (phone != null) { |
| 2870 | String meid = phone.getMeid(); |
| 2871 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2872 | } |
| 2873 | return manufacturerCode; |
| 2874 | } |
| 2875 | |
| 2876 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2877 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2878 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2879 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2880 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2881 | return null; |
| 2882 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2883 | int subId = phone.getSubId(); |
| 2884 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2885 | mApp, subId, callingPackage, callingFeatureId, |
| 2886 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2887 | return null; |
| 2888 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2889 | |
| 2890 | final long identity = Binder.clearCallingIdentity(); |
| 2891 | try { |
| 2892 | return phone.getDeviceSvn(); |
| 2893 | } finally { |
| 2894 | Binder.restoreCallingIdentity(identity); |
| 2895 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2896 | } |
| 2897 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2898 | @Override |
| 2899 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2900 | final long identity = Binder.clearCallingIdentity(); |
| 2901 | try { |
| 2902 | final Phone phone = getPhone(subId); |
| 2903 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2904 | } finally { |
| 2905 | Binder.restoreCallingIdentity(identity); |
| 2906 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2907 | } |
| 2908 | |
| 2909 | @Override |
| 2910 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2911 | final long identity = Binder.clearCallingIdentity(); |
| 2912 | try { |
| 2913 | final Phone phone = getPhone(subId); |
| 2914 | return phone == null ? null : phone.getCarrierName(); |
| 2915 | } finally { |
| 2916 | Binder.restoreCallingIdentity(identity); |
| 2917 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2918 | } |
| 2919 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2920 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2921 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2922 | final long identity = Binder.clearCallingIdentity(); |
| 2923 | try { |
| 2924 | final Phone phone = getPhone(subId); |
| 2925 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2926 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2927 | } finally { |
| 2928 | Binder.restoreCallingIdentity(identity); |
| 2929 | } |
| 2930 | } |
| 2931 | |
| 2932 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2933 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2934 | final long identity = Binder.clearCallingIdentity(); |
| 2935 | try { |
| 2936 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2937 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2938 | } finally { |
| 2939 | Binder.restoreCallingIdentity(identity); |
| 2940 | } |
| 2941 | } |
| 2942 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2943 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 2944 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 2945 | if (!isSubscriptionMccMnc) { |
| 2946 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 2947 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 2948 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2949 | if (phone == null) { |
| 2950 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 2951 | } |
| 2952 | final long identity = Binder.clearCallingIdentity(); |
| 2953 | try { |
| 2954 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 2955 | } finally { |
| 2956 | Binder.restoreCallingIdentity(identity); |
| 2957 | } |
| 2958 | } |
| 2959 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2960 | // |
| 2961 | // Internal helper methods. |
| 2962 | // |
| 2963 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 2964 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2965 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 2966 | * |
| 2967 | * @throws SecurityException if the caller does not have the required permission |
| 2968 | */ |
| 2969 | private void enforceModifyPermission() { |
| 2970 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 2971 | } |
| 2972 | |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 2973 | /** |
| 2974 | * Make sure the caller is system. |
| 2975 | * |
| 2976 | * @throws SecurityException if the caller is not system. |
| 2977 | */ |
| 2978 | private void enforceSystemCaller() { |
| 2979 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 2980 | throw new SecurityException("Caller must be system"); |
| 2981 | } |
| 2982 | } |
| 2983 | |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 2984 | private void enforceActiveEmergencySessionPermission() { |
| 2985 | mApp.enforceCallingOrSelfPermission( |
| 2986 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 2987 | } |
| 2988 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2989 | /** |
| 2990 | * Make sure the caller has the CALL_PHONE permission. |
| 2991 | * |
| 2992 | * @throws SecurityException if the caller does not have the required permission |
| 2993 | */ |
| 2994 | private void enforceCallPermission() { |
| 2995 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 2996 | } |
| 2997 | |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 2998 | private void enforceSettingsPermission() { |
| 2999 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3000 | } |
| 3001 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3002 | private String createTelUrl(String number) { |
| 3003 | if (TextUtils.isEmpty(number)) { |
| 3004 | return null; |
| 3005 | } |
| 3006 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3007 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3008 | } |
| 3009 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3010 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3011 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3012 | } |
| 3013 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3014 | private static void logv(String msg) { |
| 3015 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3016 | } |
| 3017 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3018 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3019 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3020 | } |
| 3021 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3022 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3023 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3024 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3025 | } |
| 3026 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3027 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3028 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3029 | final long identity = Binder.clearCallingIdentity(); |
| 3030 | try { |
| 3031 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3032 | if (phone == null) { |
| 3033 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3034 | } else { |
| 3035 | return phone.getPhoneType(); |
| 3036 | } |
| 3037 | } finally { |
| 3038 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3039 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3040 | } |
| 3041 | |
| 3042 | /** |
| 3043 | * Returns the CDMA ERI icon index to display |
| 3044 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3045 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3046 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3047 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3048 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3049 | } |
| 3050 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3051 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3052 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3053 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3054 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3055 | mApp, subId, callingPackage, callingFeatureId, |
| 3056 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3057 | return -1; |
| 3058 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3059 | |
| 3060 | final long identity = Binder.clearCallingIdentity(); |
| 3061 | try { |
| 3062 | final Phone phone = getPhone(subId); |
| 3063 | if (phone != null) { |
| 3064 | return phone.getCdmaEriIconIndex(); |
| 3065 | } else { |
| 3066 | return -1; |
| 3067 | } |
| 3068 | } finally { |
| 3069 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3070 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3071 | } |
| 3072 | |
| 3073 | /** |
| 3074 | * Returns the CDMA ERI icon mode, |
| 3075 | * 0 - ON |
| 3076 | * 1 - FLASHING |
| 3077 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3078 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3079 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3080 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3081 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3082 | } |
| 3083 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3084 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3085 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3086 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3087 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3088 | mApp, subId, callingPackage, callingFeatureId, |
| 3089 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3090 | return -1; |
| 3091 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3092 | |
| 3093 | final long identity = Binder.clearCallingIdentity(); |
| 3094 | try { |
| 3095 | final Phone phone = getPhone(subId); |
| 3096 | if (phone != null) { |
| 3097 | return phone.getCdmaEriIconMode(); |
| 3098 | } else { |
| 3099 | return -1; |
| 3100 | } |
| 3101 | } finally { |
| 3102 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3103 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3104 | } |
| 3105 | |
| 3106 | /** |
| 3107 | * Returns the CDMA ERI text, |
| 3108 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3109 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3110 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3111 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3112 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3113 | } |
| 3114 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3115 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3116 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3117 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3118 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3119 | mApp, subId, callingPackage, callingFeatureId, |
| 3120 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3121 | return null; |
| 3122 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3123 | |
| 3124 | final long identity = Binder.clearCallingIdentity(); |
| 3125 | try { |
| 3126 | final Phone phone = getPhone(subId); |
| 3127 | if (phone != null) { |
| 3128 | return phone.getCdmaEriText(); |
| 3129 | } else { |
| 3130 | return null; |
| 3131 | } |
| 3132 | } finally { |
| 3133 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3134 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3135 | } |
| 3136 | |
| 3137 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3138 | * Returns the CDMA MDN. |
| 3139 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3140 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3141 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3142 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3143 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3144 | |
| 3145 | final long identity = Binder.clearCallingIdentity(); |
| 3146 | try { |
| 3147 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3148 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3149 | return phone.getLine1Number(); |
| 3150 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3151 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3152 | return null; |
| 3153 | } |
| 3154 | } finally { |
| 3155 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3156 | } |
| 3157 | } |
| 3158 | |
| 3159 | /** |
| 3160 | * Returns the CDMA MIN. |
| 3161 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3162 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3163 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3164 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3165 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3166 | |
| 3167 | final long identity = Binder.clearCallingIdentity(); |
| 3168 | try { |
| 3169 | final Phone phone = getPhone(subId); |
| 3170 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3171 | return phone.getCdmaMin(); |
| 3172 | } else { |
| 3173 | return null; |
| 3174 | } |
| 3175 | } finally { |
| 3176 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3177 | } |
| 3178 | } |
| 3179 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3180 | @Override |
| 3181 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3182 | INumberVerificationCallback callback, String callingPackage) { |
| 3183 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3184 | != PERMISSION_GRANTED) { |
| 3185 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3186 | } |
| 3187 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3188 | |
| 3189 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3190 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 3191 | throw new SecurityException("Calling package must be configured in the device config"); |
| 3192 | } |
| 3193 | |
| 3194 | if (range == null) { |
| 3195 | throw new NullPointerException("Range must be non-null"); |
| 3196 | } |
| 3197 | |
| 3198 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3199 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3200 | |
| 3201 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3202 | } |
| 3203 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3204 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3205 | * Returns true if CDMA provisioning needs to run. |
| 3206 | */ |
| 3207 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3208 | final long identity = Binder.clearCallingIdentity(); |
| 3209 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3210 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3211 | } finally { |
| 3212 | Binder.restoreCallingIdentity(identity); |
| 3213 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3214 | } |
| 3215 | |
| 3216 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3217 | * Sets the voice mail number of a given subId. |
| 3218 | */ |
| 3219 | @Override |
| 3220 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3221 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3222 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3223 | |
| 3224 | final long identity = Binder.clearCallingIdentity(); |
| 3225 | try { |
| 3226 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3227 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3228 | return success; |
| 3229 | } finally { |
| 3230 | Binder.restoreCallingIdentity(identity); |
| 3231 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3232 | } |
| 3233 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3234 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3235 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3236 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3237 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3238 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3239 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3240 | throw new SecurityException("caller must be system dialer"); |
| 3241 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3242 | |
| 3243 | final long identity = Binder.clearCallingIdentity(); |
| 3244 | try { |
| 3245 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3246 | if (phoneAccountHandle == null) { |
| 3247 | return null; |
| 3248 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3249 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3250 | } finally { |
| 3251 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3252 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3253 | } |
| 3254 | |
| 3255 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3256 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3257 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3258 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3259 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3260 | mApp, subId, callingPackage, callingFeatureId, |
| 3261 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3262 | return null; |
| 3263 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3264 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3265 | final long identity = Binder.clearCallingIdentity(); |
| 3266 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3267 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3268 | } finally { |
| 3269 | Binder.restoreCallingIdentity(identity); |
| 3270 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3271 | } |
| 3272 | |
| 3273 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3274 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3275 | VisualVoicemailSmsFilterSettings settings) { |
| 3276 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3277 | |
| 3278 | final long identity = Binder.clearCallingIdentity(); |
| 3279 | try { |
| 3280 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3281 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3282 | } finally { |
| 3283 | Binder.restoreCallingIdentity(identity); |
| 3284 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3285 | } |
| 3286 | |
| 3287 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3288 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3289 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3290 | |
| 3291 | final long identity = Binder.clearCallingIdentity(); |
| 3292 | try { |
| 3293 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3294 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3295 | } finally { |
| 3296 | Binder.restoreCallingIdentity(identity); |
| 3297 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3298 | } |
| 3299 | |
| 3300 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3301 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3302 | String callingPackage, int subId) { |
| 3303 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3304 | |
| 3305 | final long identity = Binder.clearCallingIdentity(); |
| 3306 | try { |
| 3307 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3308 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3309 | } finally { |
| 3310 | Binder.restoreCallingIdentity(identity); |
| 3311 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3312 | } |
| 3313 | |
| 3314 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3315 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3316 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3317 | |
| 3318 | final long identity = Binder.clearCallingIdentity(); |
| 3319 | try { |
| 3320 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3321 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3322 | } finally { |
| 3323 | Binder.restoreCallingIdentity(identity); |
| 3324 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3325 | } |
| 3326 | |
| 3327 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3328 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3329 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3330 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3331 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3332 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3333 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3334 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3335 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3336 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3337 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3338 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3339 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3340 | * Sets the voice activation state of a given subId. |
| 3341 | */ |
| 3342 | @Override |
| 3343 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3344 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3345 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3346 | |
| 3347 | final long identity = Binder.clearCallingIdentity(); |
| 3348 | try { |
| 3349 | final Phone phone = getPhone(subId); |
| 3350 | if (phone != null) { |
| 3351 | phone.setVoiceActivationState(activationState); |
| 3352 | } else { |
| 3353 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3354 | } |
| 3355 | } finally { |
| 3356 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3357 | } |
| 3358 | } |
| 3359 | |
| 3360 | /** |
| 3361 | * Sets the data activation state of a given subId. |
| 3362 | */ |
| 3363 | @Override |
| 3364 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3365 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3366 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3367 | |
| 3368 | final long identity = Binder.clearCallingIdentity(); |
| 3369 | try { |
| 3370 | final Phone phone = getPhone(subId); |
| 3371 | if (phone != null) { |
| 3372 | phone.setDataActivationState(activationState); |
| 3373 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3374 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3375 | } |
| 3376 | } finally { |
| 3377 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3378 | } |
| 3379 | } |
| 3380 | |
| 3381 | /** |
| 3382 | * Returns the voice activation state of a given subId. |
| 3383 | */ |
| 3384 | @Override |
| 3385 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3386 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3387 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3388 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3389 | final long identity = Binder.clearCallingIdentity(); |
| 3390 | try { |
| 3391 | if (phone != null) { |
| 3392 | return phone.getVoiceActivationState(); |
| 3393 | } else { |
| 3394 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3395 | } |
| 3396 | } finally { |
| 3397 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3398 | } |
| 3399 | } |
| 3400 | |
| 3401 | /** |
| 3402 | * Returns the data activation state of a given subId. |
| 3403 | */ |
| 3404 | @Override |
| 3405 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3406 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3407 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3408 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3409 | final long identity = Binder.clearCallingIdentity(); |
| 3410 | try { |
| 3411 | if (phone != null) { |
| 3412 | return phone.getDataActivationState(); |
| 3413 | } else { |
| 3414 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3415 | } |
| 3416 | } finally { |
| 3417 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3418 | } |
| 3419 | } |
| 3420 | |
| 3421 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3422 | * Returns the unread count of voicemails for a subId |
| 3423 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3424 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3425 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3426 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3427 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3428 | mApp, subId, callingPackage, callingFeatureId, |
| 3429 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3430 | return 0; |
| 3431 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3432 | final long identity = Binder.clearCallingIdentity(); |
| 3433 | try { |
| 3434 | final Phone phone = getPhone(subId); |
| 3435 | if (phone != null) { |
| 3436 | return phone.getVoiceMessageCount(); |
| 3437 | } else { |
| 3438 | return 0; |
| 3439 | } |
| 3440 | } finally { |
| 3441 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3442 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3443 | } |
| 3444 | |
| 3445 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3446 | * returns true, if the device is in a state where both voice and data |
| 3447 | * are supported simultaneously. This can change based on location or network condition. |
| 3448 | */ |
| 3449 | @Override |
| 3450 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3451 | final long identity = Binder.clearCallingIdentity(); |
| 3452 | try { |
| 3453 | final Phone phone = getPhone(subId); |
| 3454 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3455 | } finally { |
| 3456 | Binder.restoreCallingIdentity(identity); |
| 3457 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3458 | } |
| 3459 | |
| 3460 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3461 | * Send the dialer code if called from the current default dialer or the caller has |
| 3462 | * carrier privilege. |
| 3463 | * @param inputCode The dialer code to send |
| 3464 | */ |
| 3465 | @Override |
| 3466 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3467 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3468 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3469 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3470 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3471 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3472 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3473 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3474 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3475 | |
| 3476 | final long identity = Binder.clearCallingIdentity(); |
| 3477 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3478 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3479 | } finally { |
| 3480 | Binder.restoreCallingIdentity(identity); |
| 3481 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3482 | } |
| 3483 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3484 | @Override |
| 3485 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3486 | TelephonyPermissions |
| 3487 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3488 | mApp, subId, "getNetworkSelectionMode"); |
| 3489 | final long identity = Binder.clearCallingIdentity(); |
| 3490 | try { |
| 3491 | if (!isActiveSubscription(subId)) { |
| 3492 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3493 | } |
| 3494 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3495 | } finally { |
| 3496 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3497 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3498 | } |
| 3499 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3500 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3501 | public boolean isInEmergencySmsMode() { |
| 3502 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3503 | final long identity = Binder.clearCallingIdentity(); |
| 3504 | try { |
| 3505 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3506 | if (phone.isInEmergencySmsMode()) { |
| 3507 | return true; |
| 3508 | } |
| 3509 | } |
| 3510 | } finally { |
| 3511 | Binder.restoreCallingIdentity(identity); |
| 3512 | } |
| 3513 | return false; |
| 3514 | } |
| 3515 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3516 | /** |
| 3517 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3518 | * @param subId The subscription to use to check the configuration. |
| 3519 | * @param c The callback that will be used to send the result. |
| 3520 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3521 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3522 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3523 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3524 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3525 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3526 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3527 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3528 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3529 | "IMS not available on device."); |
| 3530 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3531 | final long token = Binder.clearCallingIdentity(); |
| 3532 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3533 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3534 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3535 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3536 | } catch (ImsException e) { |
| 3537 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3538 | } finally { |
| 3539 | Binder.restoreCallingIdentity(token); |
| 3540 | } |
| 3541 | } |
| 3542 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3543 | /** |
| 3544 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3545 | * @param subId The subscription to use to check the configuration. |
| 3546 | * @param c The callback that will be used to send the result. |
| 3547 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3548 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3549 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3550 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3551 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3552 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3553 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3554 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3555 | final long token = Binder.clearCallingIdentity(); |
| 3556 | try { |
| 3557 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3558 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3559 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3560 | } catch (ImsException e) { |
| 3561 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3562 | + "is inactive, ignoring unregister."); |
| 3563 | // If the subscription is no longer active, just return, since the callback |
| 3564 | // will already have been removed internally. |
| 3565 | } finally { |
| 3566 | Binder.restoreCallingIdentity(token); |
| 3567 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3568 | } |
| 3569 | |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3570 | /** |
| 3571 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3572 | */ |
| 3573 | @Override |
| 3574 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3575 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3576 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3577 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3578 | "IMS not available on device."); |
| 3579 | } |
| 3580 | final long token = Binder.clearCallingIdentity(); |
| 3581 | try { |
| 3582 | Phone phone = getPhone(subId); |
| 3583 | if (phone == null) { |
| 3584 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3585 | + subId + "'"); |
| 3586 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3587 | } |
| 3588 | phone.getImsRegistrationState(regState -> { |
| 3589 | try { |
| 3590 | consumer.accept((regState == null) |
| 3591 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3592 | } catch (RemoteException e) { |
| 3593 | // Ignore if the remote process is no longer available to call back. |
| 3594 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3595 | } |
| 3596 | }); |
| 3597 | } finally { |
| 3598 | Binder.restoreCallingIdentity(token); |
| 3599 | } |
| 3600 | } |
| 3601 | |
| 3602 | /** |
| 3603 | * Get the transport type for the IMS service registration state. |
| 3604 | */ |
| 3605 | @Override |
| 3606 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3607 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3608 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3609 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3610 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3611 | "IMS not available on device."); |
| 3612 | } |
| 3613 | final long token = Binder.clearCallingIdentity(); |
| 3614 | try { |
| 3615 | Phone phone = getPhone(subId); |
| 3616 | if (phone == null) { |
| 3617 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3618 | + subId + "'"); |
| 3619 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3620 | } |
| 3621 | phone.getImsRegistrationTech(regTech -> { |
| 3622 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3623 | int regTechConverted = (regTech == null) |
| 3624 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3625 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3626 | regTechConverted); |
| 3627 | try { |
| 3628 | consumer.accept(regTechConverted); |
| 3629 | } catch (RemoteException e) { |
| 3630 | // Ignore if the remote process is no longer available to call back. |
| 3631 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3632 | } |
| 3633 | }); |
| 3634 | } finally { |
| 3635 | Binder.restoreCallingIdentity(token); |
| 3636 | } |
| 3637 | } |
| 3638 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3639 | /** |
| 3640 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3641 | * @param subId The subscription to use to check the configuration. |
| 3642 | * @param c The callback that will be used to send the result. |
| 3643 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3644 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3645 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3646 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3647 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3648 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3649 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3650 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3651 | "IMS not available on device."); |
| 3652 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3653 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3654 | final long token = Binder.clearCallingIdentity(); |
| 3655 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3656 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3657 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3658 | } catch (ImsException e) { |
| 3659 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3660 | } finally { |
| 3661 | Binder.restoreCallingIdentity(token); |
| 3662 | } |
| 3663 | } |
| 3664 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3665 | /** |
| 3666 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3667 | * @param subId The subscription to use to check the configuration. |
| 3668 | * @param c The callback that will be used to send the result. |
| 3669 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3670 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3671 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3672 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3673 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3674 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3675 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3676 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3677 | |
| 3678 | final long token = Binder.clearCallingIdentity(); |
| 3679 | try { |
| 3680 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3681 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3682 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3683 | } catch (ImsException e) { |
| 3684 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3685 | + "is inactive, ignoring unregister."); |
| 3686 | // If the subscription is no longer active, just return, since the callback |
| 3687 | // will already have been removed internally. |
| 3688 | } finally { |
| 3689 | Binder.restoreCallingIdentity(token); |
| 3690 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3691 | } |
| 3692 | |
| 3693 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3694 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3695 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3696 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3697 | final long token = Binder.clearCallingIdentity(); |
| 3698 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3699 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3700 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3701 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3702 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3703 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3704 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3705 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3706 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3707 | } finally { |
| 3708 | Binder.restoreCallingIdentity(token); |
| 3709 | } |
| 3710 | } |
| 3711 | |
| 3712 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3713 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3714 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3715 | final long token = Binder.clearCallingIdentity(); |
| 3716 | try { |
| 3717 | Phone phone = getPhone(subId); |
| 3718 | if (phone == null) return false; |
| 3719 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 32706d9 | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3720 | } catch (com.android.ims.ImsException e) { |
| 3721 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3722 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3723 | } finally { |
| 3724 | Binder.restoreCallingIdentity(token); |
| 3725 | } |
| 3726 | } |
| 3727 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3728 | /** |
| 3729 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3730 | * subscription. |
| 3731 | * @param subId The subscription to use to check the configuration. |
| 3732 | * @param callback The callback that will be used to send the result. |
| 3733 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3734 | * @param transportType The transport type of the MmTelFeature capability. |
| 3735 | */ |
| 3736 | @Override |
| 3737 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3738 | int transportType) { |
| 3739 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3740 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3741 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3742 | "IMS not available on device."); |
| 3743 | } |
| 3744 | final long token = Binder.clearCallingIdentity(); |
| 3745 | try { |
| 3746 | int slotId = getSlotIndex(subId); |
| 3747 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3748 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3749 | + subId + "'"); |
| 3750 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3751 | } |
| 3752 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3753 | transportType, aBoolean -> { |
| 3754 | try { |
| 3755 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3756 | } catch (RemoteException e) { |
| 3757 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3758 | + "running. Ignore"); |
| 3759 | } |
| 3760 | }); |
| 3761 | } finally { |
| 3762 | Binder.restoreCallingIdentity(token); |
| 3763 | } |
| 3764 | } |
| 3765 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3766 | /** |
| 3767 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3768 | * @param subId The subscription to use to check the configuration. |
| 3769 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3770 | @Override |
| 3771 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3772 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3773 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3774 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3775 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3776 | final long token = Binder.clearCallingIdentity(); |
| 3777 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3778 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3779 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3780 | } catch (ImsException e) { |
| 3781 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3782 | } finally { |
| 3783 | Binder.restoreCallingIdentity(token); |
| 3784 | } |
| 3785 | } |
| 3786 | |
| 3787 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3788 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3789 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3790 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3791 | final long identity = Binder.clearCallingIdentity(); |
| 3792 | try { |
| 3793 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3794 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3795 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3796 | } catch (ImsException e) { |
| 3797 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3798 | } finally { |
| 3799 | Binder.restoreCallingIdentity(identity); |
| 3800 | } |
| 3801 | } |
| 3802 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3803 | /** |
| 3804 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3805 | * @param subId The subscription to use to check the configuration. |
| 3806 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3807 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3808 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3809 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3810 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3811 | final long identity = Binder.clearCallingIdentity(); |
| 3812 | try { |
| 3813 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3814 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3815 | } catch (ImsException e) { |
| 3816 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3817 | } finally { |
| 3818 | Binder.restoreCallingIdentity(identity); |
| 3819 | } |
| 3820 | } |
| 3821 | |
| 3822 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3823 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3824 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3825 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3826 | final long identity = Binder.clearCallingIdentity(); |
| 3827 | try { |
| 3828 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3829 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
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 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3837 | /** |
| 3838 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3839 | * @param subId The subscription to use to check the configuration. |
| 3840 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3841 | @Override |
| 3842 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3843 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3844 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3845 | final long identity = Binder.clearCallingIdentity(); |
| 3846 | try { |
| 3847 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3848 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3849 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3850 | } catch (ImsException e) { |
| 3851 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3852 | } finally { |
| 3853 | Binder.restoreCallingIdentity(identity); |
| 3854 | } |
| 3855 | } |
| 3856 | |
| 3857 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3858 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3859 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3860 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3861 | final long identity = Binder.clearCallingIdentity(); |
| 3862 | try { |
| 3863 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3864 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3865 | } catch (ImsException e) { |
| 3866 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3867 | } finally { |
| 3868 | Binder.restoreCallingIdentity(identity); |
| 3869 | } |
| 3870 | } |
| 3871 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3872 | /** |
| 3873 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3874 | * @param subId The subscription to use to check the configuration. |
| 3875 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3876 | @Override |
| 3877 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3878 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3879 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3880 | final long identity = Binder.clearCallingIdentity(); |
| 3881 | try { |
| 3882 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3883 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3884 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3885 | } catch (ImsException e) { |
| 3886 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3887 | } finally { |
| 3888 | Binder.restoreCallingIdentity(identity); |
| 3889 | } |
| 3890 | } |
| 3891 | |
| 3892 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3893 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3894 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3895 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3896 | final long identity = Binder.clearCallingIdentity(); |
| 3897 | try { |
| 3898 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3899 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3900 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3901 | } catch (ImsException e) { |
| 3902 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3903 | } finally { |
| 3904 | Binder.restoreCallingIdentity(identity); |
| 3905 | } |
| 3906 | } |
| 3907 | |
| 3908 | @Override |
| 3909 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3910 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3911 | "setVoWiFiNonPersistent"); |
| 3912 | final long identity = Binder.clearCallingIdentity(); |
| 3913 | try { |
| 3914 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3915 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3916 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3917 | } catch (ImsException e) { |
| 3918 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3919 | } finally { |
| 3920 | Binder.restoreCallingIdentity(identity); |
| 3921 | } |
| 3922 | } |
| 3923 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3924 | /** |
| 3925 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3926 | * @param subId The subscription to use to check the configuration. |
| 3927 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3928 | @Override |
| 3929 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3930 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3931 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3932 | final long identity = Binder.clearCallingIdentity(); |
| 3933 | try { |
| 3934 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3935 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3936 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3937 | } catch (ImsException e) { |
| 3938 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3939 | } finally { |
| 3940 | Binder.restoreCallingIdentity(identity); |
| 3941 | } |
| 3942 | } |
| 3943 | |
| 3944 | @Override |
| 3945 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 3946 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3947 | "setVoWiFiModeSetting"); |
| 3948 | final long identity = Binder.clearCallingIdentity(); |
| 3949 | try { |
| 3950 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3951 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3952 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3953 | } catch (ImsException e) { |
| 3954 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3955 | } finally { |
| 3956 | Binder.restoreCallingIdentity(identity); |
| 3957 | } |
| 3958 | } |
| 3959 | |
| 3960 | @Override |
| 3961 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 3962 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 3963 | final long identity = Binder.clearCallingIdentity(); |
| 3964 | try { |
| 3965 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3966 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3967 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3968 | } catch (ImsException e) { |
| 3969 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3970 | } finally { |
| 3971 | Binder.restoreCallingIdentity(identity); |
| 3972 | } |
| 3973 | } |
| 3974 | |
| 3975 | @Override |
| 3976 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 3977 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3978 | "setVoWiFiRoamingModeSetting"); |
| 3979 | final long identity = Binder.clearCallingIdentity(); |
| 3980 | try { |
| 3981 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3982 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3983 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3984 | } catch (ImsException e) { |
| 3985 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3986 | } finally { |
| 3987 | Binder.restoreCallingIdentity(identity); |
| 3988 | } |
| 3989 | } |
| 3990 | |
| 3991 | @Override |
| 3992 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 3993 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3994 | "setRttCapabilityEnabled"); |
| 3995 | final long identity = Binder.clearCallingIdentity(); |
| 3996 | try { |
| 3997 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3998 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 3999 | } catch (ImsException e) { |
| 4000 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4001 | } finally { |
| 4002 | Binder.restoreCallingIdentity(identity); |
| 4003 | } |
| 4004 | } |
| 4005 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4006 | /** |
| 4007 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4008 | * @param subId The subscription to use to check the configuration. |
| 4009 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4010 | @Override |
| 4011 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4012 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4013 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4014 | final long identity = Binder.clearCallingIdentity(); |
| 4015 | try { |
| 4016 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4017 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4018 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4019 | } catch (ImsException e) { |
| 4020 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4021 | } finally { |
| 4022 | Binder.restoreCallingIdentity(identity); |
| 4023 | } |
| 4024 | } |
| 4025 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4026 | @Override |
| 4027 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4028 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 4029 | final long identity = Binder.clearCallingIdentity(); |
| 4030 | try { |
Brad Ebinger | 6cf0f65 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4031 | if (!isImsAvailableOnDevice()) { |
| 4032 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4033 | "IMS not available on device."); |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4034 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4035 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4036 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4037 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4038 | } catch (ImsException e) { |
| 4039 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4040 | } finally { |
| 4041 | Binder.restoreCallingIdentity(identity); |
| 4042 | } |
| 4043 | } |
| 4044 | |
| 4045 | @Override |
| 4046 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4047 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 4048 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4049 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4050 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4051 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4052 | try { |
| 4053 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4054 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4055 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4056 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4057 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4058 | + "is inactive, ignoring unregister."); |
| 4059 | // If the subscription is no longer active, just return, since the callback will already |
| 4060 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4061 | } finally { |
| 4062 | Binder.restoreCallingIdentity(identity); |
| 4063 | } |
| 4064 | } |
| 4065 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4066 | |
| 4067 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4068 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4069 | message); |
| 4070 | } |
| 4071 | |
| 4072 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4073 | boolean isMmtelCapability) { |
| 4074 | Phone phone = getPhone(subId); |
| 4075 | if (phone == null) { |
| 4076 | loge("phone instance null for subid " + subId); |
| 4077 | return false; |
| 4078 | } |
| 4079 | if (isMmtelCapability) { |
| 4080 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4081 | return false; |
| 4082 | } |
| 4083 | } else { |
| 4084 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4085 | return false; |
| 4086 | } |
| 4087 | } |
| 4088 | return true; |
| 4089 | } |
| 4090 | |
| 4091 | @Override |
| 4092 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4093 | boolean isProvisioned) { |
| 4094 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4095 | |
| 4096 | final long identity = Binder.clearCallingIdentity(); |
| 4097 | try { |
| 4098 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4099 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4100 | return; |
| 4101 | } |
| 4102 | |
| 4103 | // this capability requires provisioning, route to the correct API. |
| 4104 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4105 | switch (capability) { |
| 4106 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4107 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4108 | ims.setEabProvisioned(isProvisioned); |
| 4109 | break; |
| 4110 | default: { |
| 4111 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4112 | + "rcs capability '" + capability + "', which does not require " |
| 4113 | + "provisioning."); |
| 4114 | } |
| 4115 | } |
| 4116 | } finally { |
| 4117 | Binder.restoreCallingIdentity(identity); |
| 4118 | } |
| 4119 | |
| 4120 | } |
| 4121 | |
| 4122 | |
| 4123 | @Override |
| 4124 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4125 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4126 | final long identity = Binder.clearCallingIdentity(); |
| 4127 | try { |
| 4128 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4129 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4130 | return true; |
| 4131 | } |
| 4132 | |
| 4133 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4134 | switch (capability) { |
| 4135 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4136 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4137 | return ims.isEabProvisionedOnDevice(); |
| 4138 | |
| 4139 | default: { |
| 4140 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4141 | + "capability '" + capability + "', which does not require " |
| 4142 | + "provisioning."); |
| 4143 | } |
| 4144 | } |
| 4145 | |
| 4146 | } finally { |
| 4147 | Binder.restoreCallingIdentity(identity); |
| 4148 | } |
| 4149 | } |
| 4150 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4151 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4152 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4153 | boolean isProvisioned) { |
| 4154 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4155 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4156 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4157 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4158 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4159 | final long identity = Binder.clearCallingIdentity(); |
| 4160 | try { |
| 4161 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4162 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4163 | return; |
| 4164 | } |
| 4165 | |
| 4166 | // this capability requires provisioning, route to the correct API. |
| 4167 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4168 | switch (capability) { |
| 4169 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4170 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4171 | ims.setVolteProvisioned(isProvisioned); |
| 4172 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4173 | ims.setWfcProvisioned(isProvisioned); |
| 4174 | } |
| 4175 | break; |
| 4176 | } |
| 4177 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4178 | // There is currently no difference in VT provisioning type. |
| 4179 | ims.setVtProvisioned(isProvisioned); |
| 4180 | break; |
| 4181 | } |
| 4182 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4183 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4184 | // change the capability of the feature instead if needed. |
| 4185 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4186 | == isProvisioned) { |
| 4187 | // No change in provisioning. |
| 4188 | return; |
| 4189 | } |
| 4190 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4191 | try { |
| 4192 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4193 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4194 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4195 | + ", Exception" + e.getMessage()); |
| 4196 | } |
| 4197 | break; |
| 4198 | } |
| 4199 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4200 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4201 | + "MmTel capability '" + capability + "', which does not require " |
| 4202 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4203 | } |
| 4204 | } |
| 4205 | |
| 4206 | } finally { |
| 4207 | Binder.restoreCallingIdentity(identity); |
| 4208 | } |
| 4209 | } |
| 4210 | |
| 4211 | @Override |
| 4212 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4213 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4214 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4215 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4216 | } |
| 4217 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4218 | final long identity = Binder.clearCallingIdentity(); |
| 4219 | try { |
| 4220 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4221 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4222 | return true; |
| 4223 | } |
| 4224 | |
| 4225 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4226 | switch (capability) { |
| 4227 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4228 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4229 | return ims.isVolteProvisionedOnDevice(); |
| 4230 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4231 | return ims.isWfcProvisionedOnDevice(); |
| 4232 | } |
| 4233 | // This should never happen, since we are checking tech above to make sure it |
| 4234 | // is either LTE or IWLAN. |
| 4235 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4236 | + "capability."); |
| 4237 | } |
| 4238 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4239 | // There is currently no difference in VT provisioning type. |
| 4240 | return ims.isVtProvisionedOnDevice(); |
| 4241 | } |
| 4242 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4243 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4244 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4245 | } |
| 4246 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4247 | throw new IllegalArgumentException( |
| 4248 | "Tried to get provisioning for MmTel capability '" + capability |
| 4249 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4250 | } |
| 4251 | } |
| 4252 | |
| 4253 | } finally { |
| 4254 | Binder.restoreCallingIdentity(identity); |
| 4255 | } |
| 4256 | } |
| 4257 | |
| 4258 | @Override |
| 4259 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4260 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4261 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4262 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4263 | } |
| 4264 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4265 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4266 | return (provisionedBits & capability) > 0; |
| 4267 | } |
| 4268 | |
| 4269 | @Override |
| 4270 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4271 | boolean isProvisioned) { |
| 4272 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4273 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4274 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4275 | } |
| 4276 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4277 | "setProvisioningStatusForCapability"); |
| 4278 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4279 | // If the current provisioning status for capability already matches isProvisioned, |
| 4280 | // do nothing. |
| 4281 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4282 | return; |
| 4283 | } |
| 4284 | if (isProvisioned) { |
| 4285 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4286 | } else { |
| 4287 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4288 | } |
| 4289 | } |
| 4290 | |
| 4291 | /** |
| 4292 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4293 | * technology. The bitfield should mirror the bitfield defined by |
| 4294 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4295 | */ |
| 4296 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4297 | String key = getMmTelProvisioningKey(subId, tech); |
| 4298 | // Default is no capabilities are provisioned. |
| 4299 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4300 | } |
| 4301 | |
| 4302 | /** |
| 4303 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4304 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4305 | * technology specified. |
| 4306 | * |
| 4307 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4308 | */ |
| 4309 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4310 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4311 | String key = getMmTelProvisioningKey(subId, tech); |
| 4312 | editor.putInt(key, newField); |
| 4313 | editor.commit(); |
| 4314 | } |
| 4315 | |
| 4316 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4317 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4318 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4319 | } |
| 4320 | |
| 4321 | /** |
| 4322 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4323 | * carrier associated with the subscription id. |
| 4324 | */ |
| 4325 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4326 | int capability) { |
| 4327 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4328 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4329 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4330 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4331 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4332 | false); |
| 4333 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4334 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4335 | |
| 4336 | // First check to make sure that the capability requires provisioning. |
| 4337 | switch (capability) { |
| 4338 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4339 | // intentional fallthrough |
| 4340 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4341 | if (requireVoiceVtProvisioning) { |
| 4342 | // Voice and Video requires provisioning |
| 4343 | return true; |
| 4344 | } |
| 4345 | break; |
| 4346 | } |
| 4347 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4348 | if (requireUtProvisioning) { |
| 4349 | // UT requires provisioning |
| 4350 | return true; |
| 4351 | } |
| 4352 | break; |
| 4353 | } |
| 4354 | } |
| 4355 | return false; |
| 4356 | } |
| 4357 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4358 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4359 | int capability) { |
| 4360 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4361 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4362 | |
| 4363 | boolean requireRcsProvisioning = c.getBoolean( |
| 4364 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4365 | |
| 4366 | // First check to make sure that the capability requires provisioning. |
| 4367 | switch (capability) { |
| 4368 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4369 | // intentional fallthrough |
| 4370 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4371 | if (requireRcsProvisioning) { |
| 4372 | // OPTION or PRESENCE requires provisioning |
| 4373 | return true; |
| 4374 | } |
| 4375 | break; |
| 4376 | } |
| 4377 | } |
| 4378 | return false; |
| 4379 | } |
| 4380 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4381 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4382 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4383 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4384 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4385 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4386 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4387 | final long identity = Binder.clearCallingIdentity(); |
| 4388 | try { |
| 4389 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4390 | int slotId = getSlotIndex(subId); |
| 4391 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4392 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4393 | + subId + "' for key:" + key); |
| 4394 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4395 | } |
| 4396 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4397 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4398 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4399 | + subId + "' for key:" + key); |
| 4400 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4401 | } finally { |
| 4402 | Binder.restoreCallingIdentity(identity); |
| 4403 | } |
| 4404 | } |
| 4405 | |
| 4406 | @Override |
| 4407 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4408 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4409 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4410 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4411 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4412 | final long identity = Binder.clearCallingIdentity(); |
| 4413 | try { |
| 4414 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4415 | int slotId = getSlotIndex(subId); |
| 4416 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4417 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4418 | + subId + "' for key:" + key); |
| 4419 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4420 | } |
| 4421 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4422 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4423 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4424 | + subId + "' for key:" + key); |
| 4425 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4426 | } finally { |
| 4427 | Binder.restoreCallingIdentity(identity); |
| 4428 | } |
| 4429 | } |
| 4430 | |
| 4431 | @Override |
| 4432 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4433 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4434 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4435 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4436 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4437 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4438 | final long identity = Binder.clearCallingIdentity(); |
| 4439 | try { |
| 4440 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4441 | int slotId = getSlotIndex(subId); |
| 4442 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4443 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4444 | + subId + "' for key:" + key); |
| 4445 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4446 | } |
| 4447 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4448 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4449 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4450 | + "' for key:" + key); |
| 4451 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4452 | } finally { |
| 4453 | Binder.restoreCallingIdentity(identity); |
| 4454 | } |
| 4455 | } |
| 4456 | |
| 4457 | @Override |
| 4458 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4459 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4460 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4461 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4462 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4463 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4464 | final long identity = Binder.clearCallingIdentity(); |
| 4465 | try { |
| 4466 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4467 | int slotId = getSlotIndex(subId); |
| 4468 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4469 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4470 | + subId + "' for key:" + key); |
| 4471 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4472 | } |
| 4473 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4474 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4475 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4476 | + "' for key:" + key); |
| 4477 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4478 | } finally { |
| 4479 | Binder.restoreCallingIdentity(identity); |
| 4480 | } |
| 4481 | } |
| 4482 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4483 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4484 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4485 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4486 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4487 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4488 | } |
| 4489 | return slotId; |
| 4490 | } |
| 4491 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4492 | private int getSlotIndex(int subId) { |
| 4493 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4494 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4495 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4496 | } |
| 4497 | return slotId; |
| 4498 | } |
| 4499 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4500 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4501 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4502 | */ |
| 4503 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4504 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4505 | String callingFeatureId) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4506 | final int targetSdk = getTargetSdk(callingPackage); |
| 4507 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4508 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4509 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4510 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4511 | mApp, subId, callingPackage, callingFeatureId, |
| 4512 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4513 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4514 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4515 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4516 | final long identity = Binder.clearCallingIdentity(); |
| 4517 | try { |
| 4518 | final Phone phone = getPhone(subId); |
| 4519 | if (phone != null) { |
| 4520 | return phone.getServiceState().getDataNetworkType(); |
| 4521 | } else { |
| 4522 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4523 | } |
| 4524 | } finally { |
| 4525 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4526 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4527 | } |
| 4528 | |
| 4529 | /** |
| 4530 | * Returns the data network type |
| 4531 | */ |
| 4532 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4533 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4534 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4535 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4536 | } |
| 4537 | |
| 4538 | /** |
| 4539 | * Returns the data network type for a subId |
| 4540 | */ |
| 4541 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4542 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4543 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4544 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4545 | mApp, subId, callingPackage, callingFeatureId, |
| 4546 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4547 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4548 | } |
| 4549 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4550 | final long identity = Binder.clearCallingIdentity(); |
| 4551 | try { |
| 4552 | final Phone phone = getPhone(subId); |
| 4553 | if (phone != null) { |
| 4554 | return phone.getServiceState().getDataNetworkType(); |
| 4555 | } else { |
| 4556 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4557 | } |
| 4558 | } finally { |
| 4559 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4560 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4561 | } |
| 4562 | |
| 4563 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4564 | * Returns the Voice network type for a subId |
| 4565 | */ |
| 4566 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4567 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4568 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4569 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4570 | mApp, subId, callingPackage, callingFeatureId, |
| 4571 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4572 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4573 | } |
| 4574 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4575 | final long identity = Binder.clearCallingIdentity(); |
| 4576 | try { |
| 4577 | final Phone phone = getPhone(subId); |
| 4578 | if (phone != null) { |
| 4579 | return phone.getServiceState().getVoiceNetworkType(); |
| 4580 | } else { |
| 4581 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4582 | } |
| 4583 | } finally { |
| 4584 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4585 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4586 | } |
| 4587 | |
| 4588 | /** |
| 4589 | * @return true if a ICC card is present |
| 4590 | */ |
| 4591 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4592 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4593 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4594 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4595 | } |
| 4596 | |
| 4597 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4598 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4599 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4600 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4601 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4602 | final long identity = Binder.clearCallingIdentity(); |
| 4603 | try { |
| 4604 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4605 | if (phone != null) { |
| 4606 | return phone.getIccCard().hasIccCard(); |
| 4607 | } else { |
| 4608 | return false; |
| 4609 | } |
| 4610 | } finally { |
| 4611 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4612 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4613 | } |
| 4614 | |
| 4615 | /** |
| 4616 | * Return if the current radio is LTE on CDMA. This |
| 4617 | * is a tri-state return value as for a period of time |
| 4618 | * the mode may be unknown. |
| 4619 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4620 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4621 | * @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] | 4622 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4623 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4624 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4625 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4626 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4627 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4628 | } |
| 4629 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4630 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4631 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4632 | String callingFeatureId) { |
Sarah Chin | f6656a6 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4633 | try { |
| 4634 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4635 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4636 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4637 | } |
| 4638 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4639 | final long identity = Binder.clearCallingIdentity(); |
| 4640 | try { |
| 4641 | final Phone phone = getPhone(subId); |
| 4642 | if (phone == null) { |
| 4643 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4644 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 4645 | return TelephonyProperties.lte_on_cdma_device() |
| 4646 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4647 | } |
| 4648 | } finally { |
| 4649 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4650 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4651 | } |
| 4652 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4653 | /** |
| 4654 | * {@hide} |
| 4655 | * Returns Default subId, 0 in the case of single standby. |
| 4656 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4657 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4658 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4659 | } |
| 4660 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4661 | private int getSlotForDefaultSubscription() { |
| 4662 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4663 | } |
| 4664 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4665 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4666 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4667 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4668 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4669 | private boolean isActiveSubscription(int subId) { |
| 4670 | return mSubscriptionController.isActiveSubId(subId); |
| 4671 | } |
| 4672 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4673 | /** |
| 4674 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4675 | */ |
| 4676 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4677 | final long identity = Binder.clearCallingIdentity(); |
| 4678 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4679 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4680 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4681 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4682 | } finally { |
| 4683 | Binder.restoreCallingIdentity(identity); |
| 4684 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4685 | } |
| 4686 | |
| 4687 | /** |
| 4688 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4689 | */ |
| 4690 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4691 | final long identity = Binder.clearCallingIdentity(); |
| 4692 | try { |
| 4693 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4694 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4695 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4696 | } finally { |
| 4697 | Binder.restoreCallingIdentity(identity); |
| 4698 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4699 | } |
| 4700 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4701 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4702 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4703 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4704 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4705 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4706 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4707 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4708 | if (phoneId == -1) { |
| 4709 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4710 | + " does not correspond to an active phone"); |
| 4711 | } |
| 4712 | return PhoneFactory.getPhone(phoneId); |
| 4713 | } |
| 4714 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4715 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4716 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4717 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4718 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4719 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4720 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4721 | if (DBG) { |
| 4722 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4723 | } |
| 4724 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4725 | p2); |
| 4726 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4727 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4728 | |
| 4729 | @Override |
| 4730 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4731 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4732 | enforceModifyPermission(); |
| 4733 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4734 | if (DBG) { |
| 4735 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4736 | } |
| 4737 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4738 | callingPackage, aid, p2); |
| 4739 | } |
| 4740 | |
| 4741 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4742 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4743 | final long identity = Binder.clearCallingIdentity(); |
| 4744 | try { |
| 4745 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4746 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4747 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4748 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4749 | if (bestComponent == null |
| 4750 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4751 | loge("The calling package is not allowed to access ISD-R."); |
| 4752 | throw new SecurityException( |
| 4753 | "The calling package is not allowed to access ISD-R."); |
| 4754 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4755 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4756 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4757 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4758 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4759 | null /* workSource */); |
| 4760 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4761 | return response; |
| 4762 | } finally { |
| 4763 | Binder.restoreCallingIdentity(identity); |
| 4764 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4765 | } |
| 4766 | |
| 4767 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4768 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4769 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4770 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4771 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4772 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4773 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4774 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4775 | @Override |
| 4776 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4777 | enforceModifyPermission(); |
| 4778 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4779 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4780 | channel); |
| 4781 | } |
| 4782 | |
| 4783 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4784 | final long identity = Binder.clearCallingIdentity(); |
| 4785 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4786 | if (channel < 0) { |
| 4787 | return false; |
| 4788 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4789 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4790 | null /* workSource */); |
| 4791 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4792 | return success; |
| 4793 | } finally { |
| 4794 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4795 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4796 | } |
| 4797 | |
| 4798 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4799 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4800 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4801 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4802 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4803 | if (DBG) { |
| 4804 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4805 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4806 | + p3 + " data=" + data); |
| 4807 | } |
| 4808 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4809 | command, p1, p2, p3, data); |
| 4810 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4811 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4812 | @Override |
| 4813 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4814 | int command, int p1, int p2, int p3, String data) { |
| 4815 | enforceModifyPermission(); |
| 4816 | if (DBG) { |
| 4817 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4818 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4819 | + p3 + " data=" + data); |
| 4820 | } |
| 4821 | return iccTransmitApduLogicalChannelWithPermission( |
| 4822 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4823 | data); |
| 4824 | } |
| 4825 | |
| 4826 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4827 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4828 | final long identity = Binder.clearCallingIdentity(); |
| 4829 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4830 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4831 | return ""; |
| 4832 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4833 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4834 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4835 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4836 | null /* workSource */); |
| 4837 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4838 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4839 | // Append the returned status code to the end of the response payload. |
| 4840 | String s = Integer.toHexString( |
| 4841 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4842 | if (response.payload != null) { |
| 4843 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4844 | } |
| 4845 | return s; |
| 4846 | } finally { |
| 4847 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4848 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4849 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4850 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4851 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4852 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4853 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4854 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4855 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4856 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4857 | if (DBG) { |
| 4858 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4859 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4860 | } |
| 4861 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4862 | cla, command, p1, p2, p3, data); |
| 4863 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4864 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4865 | @Override |
| 4866 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4867 | int command, int p1, int p2, int p3, String data) { |
| 4868 | enforceModifyPermission(); |
| 4869 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4870 | if (DBG) { |
| 4871 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4872 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4873 | + " data=" + data); |
| 4874 | } |
| 4875 | |
| 4876 | return iccTransmitApduBasicChannelWithPermission( |
| 4877 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4878 | p2, p3, data); |
| 4879 | } |
| 4880 | |
| 4881 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4882 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4883 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4884 | final long identity = Binder.clearCallingIdentity(); |
| 4885 | try { |
| 4886 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4887 | && TextUtils.equals(ISDR_AID, data)) { |
| 4888 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4889 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4890 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4891 | if (bestComponent == null |
| 4892 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4893 | loge("The calling package is not allowed to select ISD-R."); |
| 4894 | throw new SecurityException( |
| 4895 | "The calling package is not allowed to select ISD-R."); |
| 4896 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4897 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4898 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4899 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4900 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4901 | null /* workSource */); |
| 4902 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4903 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4904 | // Append the returned status code to the end of the response payload. |
| 4905 | String s = Integer.toHexString( |
| 4906 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4907 | if (response.payload != null) { |
| 4908 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4909 | } |
| 4910 | return s; |
| 4911 | } finally { |
| 4912 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4913 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4914 | } |
| 4915 | |
| 4916 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4917 | 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] | 4918 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4919 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4920 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4921 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4922 | final long identity = Binder.clearCallingIdentity(); |
| 4923 | try { |
| 4924 | if (DBG) { |
| 4925 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4926 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4927 | } |
| 4928 | |
| 4929 | IccIoResult response = |
| 4930 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4931 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4932 | subId); |
| 4933 | |
| 4934 | if (DBG) { |
| 4935 | log("Exchange SIM_IO [R]" + response); |
| 4936 | } |
| 4937 | |
| 4938 | byte[] result = null; |
| 4939 | int length = 2; |
| 4940 | if (response.payload != null) { |
| 4941 | length = 2 + response.payload.length; |
| 4942 | result = new byte[length]; |
| 4943 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 4944 | } else { |
| 4945 | result = new byte[length]; |
| 4946 | } |
| 4947 | |
| 4948 | result[length - 1] = (byte) response.sw2; |
| 4949 | result[length - 2] = (byte) response.sw1; |
| 4950 | return result; |
| 4951 | } finally { |
| 4952 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4953 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4954 | } |
| 4955 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4956 | /** |
| 4957 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 4958 | * on a particular subscription |
| 4959 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4960 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 4961 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4962 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4963 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 4964 | return null; |
| 4965 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4966 | |
| 4967 | final long identity = Binder.clearCallingIdentity(); |
| 4968 | try { |
| 4969 | if (appType != TelephonyManager.APPTYPE_USIM |
| 4970 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 4971 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 4972 | return null; |
| 4973 | } |
| 4974 | Object response = sendRequest( |
| 4975 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 4976 | if (response instanceof String[]) { |
| 4977 | return (String[]) response; |
| 4978 | } |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4979 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4980 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4981 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4982 | } finally { |
| 4983 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4984 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 4985 | } |
| 4986 | |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4987 | /** |
| 4988 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 4989 | * subscription. |
| 4990 | * |
| 4991 | * @param subId the id of the subscription. |
| 4992 | * @param appType the uicc app type, must be USIM or SIM. |
| 4993 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 4994 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4995 | * @param callingFeatureId the feature in the package. |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 4996 | * @return number of fplmns that is successfully written to the SIM. |
| 4997 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4998 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 4999 | String callingFeatureId) { |
| 5000 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 5001 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5002 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 5003 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 5004 | } |
| 5005 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5006 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5007 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5008 | } |
| 5009 | if (fplmns == null) { |
| 5010 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5011 | } |
| 5012 | for (String fplmn : fplmns) { |
| 5013 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5014 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5015 | } |
| 5016 | } |
| 5017 | final long identity = Binder.clearCallingIdentity(); |
| 5018 | try { |
| 5019 | Object response = sendRequest( |
| 5020 | CMD_SET_FORBIDDEN_PLMNS, |
| 5021 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5022 | subId); |
| 5023 | return (int) response; |
| 5024 | } finally { |
| 5025 | Binder.restoreCallingIdentity(identity); |
| 5026 | } |
| 5027 | } |
| 5028 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5029 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5030 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5031 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5032 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5033 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5034 | final long identity = Binder.clearCallingIdentity(); |
| 5035 | try { |
| 5036 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5037 | if (response.payload == null) { |
| 5038 | return ""; |
| 5039 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5040 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5041 | // Append the returned status code to the end of the response payload. |
| 5042 | String s = Integer.toHexString( |
| 5043 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5044 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5045 | return s; |
| 5046 | } finally { |
| 5047 | Binder.restoreCallingIdentity(identity); |
| 5048 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5049 | } |
| 5050 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5051 | /** |
| 5052 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5053 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5054 | * |
| 5055 | * @param itemID the ID of the item to read |
| 5056 | * @return the NV item as a String, or null on error. |
| 5057 | */ |
| 5058 | @Override |
| 5059 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5060 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5061 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5062 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5063 | |
| 5064 | final long identity = Binder.clearCallingIdentity(); |
| 5065 | try { |
| 5066 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5067 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5068 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5069 | return value; |
| 5070 | } finally { |
| 5071 | Binder.restoreCallingIdentity(identity); |
| 5072 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5073 | } |
| 5074 | |
| 5075 | /** |
| 5076 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5077 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5078 | * |
| 5079 | * @param itemID the ID of the item to read |
| 5080 | * @param itemValue the value to write, as a String |
| 5081 | * @return true on success; false on any failure |
| 5082 | */ |
| 5083 | @Override |
| 5084 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5085 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5086 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5087 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5088 | |
| 5089 | final long identity = Binder.clearCallingIdentity(); |
| 5090 | try { |
| 5091 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5092 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5093 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5094 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5095 | return success; |
| 5096 | } finally { |
| 5097 | Binder.restoreCallingIdentity(identity); |
| 5098 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5099 | } |
| 5100 | |
| 5101 | /** |
| 5102 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5103 | * Used for device configuration by some CDMA operators. |
| 5104 | * |
| 5105 | * @param preferredRoamingList byte array containing the new PRL |
| 5106 | * @return true on success; false on any failure |
| 5107 | */ |
| 5108 | @Override |
| 5109 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5110 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5111 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5112 | |
| 5113 | final long identity = Binder.clearCallingIdentity(); |
| 5114 | try { |
| 5115 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5116 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5117 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5118 | return success; |
| 5119 | } finally { |
| 5120 | Binder.restoreCallingIdentity(identity); |
| 5121 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5122 | } |
| 5123 | |
| 5124 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5125 | * 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] | 5126 | * Used for device configuration by some CDMA operators. |
| 5127 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5128 | * @param slotIndex - device slot. |
| 5129 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5130 | * @return true on success; false on any failure |
| 5131 | */ |
| 5132 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5133 | public boolean resetModemConfig(int slotIndex) { |
| 5134 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5135 | if (phone != null) { |
| 5136 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5137 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5138 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5139 | final long identity = Binder.clearCallingIdentity(); |
| 5140 | try { |
| 5141 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5142 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5143 | return success; |
| 5144 | } finally { |
| 5145 | Binder.restoreCallingIdentity(identity); |
| 5146 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5147 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5148 | return false; |
| 5149 | } |
| 5150 | |
| 5151 | /** |
| 5152 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5153 | * |
| 5154 | * @param slotIndex - device slot. |
| 5155 | * |
| 5156 | * @return true on success; false on any failure |
| 5157 | */ |
| 5158 | @Override |
| 5159 | public boolean rebootModem(int slotIndex) { |
| 5160 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5161 | if (phone != null) { |
| 5162 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5163 | mApp, phone.getSubId(), "rebootModem"); |
| 5164 | |
| 5165 | final long identity = Binder.clearCallingIdentity(); |
| 5166 | try { |
| 5167 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5168 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5169 | return success; |
| 5170 | } finally { |
| 5171 | Binder.restoreCallingIdentity(identity); |
| 5172 | } |
| 5173 | } |
| 5174 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5175 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5176 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5177 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5178 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5179 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5180 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5181 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5182 | return new String[0]; |
| 5183 | } |
| 5184 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5185 | final long identity = Binder.clearCallingIdentity(); |
| 5186 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5187 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5188 | } finally { |
| 5189 | Binder.restoreCallingIdentity(identity); |
| 5190 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5191 | } |
| 5192 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5193 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5194 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5195 | * {@link #disableIms(int)}. |
| 5196 | * @param slotIndex device slot. |
| 5197 | */ |
| 5198 | public void resetIms(int slotIndex) { |
| 5199 | enforceModifyPermission(); |
| 5200 | |
| 5201 | final long identity = Binder.clearCallingIdentity(); |
| 5202 | try { |
| 5203 | if (mImsResolver == null) { |
| 5204 | // may happen if the does not support IMS. |
| 5205 | return; |
| 5206 | } |
| 5207 | mImsResolver.disableIms(slotIndex); |
| 5208 | mImsResolver.enableIms(slotIndex); |
| 5209 | } finally { |
| 5210 | Binder.restoreCallingIdentity(identity); |
| 5211 | } |
| 5212 | } |
| 5213 | |
| 5214 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5215 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5216 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5217 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5218 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5219 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5220 | |
| 5221 | final long identity = Binder.clearCallingIdentity(); |
| 5222 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5223 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5224 | // may happen if the device does not support IMS. |
| 5225 | return; |
| 5226 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5227 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5228 | } finally { |
| 5229 | Binder.restoreCallingIdentity(identity); |
| 5230 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5231 | } |
| 5232 | |
| 5233 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5234 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5235 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5236 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5237 | public void disableIms(int slotId) { |
| 5238 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5239 | |
| 5240 | final long identity = Binder.clearCallingIdentity(); |
| 5241 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5242 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5243 | // may happen if the device does not support IMS. |
| 5244 | return; |
| 5245 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5246 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5247 | } finally { |
| 5248 | Binder.restoreCallingIdentity(identity); |
| 5249 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5250 | } |
| 5251 | |
| 5252 | /** |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5253 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5254 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5255 | */ |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5256 | @Override |
Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5257 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5258 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5259 | |
| 5260 | final long identity = Binder.clearCallingIdentity(); |
| 5261 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5262 | if (mImsResolver == null) { |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5263 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5264 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5265 | } |
Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5266 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5267 | } finally { |
| 5268 | Binder.restoreCallingIdentity(identity); |
| 5269 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5270 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5271 | /** |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5272 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5273 | */ |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5274 | @Override |
| 5275 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5276 | enforceModifyPermission(); |
| 5277 | |
| 5278 | final long identity = Binder.clearCallingIdentity(); |
| 5279 | try { |
| 5280 | if (mImsResolver == null) return; |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5281 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5282 | } finally { |
| 5283 | Binder.restoreCallingIdentity(identity); |
| 5284 | } |
| 5285 | } |
| 5286 | |
| 5287 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5288 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5289 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5290 | */ |
| 5291 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5292 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5293 | |
| 5294 | final long identity = Binder.clearCallingIdentity(); |
| 5295 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5296 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5297 | // may happen if the device does not support IMS. |
| 5298 | return null; |
| 5299 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5300 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5301 | } finally { |
| 5302 | Binder.restoreCallingIdentity(identity); |
| 5303 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5304 | } |
| 5305 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5306 | /** |
| 5307 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5308 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5309 | */ |
| 5310 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5311 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5312 | |
| 5313 | final long identity = Binder.clearCallingIdentity(); |
| 5314 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5315 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5316 | // may happen if the device does not support IMS. |
| 5317 | return null; |
| 5318 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5319 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5320 | } finally { |
| 5321 | Binder.restoreCallingIdentity(identity); |
| 5322 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5323 | } |
| 5324 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5325 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5326 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5327 | * |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5328 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5329 | * @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] | 5330 | * ImsService is the device default ImsService. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5331 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5332 | * @param packageName The name of the package that the current configuration will be replaced |
| 5333 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5334 | * @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] | 5335 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5336 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5337 | int[] featureTypes, String packageName) { |
| 5338 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5339 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5340 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5341 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5342 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5343 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5344 | final long identity = Binder.clearCallingIdentity(); |
| 5345 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5346 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5347 | // may happen if the device does not support IMS. |
| 5348 | return false; |
| 5349 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5350 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5351 | for (int featureType : featureTypes) { |
| 5352 | featureConfig.put(featureType, packageName); |
| 5353 | } |
| 5354 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5355 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5356 | } finally { |
| 5357 | Binder.restoreCallingIdentity(identity); |
| 5358 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5359 | } |
| 5360 | |
| 5361 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5362 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5363 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5364 | * |
| 5365 | * This should only be used for testing. |
| 5366 | * |
| 5367 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5368 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5369 | */ |
| 5370 | @Override |
| 5371 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5372 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5373 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5374 | "clearCarrierImsServiceOverride"); |
| 5375 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5376 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5377 | "clearCarrierImsServiceOverride"); |
| 5378 | |
| 5379 | final long identity = Binder.clearCallingIdentity(); |
| 5380 | try { |
| 5381 | if (mImsResolver == null) { |
| 5382 | // may happen if the device does not support IMS. |
| 5383 | return false; |
| 5384 | } |
| 5385 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5386 | } finally { |
| 5387 | Binder.restoreCallingIdentity(identity); |
| 5388 | } |
| 5389 | } |
| 5390 | |
| 5391 | /** |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5392 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5393 | * |
| 5394 | * @param slotId The slot that the ImsService is associated with. |
| 5395 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5396 | * the device default. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5397 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5398 | * @return the package name of the ImsService configuration. |
| 5399 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5400 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5401 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5402 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5403 | TelephonyPermissions |
| 5404 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5405 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5406 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5407 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5408 | final long identity = Binder.clearCallingIdentity(); |
| 5409 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5410 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5411 | // may happen if the device does not support IMS. |
| 5412 | return ""; |
| 5413 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5414 | // TODO: change API to query RCS separately. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5415 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5416 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5417 | } finally { |
| 5418 | Binder.restoreCallingIdentity(identity); |
| 5419 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5420 | } |
| 5421 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5422 | /** |
| 5423 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5424 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5425 | * @param callback A callback with an integer containing the |
| 5426 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5427 | */ |
| 5428 | @Override |
| 5429 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5430 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5431 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5432 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5433 | "IMS not available on device."); |
| 5434 | } |
| 5435 | final long token = Binder.clearCallingIdentity(); |
| 5436 | try { |
| 5437 | int slotId = getSlotIndex(subId); |
| 5438 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5439 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5440 | + subId + "'"); |
| 5441 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5442 | } |
| 5443 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5444 | try { |
| 5445 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5446 | } catch (RemoteException e) { |
| 5447 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5448 | + "Ignore"); |
| 5449 | } |
| 5450 | }); |
| 5451 | } finally { |
| 5452 | Binder.restoreCallingIdentity(token); |
| 5453 | } |
| 5454 | } |
| 5455 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5456 | public void setImsRegistrationState(boolean registered) { |
| 5457 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5458 | |
| 5459 | final long identity = Binder.clearCallingIdentity(); |
| 5460 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5461 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5462 | } finally { |
| 5463 | Binder.restoreCallingIdentity(identity); |
| 5464 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5465 | } |
| 5466 | |
| 5467 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5468 | * Set the network selection mode to automatic. |
| 5469 | * |
| 5470 | */ |
| 5471 | @Override |
| 5472 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5473 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5474 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5475 | |
| 5476 | final long identity = Binder.clearCallingIdentity(); |
| 5477 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5478 | if (!isActiveSubscription(subId)) { |
| 5479 | return; |
| 5480 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5481 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 5482 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 5483 | } finally { |
| 5484 | Binder.restoreCallingIdentity(identity); |
| 5485 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5486 | } |
| 5487 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5488 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5489 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5490 | * |
| 5491 | * @param subId the id of the subscription. |
| 5492 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5493 | * the operator to attach to. |
| 5494 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5495 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5496 | * normal network selection next time. |
| 5497 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5498 | */ |
| 5499 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5500 | public boolean setNetworkSelectionModeManual( |
| 5501 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5502 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5503 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5504 | |
| 5505 | if (!isActiveSubscription(subId)) { |
| 5506 | return false; |
| 5507 | } |
| 5508 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5509 | final long identity = Binder.clearCallingIdentity(); |
| 5510 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5511 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5512 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5513 | if (DBG) { |
| 5514 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5515 | + " operator: " + operatorInfo); |
| 5516 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5517 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5518 | } finally { |
| 5519 | Binder.restoreCallingIdentity(identity); |
| 5520 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5521 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5522 | /** |
| 5523 | * Get the manual network selection |
| 5524 | * |
| 5525 | * @param subId the id of the subscription. |
| 5526 | * |
| 5527 | * @return the previously saved user selected PLMN |
| 5528 | */ |
| 5529 | @Override |
| 5530 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5531 | TelephonyPermissions |
| 5532 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5533 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5534 | |
| 5535 | final long identity = Binder.clearCallingIdentity(); |
| 5536 | try { |
| 5537 | if (!isActiveSubscription(subId)) { |
| 5538 | return ""; |
| 5539 | } |
| 5540 | |
| 5541 | final Phone phone = getPhone(subId); |
| 5542 | if (phone == null) { |
| 5543 | return ""; |
| 5544 | } |
| 5545 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5546 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5547 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5548 | } finally { |
| 5549 | Binder.restoreCallingIdentity(identity); |
| 5550 | } |
| 5551 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5552 | |
| 5553 | /** |
| 5554 | * Scans for available networks. |
| 5555 | */ |
| 5556 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5557 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5558 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5559 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5560 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5561 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5562 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5563 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5564 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5565 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5566 | .setCallingPid(Binder.getCallingPid()) |
| 5567 | .setCallingUid(Binder.getCallingUid()) |
| 5568 | .setMethod("getCellNetworkScanResults") |
| 5569 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5570 | .build()); |
| 5571 | switch (locationResult) { |
| 5572 | case DENIED_HARD: |
| 5573 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5574 | case DENIED_SOFT: |
| 5575 | return null; |
| 5576 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5577 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5578 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5579 | try { |
| 5580 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5581 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5582 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5583 | } finally { |
| 5584 | Binder.restoreCallingIdentity(identity); |
| 5585 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5586 | } |
| 5587 | |
| 5588 | /** |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5589 | * Get the call forwarding info, given the call forwarding reason. |
| 5590 | */ |
| 5591 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5592 | public void getCallForwarding(int subId, int callForwardingReason, |
| 5593 | ICallForwardingInfoCallback callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5594 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5595 | long identity = Binder.clearCallingIdentity(); |
| 5596 | try { |
| 5597 | if (DBG) { |
| 5598 | log("getCallForwarding: subId " + subId |
| 5599 | + " callForwardingReason" + callForwardingReason); |
| 5600 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5601 | |
| 5602 | Phone phone = getPhone(subId); |
| 5603 | if (phone == null) { |
| 5604 | try { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5605 | callback.onError( |
| 5606 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5607 | } catch (RemoteException e) { |
| 5608 | // ignore |
| 5609 | } |
| 5610 | return; |
| 5611 | } |
| 5612 | |
| 5613 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 5614 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 5615 | @Override |
| 5616 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 5617 | try { |
| 5618 | callback.onCallForwardingInfoAvailable(info); |
| 5619 | } catch (RemoteException e) { |
| 5620 | // ignore |
| 5621 | } |
| 5622 | } |
| 5623 | |
| 5624 | @Override |
| 5625 | public void onError(int error) { |
| 5626 | try { |
| 5627 | callback.onError(error); |
| 5628 | } catch (RemoteException e) { |
| 5629 | // ignore |
| 5630 | } |
| 5631 | } |
| 5632 | }); |
| 5633 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5634 | } finally { |
| 5635 | Binder.restoreCallingIdentity(identity); |
| 5636 | } |
| 5637 | } |
| 5638 | |
| 5639 | /** |
| 5640 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5641 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5642 | */ |
| 5643 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5644 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 5645 | IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5646 | enforceModifyPermission(); |
| 5647 | long identity = Binder.clearCallingIdentity(); |
| 5648 | try { |
| 5649 | if (DBG) { |
| 5650 | log("setCallForwarding: subId " + subId |
| 5651 | + " callForwardingInfo" + callForwardingInfo); |
| 5652 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5653 | |
| 5654 | Phone phone = getPhone(subId); |
| 5655 | if (phone == null) { |
| 5656 | try { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5657 | callback.accept( |
| 5658 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5659 | } catch (RemoteException e) { |
| 5660 | // ignore |
| 5661 | } |
| 5662 | return; |
| 5663 | } |
| 5664 | |
| 5665 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 5666 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5667 | |
| 5668 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5669 | } finally { |
| 5670 | Binder.restoreCallingIdentity(identity); |
| 5671 | } |
| 5672 | } |
| 5673 | |
| 5674 | /** |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5675 | * Get the call waiting status for a subId. |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5676 | */ |
| 5677 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5678 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5679 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5680 | long identity = Binder.clearCallingIdentity(); |
| 5681 | try { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5682 | |
| 5683 | Phone phone = getPhone(subId); |
| 5684 | if (phone == null) { |
| 5685 | try { |
| 5686 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5687 | } catch (RemoteException e) { |
| 5688 | // ignore |
| 5689 | } |
| 5690 | return; |
| 5691 | } |
| 5692 | |
| 5693 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 5694 | |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5695 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5696 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5697 | } finally { |
| 5698 | Binder.restoreCallingIdentity(identity); |
| 5699 | } |
| 5700 | } |
| 5701 | |
| 5702 | /** |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5703 | * Sets whether call waiting is enabled for a given subId. |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5704 | */ |
| 5705 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5706 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5707 | enforceModifyPermission(); |
| 5708 | long identity = Binder.clearCallingIdentity(); |
| 5709 | try { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5710 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 5711 | |
| 5712 | Phone phone = getPhone(subId); |
| 5713 | if (phone == null) { |
| 5714 | try { |
| 5715 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5716 | } catch (RemoteException e) { |
| 5717 | // ignore |
| 5718 | } |
| 5719 | return; |
| 5720 | } |
| 5721 | |
| 5722 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 5723 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5724 | |
| 5725 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5726 | } finally { |
| 5727 | Binder.restoreCallingIdentity(identity); |
| 5728 | } |
| 5729 | } |
| 5730 | |
| 5731 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5732 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5733 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5734 | * @param subId id of the subscription |
| 5735 | * @param request contains the radio access networks with bands/channels to scan |
| 5736 | * @param messenger callback messenger for scan results or errors |
| 5737 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5738 | * @return the id of the requested scan which can be used to stop the scan. |
| 5739 | */ |
| 5740 | @Override |
| 5741 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5742 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5743 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5744 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5745 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5746 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5747 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5748 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5749 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5750 | .setCallingPid(Binder.getCallingPid()) |
| 5751 | .setCallingUid(Binder.getCallingUid()) |
| 5752 | .setMethod("requestNetworkScan") |
| 5753 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5754 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5755 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 284aa04 | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5756 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 5757 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5758 | if (e != null) { |
| 5759 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5760 | throw e; |
| 5761 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5762 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5763 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5764 | } |
| 5765 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5766 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5767 | int callingUid = Binder.getCallingUid(); |
| 5768 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5769 | final long identity = Binder.clearCallingIdentity(); |
| 5770 | try { |
| 5771 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5772 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5773 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5774 | } finally { |
| 5775 | Binder.restoreCallingIdentity(identity); |
| 5776 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5777 | } |
| 5778 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5779 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 284aa04 | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5780 | NetworkScanRequest request, int subId, String callingPackage) { |
| 5781 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5782 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5783 | boolean hasNetworkScanPermission = |
| 5784 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5785 | == PERMISSION_GRANTED; |
| 5786 | |
| 5787 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5788 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5789 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5790 | } |
| 5791 | |
| 5792 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5793 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5794 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5795 | return new SecurityException("Specific channels must not be" |
| 5796 | + " scanned without location access."); |
| 5797 | } |
| 5798 | } |
| 5799 | } |
| 5800 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5801 | return null; |
| 5802 | } |
| 5803 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5804 | /** |
| 5805 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5806 | * |
| 5807 | * @param subId id of the subscription |
| 5808 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5809 | */ |
| 5810 | @Override |
| 5811 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5812 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5813 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5814 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5815 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5816 | final long identity = Binder.clearCallingIdentity(); |
| 5817 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5818 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5819 | } finally { |
| 5820 | Binder.restoreCallingIdentity(identity); |
| 5821 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5822 | } |
| 5823 | |
| 5824 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5825 | * Get the calculated preferred network type. |
| 5826 | * Used for debugging incorrect network type. |
| 5827 | * |
| 5828 | * @return the preferred network type, defined in RILConstants.java. |
| 5829 | */ |
| 5830 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5831 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5832 | final Phone defaultPhone = getDefaultPhone(); |
| 5833 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5834 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5835 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5836 | } |
| 5837 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5838 | final long identity = Binder.clearCallingIdentity(); |
| 5839 | try { |
| 5840 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5841 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5842 | } finally { |
| 5843 | Binder.restoreCallingIdentity(identity); |
| 5844 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5845 | } |
| 5846 | |
| 5847 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5848 | * Get the preferred network type. |
| 5849 | * Used for device configuration by some CDMA operators. |
| 5850 | * |
| 5851 | * @return the preferred network type, defined in RILConstants.java. |
| 5852 | */ |
| 5853 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5854 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5855 | TelephonyPermissions |
| 5856 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5857 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5858 | |
| 5859 | final long identity = Binder.clearCallingIdentity(); |
| 5860 | try { |
| 5861 | if (DBG) log("getPreferredNetworkType"); |
| 5862 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5863 | int networkType = (result != null ? result[0] : -1); |
| 5864 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5865 | return networkType; |
| 5866 | } finally { |
| 5867 | Binder.restoreCallingIdentity(identity); |
| 5868 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5869 | } |
| 5870 | |
| 5871 | /** |
| 5872 | * Set the preferred network type. |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5873 | * |
| 5874 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5875 | * @return true on success; false on any failure. |
| 5876 | */ |
| 5877 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5878 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5879 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5880 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5881 | |
| 5882 | final long identity = Binder.clearCallingIdentity(); |
| 5883 | try { |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5884 | Settings.Global.putInt(mApp.getContentResolver(), |
| 5885 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5886 | |
| 5887 | Boolean success = (Boolean) sendRequest( |
| 5888 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
| 5889 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 5890 | return success; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5891 | } finally { |
| 5892 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5893 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5894 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5895 | |
| 5896 | /** |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5897 | * Get the allowed network types that store in the telephony provider. |
| 5898 | * |
| 5899 | * @param subId the id of the subscription. |
| 5900 | * @return allowedNetworkTypes the allowed network types. |
| 5901 | */ |
| 5902 | @Override |
| 5903 | public long getAllowedNetworkTypes(int subId) { |
| 5904 | TelephonyPermissions |
| 5905 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5906 | mApp, subId, "getAllowedNetworkTypes"); |
| 5907 | |
| 5908 | final long identity = Binder.clearCallingIdentity(); |
| 5909 | try { |
| 5910 | return SubscriptionManager.getLongSubscriptionProperty( |
| 5911 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5912 | } finally { |
| 5913 | Binder.restoreCallingIdentity(identity); |
| 5914 | } |
| 5915 | } |
| 5916 | |
| 5917 | /** |
| 5918 | * Set the allowed network types. |
| 5919 | * |
| 5920 | * @param subId the id of the subscription. |
| 5921 | * @param allowedNetworkTypes the allowed network types. |
| 5922 | * @return true on success; false on any failure. |
| 5923 | */ |
| 5924 | @Override |
| 5925 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 5926 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5927 | mApp, subId, "setAllowedNetworkTypes"); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5928 | |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5929 | SubscriptionManager.setSubscriptionProperty(subId, |
| 5930 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 5931 | String.valueOf(allowedNetworkTypes)); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5932 | |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5933 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 5934 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5935 | RILConstants.PREFERRED_NETWORK_MODE); |
| 5936 | return setPreferredNetworkType(subId, preferredNetworkMode); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5937 | } |
| 5938 | |
| 5939 | /** |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 5940 | * Get the allowed network types for certain reason. |
| 5941 | * |
| 5942 | * @param subId the id of the subscription. |
| 5943 | * @param reason the reason the allowed network type change is taking place |
| 5944 | * @return the allowed network types. |
| 5945 | */ |
| 5946 | @Override |
| 5947 | public long getAllowedNetworkTypesForReason(int subId, |
| 5948 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
| 5949 | TelephonyPermissions |
| 5950 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5951 | mApp, subId, "getAllowedNetworkTypesForReason"); |
| 5952 | final long identity = Binder.clearCallingIdentity(); |
| 5953 | try { |
| 5954 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 5955 | } finally { |
| 5956 | Binder.restoreCallingIdentity(identity); |
| 5957 | } |
| 5958 | } |
| 5959 | |
| 5960 | /** |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 5961 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 5962 | * @param subId subscription id of the sim card |
| 5963 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 5964 | * This can be passed following states |
| 5965 | * <ol> |
| 5966 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 5967 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 5968 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 5969 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 5970 | * </ol> |
| 5971 | * @return operation result. |
| 5972 | */ |
| 5973 | @Override |
| 5974 | public int setNrDualConnectivityState(int subId, |
| 5975 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 5976 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5977 | mApp, subId, "enableNRDualConnectivity"); |
| 5978 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 5979 | final long identity = Binder.clearCallingIdentity(); |
| 5980 | try { |
| 5981 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 5982 | nrDualConnectivityState, subId, |
| 5983 | workSource); |
| 5984 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 5985 | return result; |
| 5986 | } finally { |
| 5987 | Binder.restoreCallingIdentity(identity); |
| 5988 | } |
| 5989 | } |
| 5990 | |
| 5991 | /** |
| 5992 | * Is E-UTRA-NR Dual Connectivity enabled |
| 5993 | * @return true if dual connectivity is enabled else false |
| 5994 | */ |
| 5995 | @Override |
| 5996 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 5997 | TelephonyPermissions |
| 5998 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5999 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6000 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6001 | final long identity = Binder.clearCallingIdentity(); |
| 6002 | try { |
| 6003 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6004 | null, subId, workSource); |
| 6005 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6006 | return isEnabled; |
| 6007 | } finally { |
| 6008 | Binder.restoreCallingIdentity(identity); |
| 6009 | } |
| 6010 | } |
| 6011 | |
| 6012 | /** |
Sooraj Sasindran | 1f812e0 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 6013 | * get carrier bandwidth per primary and secondary carrier |
| 6014 | * @param subId subscription id of the sim card |
| 6015 | * @return CarrierBandwidth with bandwidth of both primary and secondary carrier.. |
| 6016 | */ |
| 6017 | @Override |
| 6018 | public CarrierBandwidth getCarrierBandwidth(int subId) { |
| 6019 | TelephonyPermissions |
| 6020 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6021 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6022 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6023 | final long identity = Binder.clearCallingIdentity(); |
| 6024 | try { |
| 6025 | CarrierBandwidth carrierBandwidth = |
| 6026 | getPhoneFromSubId(subId).getCarrierBandwidth(); |
| 6027 | if (DBG) log("getCarrierBandwidth: " + carrierBandwidth); |
| 6028 | return carrierBandwidth; |
| 6029 | } finally { |
| 6030 | Binder.restoreCallingIdentity(identity); |
| 6031 | } |
| 6032 | } |
| 6033 | |
| 6034 | /** |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6035 | * Get the effective allowed network types on the device. |
| 6036 | * This API will return an intersection of allowed network types for all reasons, |
| 6037 | * including the configuration done through setAllowedNetworkTypes |
| 6038 | * |
| 6039 | * @param subId the id of the subscription. |
| 6040 | * @return the allowed network types |
| 6041 | */ |
| 6042 | @Override |
| 6043 | public long getEffectiveAllowedNetworkTypes(int subId) { |
| 6044 | TelephonyPermissions |
| 6045 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6046 | mApp, subId, "getEffectiveAllowedNetworkTypes"); |
| 6047 | final long identity = Binder.clearCallingIdentity(); |
| 6048 | try { |
| 6049 | return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes(); |
| 6050 | } finally { |
| 6051 | Binder.restoreCallingIdentity(identity); |
| 6052 | } |
| 6053 | } |
| 6054 | |
| 6055 | /** |
| 6056 | * Set the allowed network types of the device and |
| 6057 | * provide the reason triggering the allowed network change. |
| 6058 | * |
| 6059 | * @param subId the id of the subscription. |
| 6060 | * @param reason the reason the allowed network type change is taking place |
| 6061 | * @param allowedNetworkTypes the allowed network types. |
| 6062 | * @return true on success; false on any failure. |
| 6063 | */ |
| 6064 | @Override |
| 6065 | public boolean setAllowedNetworkTypesForReason(int subId, |
| 6066 | @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) { |
| 6067 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6068 | mApp, subId, "setAllowedNetworkTypesForReason"); |
| 6069 | final long identity = Binder.clearCallingIdentity(); |
| 6070 | try { |
| 6071 | getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes); |
| 6072 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 6073 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 6074 | RILConstants.PREFERRED_NETWORK_MODE); |
| 6075 | return setPreferredNetworkType(subId, preferredNetworkMode); |
| 6076 | } finally { |
| 6077 | Binder.restoreCallingIdentity(identity); |
| 6078 | } |
| 6079 | } |
| 6080 | |
| 6081 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6082 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6083 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6084 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6085 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6086 | * @hide |
| 6087 | */ |
| 6088 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6089 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6090 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6091 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6092 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6093 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6094 | if (phone != null) { |
| 6095 | return phone.hasMatchedTetherApnSetting(); |
| 6096 | } else { |
| 6097 | return false; |
| 6098 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6099 | } finally { |
| 6100 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6101 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6102 | } |
| 6103 | |
| 6104 | /** |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6105 | * Enable or disable always reporting signal strength changes from radio. |
| 6106 | * |
| 6107 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 6108 | */ |
| 6109 | @Override |
| 6110 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 6111 | enforceModifyPermission(); |
| 6112 | enforceSystemCaller(); |
| 6113 | |
| 6114 | final long identity = Binder.clearCallingIdentity(); |
| 6115 | final Phone phone = getPhone(subId); |
| 6116 | try { |
| 6117 | if (phone != null) { |
| 6118 | if (DBG) { |
| 6119 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6120 | + " isEnable=" + isEnable); |
| 6121 | } |
| 6122 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6123 | } else { |
| 6124 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6125 | + subId); |
| 6126 | } |
| 6127 | } finally { |
| 6128 | Binder.restoreCallingIdentity(identity); |
| 6129 | } |
| 6130 | } |
| 6131 | |
| 6132 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6133 | * Get the user enabled state of Mobile Data. |
| 6134 | * |
| 6135 | * TODO: remove and use isUserDataEnabled. |
| 6136 | * This can't be removed now because some vendor codes |
| 6137 | * calls through ITelephony directly while they should |
| 6138 | * use TelephonyManager. |
| 6139 | * |
| 6140 | * @return true on enabled |
| 6141 | */ |
| 6142 | @Override |
| 6143 | public boolean getDataEnabled(int subId) { |
| 6144 | return isUserDataEnabled(subId); |
| 6145 | } |
| 6146 | |
| 6147 | /** |
| 6148 | * Get whether mobile data is enabled per user setting. |
| 6149 | * |
| 6150 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6151 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6152 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6153 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6154 | * |
| 6155 | * @return {@code true} if data is enabled else {@code false} |
| 6156 | */ |
| 6157 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6158 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6159 | try { |
| 6160 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6161 | null); |
| 6162 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6163 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6164 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6165 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6166 | |
| 6167 | final long identity = Binder.clearCallingIdentity(); |
| 6168 | try { |
| 6169 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6170 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6171 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6172 | if (phone != null) { |
| 6173 | boolean retVal = phone.isUserDataEnabled(); |
| 6174 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6175 | return retVal; |
| 6176 | } else { |
| 6177 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6178 | return false; |
| 6179 | } |
| 6180 | } finally { |
| 6181 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6182 | } |
| 6183 | } |
| 6184 | |
| 6185 | /** |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6186 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6187 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6188 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6189 | * |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6190 | * @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] | 6191 | */ |
| 6192 | @Override |
| 6193 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6194 | try { |
| 6195 | try { |
| 6196 | mApp.enforceCallingOrSelfPermission( |
| 6197 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6198 | null); |
| 6199 | } catch (Exception e) { |
| 6200 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6201 | "isDataEnabled"); |
| 6202 | } |
| 6203 | } catch (Exception e) { |
| 6204 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6205 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6206 | |
| 6207 | final long identity = Binder.clearCallingIdentity(); |
| 6208 | try { |
| 6209 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6210 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6211 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6212 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6213 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6214 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6215 | return retVal; |
| 6216 | } else { |
| 6217 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6218 | return false; |
| 6219 | } |
| 6220 | } finally { |
| 6221 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6222 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6223 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6224 | |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6225 | /** |
| 6226 | * Check if data is enabled for a specific reason |
| 6227 | * @param subId Subscription index |
| 6228 | * @param reason the reason the data enable change is taking place |
| 6229 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6230 | */ |
| 6231 | @Override |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6232 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6233 | @TelephonyManager.DataEnabledReason int reason) { |
| 6234 | try { |
| 6235 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6236 | null); |
| 6237 | } catch (Exception e) { |
| 6238 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6239 | "isDataEnabledForReason"); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6240 | } |
| 6241 | |
| 6242 | |
| 6243 | final long identity = Binder.clearCallingIdentity(); |
| 6244 | try { |
| 6245 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6246 | if (DBG) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6247 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6248 | + " reason=" + reason); |
| 6249 | } |
| 6250 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6251 | if (phone != null) { |
| 6252 | boolean retVal; |
| 6253 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6254 | retVal = phone.isUserDataEnabled(); |
| 6255 | } else { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6256 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6257 | } |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6258 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6259 | return retVal; |
| 6260 | } else { |
| 6261 | if (DBG) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6262 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6263 | + subId + " retVal=false"); |
| 6264 | } |
| 6265 | return false; |
| 6266 | } |
| 6267 | } finally { |
| 6268 | Binder.restoreCallingIdentity(identity); |
| 6269 | } |
| 6270 | } |
| 6271 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6272 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6273 | Phone phone) { |
Hall Liu | ce478d2 | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 6274 | if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) { |
| 6275 | // Skip the check if it's one of these special uids |
| 6276 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6277 | } |
| 6278 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6279 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6280 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6281 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6282 | || subController == null) return privilegeFromSim; |
| 6283 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6284 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6285 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6286 | |
| 6287 | final long identity = Binder.clearCallingIdentity(); |
| 6288 | try { |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6289 | int subId = phone.getSubId(); |
| 6290 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6291 | // A test override is in place for the privileges for this subId, so don't try to |
| 6292 | // read the subscription privileges. |
| 6293 | return privilegeFromSim; |
| 6294 | } |
| 6295 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6296 | SubscriptionManager subManager = (SubscriptionManager) |
| 6297 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6298 | for (String pkg : packages) { |
| 6299 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6300 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6301 | } |
| 6302 | } |
| 6303 | return privilegeFromSim; |
| 6304 | } finally { |
| 6305 | Binder.restoreCallingIdentity(identity); |
| 6306 | } |
| 6307 | } |
| 6308 | |
| 6309 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6310 | String pkgName) { |
| 6311 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6312 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6313 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6314 | || subController == null) return privilegeFromSim; |
| 6315 | |
| 6316 | final long identity = Binder.clearCallingIdentity(); |
| 6317 | try { |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6318 | int subId = phone.getSubId(); |
| 6319 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6320 | // A test override is in place for the privileges for this subId, so don't try to |
| 6321 | // read the subscription privileges. |
| 6322 | return privilegeFromSim; |
| 6323 | } |
| 6324 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6325 | SubscriptionManager subManager = (SubscriptionManager) |
| 6326 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6327 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6328 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6329 | } finally { |
| 6330 | Binder.restoreCallingIdentity(identity); |
| 6331 | } |
| 6332 | } |
| 6333 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6334 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6335 | public int getCarrierPrivilegeStatus(int subId) { |
| 6336 | final Phone phone = getPhone(subId); |
| 6337 | if (phone == null) { |
| 6338 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6339 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6340 | } |
| 6341 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6342 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6343 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6344 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6345 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6346 | |
| 6347 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6348 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6349 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6350 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6351 | |
| 6352 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6353 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6354 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6355 | final Phone phone = getPhone(subId); |
| 6356 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6357 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6358 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6359 | } |
| 6360 | UiccProfile profile = |
| 6361 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6362 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6363 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6364 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6365 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6366 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6367 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6368 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6369 | } |
| 6370 | |
| 6371 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6372 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 6373 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6374 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6375 | } |
| 6376 | |
| 6377 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 6378 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6379 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6380 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6381 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6382 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6383 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6384 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6385 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6386 | } |
| 6387 | |
| 6388 | @Override |
| 6389 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6390 | if (TextUtils.isEmpty(pkgName)) |
| 6391 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6392 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6393 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6394 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 6395 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6396 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6397 | continue; |
| 6398 | } |
| 6399 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6400 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6401 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6402 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6403 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6404 | break; |
| 6405 | } |
| 6406 | } |
| 6407 | |
| 6408 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6409 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6410 | |
| 6411 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6412 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 6413 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6414 | loge("phoneId " + phoneId + " is not valid."); |
| 6415 | return null; |
| 6416 | } |
| 6417 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6418 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6419 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6420 | return null ; |
| 6421 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6422 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6423 | } |
| 6424 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6425 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6426 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6427 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6428 | List<String> privilegedPackages = new ArrayList<>(); |
| 6429 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6430 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 6431 | // has UICC in that slot. |
| 6432 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6433 | if (card.hasCarrierPrivilegeRules()) { |
| 6434 | if (packages == null) { |
| 6435 | // Only check packages in user 0 for now |
| 6436 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6437 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6438 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6439 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6440 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6441 | } |
| 6442 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6443 | PackageInfo pkgInfo = packages.get(p); |
| 6444 | if (pkgInfo != null && pkgInfo.packageName != null |
| 6445 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6446 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6447 | privilegedPackages.add(pkgInfo.packageName); |
| 6448 | } |
| 6449 | } |
| 6450 | } |
| 6451 | } |
| 6452 | return privilegedPackages; |
| 6453 | } |
| 6454 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6455 | @Override |
| 6456 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6457 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6458 | |
| 6459 | final long identity = Binder.clearCallingIdentity(); |
| 6460 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6461 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6462 | try { |
| 6463 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6464 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6465 | } |
| 6466 | } finally { |
| 6467 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6468 | } |
| 6469 | return privilegedPackages; |
| 6470 | } |
| 6471 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6472 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6473 | final Phone phone = getPhone(subId); |
| 6474 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6475 | if (card == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6476 | return null; |
| 6477 | } |
| 6478 | String iccId = card.getIccId(); |
| 6479 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6480 | return null; |
| 6481 | } |
| 6482 | return iccId; |
| 6483 | } |
| 6484 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6485 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6486 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6487 | String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6488 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6489 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6490 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6491 | final long identity = Binder.clearCallingIdentity(); |
| 6492 | try { |
| 6493 | final String iccId = getIccId(subId); |
| 6494 | final Phone phone = getPhone(subId); |
| 6495 | if (phone == null) { |
| 6496 | return false; |
| 6497 | } |
| 6498 | final String subscriberId = phone.getSubscriberId(); |
| 6499 | |
| 6500 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6501 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6502 | + subscriberId + " to " + number); |
| 6503 | } |
| 6504 | |
| 6505 | if (TextUtils.isEmpty(iccId)) { |
| 6506 | return false; |
| 6507 | } |
| 6508 | |
| 6509 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6510 | |
| 6511 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6512 | if (alphaTag == null) { |
| 6513 | editor.remove(alphaTagPrefKey); |
| 6514 | } else { |
| 6515 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6516 | } |
| 6517 | |
| 6518 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6519 | // track all merged IMSIs based on line number |
| 6520 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6521 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6522 | if (number == null) { |
| 6523 | editor.remove(numberPrefKey); |
| 6524 | editor.remove(subscriberPrefKey); |
| 6525 | } else { |
| 6526 | editor.putString(numberPrefKey, number); |
| 6527 | editor.putString(subscriberPrefKey, subscriberId); |
| 6528 | } |
| 6529 | |
| 6530 | editor.commit(); |
| 6531 | return true; |
| 6532 | } finally { |
| 6533 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6534 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6535 | } |
| 6536 | |
| 6537 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6538 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6539 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6540 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6541 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6542 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6543 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6544 | return null; |
| 6545 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6546 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6547 | final long identity = Binder.clearCallingIdentity(); |
| 6548 | try { |
| 6549 | String iccId = getIccId(subId); |
| 6550 | if (iccId != null) { |
| 6551 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6552 | if (DBG_MERGE) { |
| 6553 | log("getLine1NumberForDisplay returning " |
| 6554 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6555 | } |
| 6556 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6557 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6558 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6559 | return null; |
| 6560 | } finally { |
| 6561 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6562 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6563 | } |
| 6564 | |
| 6565 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6566 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6567 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6568 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6569 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6570 | return null; |
| 6571 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6572 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6573 | final long identity = Binder.clearCallingIdentity(); |
| 6574 | try { |
| 6575 | String iccId = getIccId(subId); |
| 6576 | if (iccId != null) { |
| 6577 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6578 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6579 | } |
| 6580 | return null; |
| 6581 | } finally { |
| 6582 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6583 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6584 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6585 | |
| 6586 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6587 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6588 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6589 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6590 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6591 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6592 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6593 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6594 | return null; |
| 6595 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6596 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6597 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6598 | // the process, where TelephonyManager was instantiated. |
| 6599 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6600 | final long identity = Binder.clearCallingIdentity(); |
| 6601 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6602 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6603 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6604 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6605 | |
| 6606 | // Figure out what subscribers are currently active |
| 6607 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6608 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6609 | // Only consider subs which match the current subId |
| 6610 | // This logic can be simplified. See b/131189269 for progress. |
| 6611 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6612 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6613 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6614 | |
| 6615 | // First pass, find a number override for an active subscriber |
| 6616 | String mergeNumber = null; |
| 6617 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6618 | for (String key : prefs.keySet()) { |
| 6619 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6620 | final String subscriberId = (String) prefs.get(key); |
| 6621 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6622 | final String iccId = key.substring( |
| 6623 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6624 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6625 | mergeNumber = (String) prefs.get(numberKey); |
| 6626 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6627 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6628 | + " for active subscriber " + subscriberId); |
| 6629 | } |
| 6630 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6631 | break; |
| 6632 | } |
| 6633 | } |
| 6634 | } |
| 6635 | } |
| 6636 | |
| 6637 | // Shortcut when no active merged subscribers |
| 6638 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6639 | return null; |
| 6640 | } |
| 6641 | |
| 6642 | // Second pass, find all subscribers under that line override |
| 6643 | final ArraySet<String> result = new ArraySet<>(); |
| 6644 | for (String key : prefs.keySet()) { |
| 6645 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6646 | final String number = (String) prefs.get(key); |
| 6647 | if (mergeNumber.equals(number)) { |
| 6648 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6649 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6650 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6651 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6652 | result.add(subscriberId); |
| 6653 | } |
| 6654 | } |
| 6655 | } |
| 6656 | } |
| 6657 | |
| 6658 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6659 | Arrays.sort(resultArray); |
| 6660 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6661 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6662 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6663 | } |
| 6664 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6665 | } finally { |
| 6666 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6667 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6668 | } |
| 6669 | |
| 6670 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6671 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6672 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6673 | |
| 6674 | final long identity = Binder.clearCallingIdentity(); |
| 6675 | try { |
| 6676 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6677 | TelephonyManager.class); |
| 6678 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6679 | if (subscriberId == null) { |
| 6680 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6681 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6682 | + subId); |
| 6683 | } |
| 6684 | return null; |
| 6685 | } |
| 6686 | |
| 6687 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6688 | .getSubscriptionInfo(subId); |
| 6689 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6690 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6691 | if (groupUuid == null) { |
| 6692 | return new String[]{subscriberId}; |
| 6693 | } |
| 6694 | |
| 6695 | // Get all subscriberIds from the group. |
| 6696 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6697 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6698 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6699 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6700 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6701 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6702 | if (subscriberId != null) { |
| 6703 | mergedSubscriberIds.add(subscriberId); |
| 6704 | } |
| 6705 | } |
| 6706 | |
| 6707 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6708 | } finally { |
| 6709 | Binder.restoreCallingIdentity(identity); |
| 6710 | |
| 6711 | } |
| 6712 | } |
| 6713 | |
| 6714 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6715 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6716 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6717 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6718 | |
| 6719 | final long identity = Binder.clearCallingIdentity(); |
| 6720 | try { |
| 6721 | final Phone phone = getPhone(subId); |
| 6722 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6723 | } finally { |
| 6724 | Binder.restoreCallingIdentity(identity); |
| 6725 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6726 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6727 | |
| 6728 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6729 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6730 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6731 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6732 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6733 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6734 | |
| 6735 | final long identity = Binder.clearCallingIdentity(); |
| 6736 | try { |
| 6737 | final Phone phone = getPhone(subId); |
| 6738 | if (phone == null) { |
| 6739 | return false; |
| 6740 | } |
| 6741 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6742 | cdmaNonRoamingList); |
| 6743 | } finally { |
| 6744 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6745 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6746 | } |
| 6747 | |
| 6748 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6749 | @Deprecated |
| 6750 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6751 | enforceModifyPermission(); |
| 6752 | |
| 6753 | int returnValue = 0; |
| 6754 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6755 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6756 | if(result.exception == null) { |
| 6757 | if (result.result != null) { |
| 6758 | byte[] responseData = (byte[])(result.result); |
| 6759 | if(responseData.length > oemResp.length) { |
| 6760 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6761 | responseData.length + "bytes. Buffer Size is " + |
| 6762 | oemResp.length + "bytes."); |
| 6763 | } |
| 6764 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6765 | returnValue = responseData.length; |
| 6766 | } |
| 6767 | } else { |
| 6768 | CommandException ex = (CommandException) result.exception; |
| 6769 | returnValue = ex.getCommandError().ordinal(); |
| 6770 | if(returnValue > 0) returnValue *= -1; |
| 6771 | } |
| 6772 | } catch (RuntimeException e) { |
| 6773 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6774 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6775 | if(returnValue > 0) returnValue *= -1; |
| 6776 | } |
| 6777 | |
| 6778 | return returnValue; |
| 6779 | } |
| 6780 | |
| 6781 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6782 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6783 | try { |
| 6784 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6785 | } catch (RuntimeException e) { |
| 6786 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6787 | } |
| 6788 | } |
| 6789 | |
| 6790 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6791 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6792 | Phone phone = PhoneFactory.getPhone(phoneId); |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6793 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6794 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6795 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6796 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6797 | final long identity = Binder.clearCallingIdentity(); |
| 6798 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6799 | TelephonyPermissions |
| 6800 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6801 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6802 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6803 | } finally { |
| 6804 | Binder.restoreCallingIdentity(identity); |
| 6805 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6806 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6807 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6808 | |
| 6809 | @Override |
| 6810 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6811 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6812 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6813 | |
| 6814 | final long identity = Binder.clearCallingIdentity(); |
| 6815 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6816 | ImsManager.getInstance(defaultPhone.getContext(), |
| 6817 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6818 | } finally { |
| 6819 | Binder.restoreCallingIdentity(identity); |
| 6820 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6821 | } |
| 6822 | |
| 6823 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6824 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6825 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6826 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 6827 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6828 | return false; |
| 6829 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6830 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6831 | final long identity = Binder.clearCallingIdentity(); |
| 6832 | try { |
| 6833 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 6834 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 6835 | // In the long run, we may instead need to check if there exists a connection service |
| 6836 | // which can support video calling. |
| 6837 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6838 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6839 | return imsManager.isVtEnabledByPlatform() |
| 6840 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 6841 | && imsManager.isVtEnabledByUser(); |
| 6842 | } finally { |
| 6843 | Binder.restoreCallingIdentity(identity); |
| 6844 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6845 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 6846 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6847 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6848 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 6849 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6850 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6851 | mApp, subId, callingPackage, callingFeatureId, |
| 6852 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6853 | return false; |
| 6854 | } |
| 6855 | |
| 6856 | final long identity = Binder.clearCallingIdentity(); |
| 6857 | try { |
| 6858 | CarrierConfigManager configManager = |
| 6859 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6860 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6861 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 6862 | } finally { |
| 6863 | Binder.restoreCallingIdentity(identity); |
| 6864 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6865 | } |
| 6866 | |
| 6867 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6868 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6869 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6870 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6871 | return false; |
| 6872 | } |
| 6873 | |
| 6874 | final long identity = Binder.clearCallingIdentity(); |
| 6875 | try { |
| 6876 | CarrierConfigManager configManager = |
| 6877 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6878 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6879 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 6880 | } finally { |
| 6881 | Binder.restoreCallingIdentity(identity); |
| 6882 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6883 | } |
| 6884 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6885 | @Override |
| 6886 | public boolean isTtyModeSupported() { |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6887 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 6888 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6889 | } |
| 6890 | |
| 6891 | @Override |
| 6892 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6893 | final long identity = Binder.clearCallingIdentity(); |
| 6894 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6895 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6896 | } finally { |
| 6897 | Binder.restoreCallingIdentity(identity); |
| 6898 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6899 | } |
| 6900 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6901 | /** |
| 6902 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 6903 | * support for the feature and device firmware support. |
| 6904 | * |
| 6905 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 6906 | */ |
| 6907 | @Override |
| 6908 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6909 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6910 | final Phone phone = getPhone(subscriptionId); |
| 6911 | if (phone == null) { |
| 6912 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 6913 | return false; |
| 6914 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6915 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6916 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6917 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 6918 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6919 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6920 | return isCarrierSupported && isDeviceSupported; |
| 6921 | } finally { |
| 6922 | Binder.restoreCallingIdentity(identity); |
| 6923 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 6924 | } |
| 6925 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6926 | /** |
Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 6927 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 6928 | * RTT setting, will return true if the device and carrier both support RTT. |
| 6929 | * 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] | 6930 | */ |
| 6931 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6932 | final long identity = Binder.clearCallingIdentity(); |
| 6933 | try { |
Hall Liu | 63767ec | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 6934 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 6935 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 6936 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 6937 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 6938 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 6939 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6940 | } finally { |
| 6941 | Binder.restoreCallingIdentity(identity); |
| 6942 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 6943 | } |
| 6944 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6945 | @Deprecated |
| 6946 | @Override |
| 6947 | public String getDeviceId(String callingPackage) { |
| 6948 | return getDeviceIdWithFeature(callingPackage, null); |
| 6949 | } |
| 6950 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6951 | /** |
| 6952 | * Returns the unique device ID of phone, for example, the IMEI for |
| 6953 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 6954 | * |
| 6955 | * <p>Requires Permission: |
| 6956 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 6957 | */ |
| 6958 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6959 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6960 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6961 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6962 | return null; |
| 6963 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6964 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 6965 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6966 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6967 | return null; |
| 6968 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6969 | |
| 6970 | final long identity = Binder.clearCallingIdentity(); |
| 6971 | try { |
| 6972 | return phone.getDeviceId(); |
| 6973 | } finally { |
| 6974 | Binder.restoreCallingIdentity(identity); |
| 6975 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6976 | } |
| 6977 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6978 | /** |
| 6979 | * {@hide} |
| 6980 | * Returns the IMS Registration Status on a particular subid |
| 6981 | * |
| 6982 | * @param subId |
| 6983 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6984 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6985 | Phone phone = getPhone(subId); |
| 6986 | if (phone != null) { |
| 6987 | return phone.isImsRegistered(); |
| 6988 | } else { |
| 6989 | return false; |
| 6990 | } |
| 6991 | } |
| 6992 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 6993 | @Override |
| 6994 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6995 | final long identity = Binder.clearCallingIdentity(); |
| 6996 | try { |
| 6997 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 6998 | } finally { |
| 6999 | Binder.restoreCallingIdentity(identity); |
| 7000 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7001 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 7002 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7003 | @Override |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7004 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7005 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7006 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7007 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7008 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7009 | } |
| 7010 | final long identity = Binder.clearCallingIdentity(); |
| 7011 | try { |
| 7012 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7013 | } finally { |
| 7014 | Binder.restoreCallingIdentity(identity); |
| 7015 | } |
| 7016 | } |
| 7017 | |
| 7018 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7019 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
duki.hong | fd96bde | 2020-07-22 17:32:19 +0900 | [diff] [blame] | 7020 | enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, " |
| 7021 | + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7022 | final long identity = Binder.clearCallingIdentity(); |
| 7023 | try { |
| 7024 | Phone phone = getPhone(subscriptionId); |
| 7025 | if (phone == null) { |
| 7026 | return null; |
| 7027 | } |
| 7028 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7029 | } finally { |
| 7030 | Binder.restoreCallingIdentity(identity); |
| 7031 | } |
| 7032 | } |
| 7033 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7034 | /** |
| 7035 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7036 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7037 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7038 | final long identity = Binder.clearCallingIdentity(); |
| 7039 | try { |
| 7040 | Phone phone = getPhone(subId); |
| 7041 | if (phone != null) { |
| 7042 | return phone.isWifiCallingEnabled(); |
| 7043 | } else { |
| 7044 | return false; |
| 7045 | } |
| 7046 | } finally { |
| 7047 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7048 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7049 | } |
| 7050 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7051 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7052 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7053 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7054 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7055 | final long identity = Binder.clearCallingIdentity(); |
| 7056 | try { |
| 7057 | Phone phone = getPhone(subId); |
| 7058 | if (phone != null) { |
| 7059 | return phone.isVideoEnabled(); |
| 7060 | } else { |
| 7061 | return false; |
| 7062 | } |
| 7063 | } finally { |
| 7064 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7065 | } |
| 7066 | } |
| 7067 | |
| 7068 | /** |
| 7069 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7070 | * defined in {@link ImsRegistrationImplBase}. |
| 7071 | */ |
| 7072 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7073 | final long identity = Binder.clearCallingIdentity(); |
| 7074 | try { |
| 7075 | Phone phone = getPhone(subId); |
| 7076 | if (phone != null) { |
| 7077 | return phone.getImsRegistrationTech(); |
| 7078 | } else { |
| 7079 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7080 | } |
| 7081 | } finally { |
| 7082 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7083 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7084 | } |
| 7085 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7086 | @Override |
| 7087 | public void factoryReset(int subId) { |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7088 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7089 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7090 | return; |
| 7091 | } |
| 7092 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7093 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7094 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7095 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7096 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7097 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7098 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7099 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7100 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7101 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7102 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 7103 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7104 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7105 | // There has been issues when Sms raw table somehow stores orphan |
| 7106 | // fragments. They lead to garbled message when new fragments come |
| 7107 | // in and combined with those stale ones. In case this happens again, |
| 7108 | // user can reset all network settings which will clean up this table. |
| 7109 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7110 | // Clean up IMS settings as well here. |
| 7111 | int slotId = getSlotIndex(subId); |
| 7112 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7113 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7114 | } |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7115 | |
| 7116 | // Erase modem config if erase modem on network setting is enabled. |
| 7117 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7118 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7119 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 7120 | sendEraseModemConfig(getDefaultPhone()); |
| 7121 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7122 | } finally { |
| 7123 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7124 | } |
| 7125 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7126 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7127 | private void cleanUpSmsRawTable(Context context) { |
| 7128 | ContentResolver resolver = context.getContentResolver(); |
| 7129 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7130 | resolver.delete(uri, null, null); |
| 7131 | } |
| 7132 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7133 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7134 | public String getSimLocaleForSubscriber(int subId) { |
| 7135 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7136 | final Phone phone = getPhone(subId); |
| 7137 | if (phone == null) { |
| 7138 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7139 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7140 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7141 | final long identity = Binder.clearCallingIdentity(); |
| 7142 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7143 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7144 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7145 | if (info == null) { |
| 7146 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7147 | return null; |
| 7148 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7149 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7150 | // preferences (EF-PL and EF-LI)... |
| 7151 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7152 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7153 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7154 | if (localeFromDefaultSim != null) { |
| 7155 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7156 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7157 | + localeFromDefaultSim); |
| 7158 | return localeFromDefaultSim.toLanguageTag(); |
| 7159 | } else { |
| 7160 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7161 | } |
| 7162 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7163 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7164 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7165 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7166 | // the SIM and carrier preferences does not include a country we add the country |
| 7167 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7168 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7169 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7170 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7171 | return mccLocale.toLanguageTag(); |
| 7172 | } |
| 7173 | |
| 7174 | if (DBG) log("No locale found - returning null"); |
| 7175 | return null; |
| 7176 | } finally { |
| 7177 | Binder.restoreCallingIdentity(identity); |
| 7178 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7179 | } |
| 7180 | |
| 7181 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7182 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7183 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7184 | } |
| 7185 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7186 | /** |
| 7187 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7188 | */ |
| 7189 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7190 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7191 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7192 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7193 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7194 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7195 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7196 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7197 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7198 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7199 | * representing the state of the modem. |
| 7200 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7201 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7202 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7203 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7204 | */ |
| 7205 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7206 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7207 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7208 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7209 | |
| 7210 | final long identity = Binder.clearCallingIdentity(); |
| 7211 | try { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 7212 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7213 | } finally { |
| 7214 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7215 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7216 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7217 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7218 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7219 | // less than total activity duration. |
| 7220 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7221 | if (info == null) { |
| 7222 | return false; |
| 7223 | } |
| 7224 | int activityDurationMs = |
| 7225 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 7226 | int totalTxTimeMs = 0; |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7227 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 7228 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 7229 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7230 | } |
| 7231 | return (info.isValid() |
| 7232 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7233 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7234 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7235 | && (totalTxTimeMs <= activityDurationMs)); |
| 7236 | } |
| 7237 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7238 | /** |
| 7239 | * {@hide} |
| 7240 | * Returns the service state information on specified subscription. |
| 7241 | */ |
| 7242 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7243 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7244 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7245 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7246 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7247 | return null; |
| 7248 | } |
| 7249 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7250 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7251 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7252 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7253 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7254 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7255 | .setCallingPid(Binder.getCallingPid()) |
| 7256 | .setCallingUid(Binder.getCallingUid()) |
| 7257 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7258 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7259 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7260 | .build()); |
| 7261 | |
| 7262 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7263 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7264 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7265 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7266 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7267 | .setCallingPid(Binder.getCallingPid()) |
| 7268 | .setCallingUid(Binder.getCallingUid()) |
| 7269 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7270 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7271 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7272 | .build()); |
| 7273 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7274 | boolean hasFinePermission = |
| 7275 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7276 | boolean hasCoarsePermission = |
| 7277 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7278 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7279 | final long identity = Binder.clearCallingIdentity(); |
| 7280 | try { |
| 7281 | final Phone phone = getPhone(subId); |
| 7282 | if (phone == null) { |
| 7283 | return null; |
| 7284 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7285 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7286 | ServiceState ss = phone.getServiceState(); |
| 7287 | |
| 7288 | // Scrub out the location info in ServiceState depending on what level of access |
| 7289 | // the caller has. |
| 7290 | if (hasFinePermission) return ss; |
Malcolm Chen | db33797 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7291 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7292 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7293 | } finally { |
| 7294 | Binder.restoreCallingIdentity(identity); |
| 7295 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7296 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7297 | |
| 7298 | /** |
| 7299 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7300 | * |
| 7301 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7302 | * voicemail ringtone. |
| 7303 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7304 | * PhoneAccount. |
| 7305 | */ |
| 7306 | @Override |
| 7307 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7308 | final long identity = Binder.clearCallingIdentity(); |
| 7309 | try { |
| 7310 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7311 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7312 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7313 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7314 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7315 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7316 | } finally { |
| 7317 | Binder.restoreCallingIdentity(identity); |
| 7318 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7319 | } |
| 7320 | |
| 7321 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7322 | * Sets the per-account voicemail ringtone. |
| 7323 | * |
| 7324 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7325 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7326 | * |
| 7327 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7328 | * voicemail ringtone. |
| 7329 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7330 | * PhoneAccount. |
| 7331 | */ |
| 7332 | @Override |
| 7333 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7334 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7335 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7336 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7337 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7338 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7339 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7340 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7341 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7342 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7343 | |
| 7344 | final long identity = Binder.clearCallingIdentity(); |
| 7345 | try { |
| 7346 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7347 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7348 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7349 | } |
| 7350 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7351 | } finally { |
| 7352 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7353 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7354 | } |
| 7355 | |
| 7356 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7357 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7358 | * |
| 7359 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7360 | * voicemail vibration setting. |
| 7361 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7362 | */ |
| 7363 | @Override |
| 7364 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7365 | final long identity = Binder.clearCallingIdentity(); |
| 7366 | try { |
| 7367 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7368 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7369 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7370 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7371 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7372 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7373 | } finally { |
| 7374 | Binder.restoreCallingIdentity(identity); |
| 7375 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7376 | } |
| 7377 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7378 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7379 | * Sets the per-account voicemail vibration. |
| 7380 | * |
| 7381 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7382 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7383 | * |
| 7384 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7385 | * voicemail vibration setting. |
| 7386 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7387 | * specific PhoneAccount. |
| 7388 | */ |
| 7389 | @Override |
| 7390 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7391 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7392 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7393 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7394 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7395 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7396 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7397 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7398 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7399 | } |
| 7400 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7401 | final long identity = Binder.clearCallingIdentity(); |
| 7402 | try { |
| 7403 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7404 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7405 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7406 | } |
| 7407 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7408 | } finally { |
| 7409 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7410 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7411 | } |
| 7412 | |
| 7413 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7414 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 7415 | * |
| 7416 | * @throws SecurityException if the caller does not have the required permission |
| 7417 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7418 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7419 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7420 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7421 | } |
| 7422 | |
| 7423 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7424 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 7425 | * permission. |
| 7426 | * |
| 7427 | * @throws SecurityException if the caller does not have the required permission |
| 7428 | */ |
| 7429 | private void enforceSendSmsPermission() { |
| 7430 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 7431 | } |
| 7432 | |
| 7433 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7434 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7435 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7436 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7437 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7438 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7439 | final long identity = Binder.clearCallingIdentity(); |
| 7440 | try { |
| 7441 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7442 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7443 | if (componentName == null) { |
| 7444 | throw new SecurityException( |
| 7445 | "Caller not current active visual voicemail package[null]"); |
| 7446 | } |
| 7447 | String vvmPackage = componentName.getPackageName(); |
| 7448 | if (!callingPackage.equals(vvmPackage)) { |
| 7449 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 7450 | + vvmPackage + "]"); |
| 7451 | } |
| 7452 | } finally { |
| 7453 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7454 | } |
| 7455 | } |
| 7456 | |
| 7457 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7458 | * Return the application ID for the app type. |
| 7459 | * |
| 7460 | * @param subId the subscription ID that this request applies to. |
| 7461 | * @param appType the uicc app type. |
| 7462 | * @return Application ID for specificied app type, or null if no uicc. |
| 7463 | */ |
| 7464 | @Override |
| 7465 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7466 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7467 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7468 | |
| 7469 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7470 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7471 | if (phone == null) { |
| 7472 | return null; |
| 7473 | } |
| 7474 | String aid = null; |
| 7475 | try { |
| 7476 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 7477 | .getApplicationByType(appType).getAid(); |
| 7478 | } catch (Exception e) { |
| 7479 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 7480 | } |
| 7481 | return aid; |
| 7482 | } finally { |
| 7483 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7484 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7485 | } |
| 7486 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7487 | /** |
| 7488 | * Return the Electronic Serial Number. |
| 7489 | * |
| 7490 | * @param subId the subscription ID that this request applies to. |
| 7491 | * @return ESN or null if error. |
| 7492 | */ |
| 7493 | @Override |
| 7494 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7495 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7496 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7497 | |
| 7498 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7499 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7500 | if (phone == null) { |
| 7501 | return null; |
| 7502 | } |
| 7503 | String esn = null; |
| 7504 | try { |
| 7505 | esn = phone.getEsn(); |
| 7506 | } catch (Exception e) { |
| 7507 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 7508 | } |
| 7509 | return esn; |
| 7510 | } finally { |
| 7511 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7512 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7513 | } |
| 7514 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7515 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7516 | * Return the Preferred Roaming List Version. |
| 7517 | * |
| 7518 | * @param subId the subscription ID that this request applies to. |
| 7519 | * @return PRLVersion or null if error. |
| 7520 | */ |
| 7521 | @Override |
| 7522 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7523 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7524 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7525 | |
| 7526 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7527 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7528 | if (phone == null) { |
| 7529 | return null; |
| 7530 | } |
| 7531 | String cdmaPrlVersion = null; |
| 7532 | try { |
| 7533 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7534 | } catch (Exception e) { |
| 7535 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7536 | } |
| 7537 | return cdmaPrlVersion; |
| 7538 | } finally { |
| 7539 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7540 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7541 | } |
| 7542 | |
| 7543 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7544 | * Get snapshot of Telephony histograms |
| 7545 | * @return List of Telephony histograms |
| 7546 | * @hide |
| 7547 | */ |
| 7548 | @Override |
| 7549 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7550 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7551 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7552 | |
| 7553 | final long identity = Binder.clearCallingIdentity(); |
| 7554 | try { |
| 7555 | return RIL.getTelephonyRILTimingHistograms(); |
| 7556 | } finally { |
| 7557 | Binder.restoreCallingIdentity(identity); |
| 7558 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7559 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7560 | |
| 7561 | /** |
| 7562 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7563 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7564 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7565 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7566 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7567 | * @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] | 7568 | */ |
| 7569 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7570 | @TelephonyManager.SetCarrierRestrictionResult |
| 7571 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7572 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7573 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7574 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7575 | if (carrierRestrictionRules == null) { |
| 7576 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7577 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7578 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7579 | final long identity = Binder.clearCallingIdentity(); |
| 7580 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7581 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7582 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7583 | } finally { |
| 7584 | Binder.restoreCallingIdentity(identity); |
| 7585 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7586 | } |
| 7587 | |
| 7588 | /** |
| 7589 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7590 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7591 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7592 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7593 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7594 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7595 | */ |
| 7596 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7597 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7598 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7599 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7600 | |
| 7601 | final long identity = Binder.clearCallingIdentity(); |
| 7602 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7603 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7604 | if (response instanceof CarrierRestrictionRules) { |
| 7605 | return (CarrierRestrictionRules) response; |
| 7606 | } |
| 7607 | // Response is an Exception of some kind, |
| 7608 | // which is signalled to the user as a NULL retval |
| 7609 | return null; |
| 7610 | } catch (Exception e) { |
| 7611 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7612 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7613 | } finally { |
| 7614 | Binder.restoreCallingIdentity(identity); |
| 7615 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7616 | } |
| 7617 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7618 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7619 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7620 | * @param subId the subscription ID that this action applies to. |
| 7621 | * @param enabled control enable or disable radio. |
| 7622 | * {@hide} |
| 7623 | */ |
| 7624 | @Override |
| 7625 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7626 | enforceModifyPermission(); |
| 7627 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7628 | |
| 7629 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7630 | if (phone == null) { |
| 7631 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7632 | return; |
| 7633 | } |
| 7634 | try { |
| 7635 | phone.carrierActionSetRadioEnabled(enabled); |
| 7636 | } catch (Exception e) { |
| 7637 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7638 | } finally { |
| 7639 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7640 | } |
| 7641 | } |
| 7642 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7643 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7644 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7645 | * network status based on which carrier apps could apply actions accordingly, |
| 7646 | * enable/disable default url handler for example. |
| 7647 | * |
| 7648 | * @param subId the subscription ID that this action applies to. |
| 7649 | * @param report control start/stop reporting the default network status. |
| 7650 | * {@hide} |
| 7651 | */ |
| 7652 | @Override |
| 7653 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7654 | enforceModifyPermission(); |
| 7655 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7656 | |
| 7657 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7658 | if (phone == null) { |
| 7659 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7660 | return; |
| 7661 | } |
| 7662 | try { |
| 7663 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7664 | } catch (Exception e) { |
| 7665 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7666 | } finally { |
| 7667 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7668 | } |
| 7669 | } |
| 7670 | |
| 7671 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7672 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7673 | * @param subId the subscription ID that this action applies to. |
| 7674 | * {@hide} |
| 7675 | */ |
| 7676 | @Override |
| 7677 | public void carrierActionResetAll(int subId) { |
| 7678 | enforceModifyPermission(); |
| 7679 | final Phone phone = getPhone(subId); |
| 7680 | if (phone == null) { |
| 7681 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7682 | return; |
| 7683 | } |
| 7684 | try { |
| 7685 | phone.carrierActionResetAll(); |
| 7686 | } catch (Exception e) { |
| 7687 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7688 | } |
| 7689 | } |
| 7690 | |
| 7691 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7692 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7693 | * bug report is being generated. |
| 7694 | */ |
| 7695 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7696 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7697 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7698 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7699 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7700 | + Binder.getCallingPid() |
| 7701 | + ", uid=" + Binder.getCallingUid() |
| 7702 | + "without permission " |
| 7703 | + android.Manifest.permission.DUMP); |
| 7704 | return; |
| 7705 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7706 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7707 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7708 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7709 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 7710 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 7711 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 7712 | @NonNull String[] args) { |
| 7713 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 7714 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 7715 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7716 | } |
| 7717 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7718 | /** |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7719 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7720 | * @param subId Subscription index |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7721 | * @param reason the reason the data enable change is taking place |
| 7722 | * @param enabled True if enabling the data, otherwise disabling. |
| 7723 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7724 | */ |
| 7725 | @Override |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7726 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7727 | boolean enabled) { |
| 7728 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 7729 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7730 | try { |
| 7731 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7732 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7733 | } catch (SecurityException se) { |
| 7734 | enforceModifyPermission(); |
| 7735 | } |
| 7736 | } else { |
| 7737 | enforceModifyPermission(); |
| 7738 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7739 | |
| 7740 | final long identity = Binder.clearCallingIdentity(); |
| 7741 | try { |
| 7742 | Phone phone = getPhone(subId); |
| 7743 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7744 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7745 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7746 | } else { |
| 7747 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 7748 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7749 | } |
| 7750 | } finally { |
| 7751 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7752 | } |
| 7753 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7754 | |
| 7755 | /** |
| 7756 | * Get Client request stats |
| 7757 | * @return List of Client Request Stats |
| 7758 | * @hide |
| 7759 | */ |
| 7760 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7761 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7762 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7763 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7764 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7765 | return null; |
| 7766 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7767 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7768 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7769 | final long identity = Binder.clearCallingIdentity(); |
| 7770 | try { |
| 7771 | if (phone != null) { |
| 7772 | return phone.getClientRequestStats(); |
| 7773 | } |
| 7774 | |
| 7775 | return null; |
| 7776 | } finally { |
| 7777 | Binder.restoreCallingIdentity(identity); |
| 7778 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7779 | } |
| 7780 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7781 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7782 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7783 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7784 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7785 | |
| 7786 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7787 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7788 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7789 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7790 | * @param state State of SIM (power down, power up, pass through) |
| 7791 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7792 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7793 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7794 | * |
| 7795 | **/ |
| 7796 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7797 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7798 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7799 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7800 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7801 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7802 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7803 | final long identity = Binder.clearCallingIdentity(); |
| 7804 | try { |
| 7805 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7806 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7807 | } |
| 7808 | } finally { |
| 7809 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7810 | } |
| 7811 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7812 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7813 | private boolean isUssdApiAllowed(int subId) { |
| 7814 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7815 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7816 | if (configManager == null) { |
| 7817 | return false; |
| 7818 | } |
| 7819 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 7820 | if (pb == null) { |
| 7821 | return false; |
| 7822 | } |
| 7823 | return pb.getBoolean( |
| 7824 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 7825 | } |
| 7826 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7827 | /** |
| 7828 | * Check if phone is in emergency callback mode |
| 7829 | * @return true if phone is in emergency callback mode |
| 7830 | * @param subId sub id |
| 7831 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 7832 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7833 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7834 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7835 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7836 | |
| 7837 | final long identity = Binder.clearCallingIdentity(); |
| 7838 | try { |
| 7839 | if (phone != null) { |
| 7840 | return phone.isInEcm(); |
| 7841 | } else { |
| 7842 | return false; |
| 7843 | } |
| 7844 | } finally { |
| 7845 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7846 | } |
| 7847 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7848 | |
| 7849 | /** |
| 7850 | * Get the current signal strength information for the given subscription. |
| 7851 | * Because this information is not updated when the device is in a low power state |
| 7852 | * it should not be relied-upon to be current. |
| 7853 | * @param subId Subscription index |
| 7854 | * @return the most recent cached signal strength info from the modem |
| 7855 | */ |
| 7856 | @Override |
| 7857 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7858 | final long identity = Binder.clearCallingIdentity(); |
| 7859 | try { |
| 7860 | Phone p = getPhone(subId); |
| 7861 | if (p == null) { |
| 7862 | return null; |
| 7863 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7864 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7865 | return p.getSignalStrength(); |
| 7866 | } finally { |
| 7867 | Binder.restoreCallingIdentity(identity); |
| 7868 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7869 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7870 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7871 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7872 | * Get the current modem radio state for the given slot. |
| 7873 | * @param slotIndex slot index. |
| 7874 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7875 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7876 | * @return the current radio power state from the modem |
| 7877 | */ |
| 7878 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7879 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7880 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7881 | if (phone != null) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7882 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 7883 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7884 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7885 | } |
| 7886 | |
| 7887 | final long identity = Binder.clearCallingIdentity(); |
| 7888 | try { |
| 7889 | return phone.getRadioPowerState(); |
| 7890 | } finally { |
| 7891 | Binder.restoreCallingIdentity(identity); |
| 7892 | } |
| 7893 | } |
| 7894 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7895 | } |
| 7896 | |
| 7897 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7898 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 7899 | * |
| 7900 | * <p>Requires one of the following permissions: |
| 7901 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 7902 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 7903 | * privileges. |
| 7904 | * |
| 7905 | * @param subId subscription id |
| 7906 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 7907 | * {@code false}. |
| 7908 | */ |
| 7909 | @Override |
| 7910 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 11263f3 | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 7911 | try { |
| 7912 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7913 | null); |
| 7914 | } catch (Exception e) { |
| 7915 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 7916 | mApp, subId, "isDataRoamingEnabled"); |
| 7917 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7918 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7919 | boolean isEnabled = false; |
| 7920 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7921 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7922 | Phone phone = getPhone(subId); |
| 7923 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7924 | } finally { |
| 7925 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7926 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7927 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7928 | } |
| 7929 | |
| 7930 | |
| 7931 | /** |
| 7932 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 7933 | * |
| 7934 | * <p> Requires permission: |
| 7935 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 7936 | * privileges. |
| 7937 | * |
| 7938 | * @param subId subscription id |
| 7939 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 7940 | */ |
| 7941 | @Override |
| 7942 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7943 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7944 | mApp, subId, "setDataRoamingEnabled"); |
| 7945 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7946 | final long identity = Binder.clearCallingIdentity(); |
| 7947 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7948 | Phone phone = getPhone(subId); |
| 7949 | if (phone != null) { |
| 7950 | phone.setDataRoamingEnabled(isEnabled); |
| 7951 | } |
| 7952 | } finally { |
| 7953 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7954 | } |
| 7955 | } |
| 7956 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7957 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7958 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 7959 | TelephonyPermissions |
| 7960 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7961 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 7962 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7963 | boolean isAllowed = true; |
| 7964 | final long identity = Binder.clearCallingIdentity(); |
| 7965 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7966 | Phone phone = getPhone(subId); |
| 7967 | if (phone != null) { |
| 7968 | isAllowed = phone.isCspPlmnEnabled(); |
| 7969 | } |
| 7970 | } finally { |
| 7971 | Binder.restoreCallingIdentity(identity); |
| 7972 | } |
| 7973 | return isAllowed; |
| 7974 | } |
| 7975 | |
| 7976 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7977 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | cfdfe3a | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 7978 | // Verify that tha callingPackage belongs to the calling UID |
| 7979 | mApp.getSystemService(AppOpsManager.class) |
| 7980 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 7981 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7982 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7983 | try { |
| 7984 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7985 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7986 | } catch (SecurityException e) { |
| 7987 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 7988 | // has carrier privileges on an active UICC |
| 7989 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 7990 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7991 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 7992 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7993 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 7994 | |
| 7995 | final long identity = Binder.clearCallingIdentity(); |
| 7996 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7997 | UiccController uiccController = UiccController.getInstance(); |
| 7998 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7999 | if (hasReadPermission) { |
| 8000 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8001 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8002 | |
| 8003 | // Remove private info if the caller doesn't have access |
| 8004 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8005 | for (UiccCardInfo cardInfo : cardInfos) { |
| 8006 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8007 | // is available |
| 8008 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 8009 | if (card == null || card.getUiccProfile() == null) { |
| 8010 | // assume no access if the card or profile is unavailable |
| 8011 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8012 | continue; |
| 8013 | } |
| 8014 | UiccProfile profile = card.getUiccProfile(); |
| 8015 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8016 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8017 | filteredInfos.add(cardInfo); |
| 8018 | } else { |
| 8019 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8020 | } |
| 8021 | } |
| 8022 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8023 | } finally { |
| 8024 | Binder.restoreCallingIdentity(identity); |
| 8025 | } |
| 8026 | } |
| 8027 | |
| 8028 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8029 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8030 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8031 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8032 | final long identity = Binder.clearCallingIdentity(); |
| 8033 | try { |
| 8034 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8035 | if (slots == null) { |
| 8036 | Rlog.i(LOG_TAG, "slots is null."); |
| 8037 | return null; |
| 8038 | } |
| 8039 | |
| 8040 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8041 | for (int i = 0; i < slots.length; i++) { |
| 8042 | UiccSlot slot = slots[i]; |
| 8043 | if (slot == null) { |
| 8044 | continue; |
| 8045 | } |
| 8046 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8047 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8048 | UiccCard card = slot.getUiccCard(); |
| 8049 | if (card != null) { |
| 8050 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8051 | } else { |
Jordan Liu | d96b529 | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8052 | cardId = slot.getEid(); |
| 8053 | if (TextUtils.isEmpty(cardId)) { |
| 8054 | cardId = slot.getIccId(); |
| 8055 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8056 | } |
| 8057 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8058 | if (cardId != null) { |
| 8059 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8060 | // if cardId is an EID, it's all digits so this is fine |
| 8061 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8062 | } |
| 8063 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8064 | int cardState = 0; |
| 8065 | switch (slot.getCardState()) { |
| 8066 | case CARDSTATE_ABSENT: |
| 8067 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8068 | break; |
| 8069 | case CARDSTATE_PRESENT: |
| 8070 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8071 | break; |
| 8072 | case CARDSTATE_ERROR: |
| 8073 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8074 | break; |
| 8075 | case CARDSTATE_RESTRICTED: |
| 8076 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8077 | break; |
| 8078 | default: |
| 8079 | break; |
| 8080 | |
| 8081 | } |
| 8082 | |
| 8083 | infos[i] = new UiccSlotInfo( |
| 8084 | slot.isActive(), |
| 8085 | slot.isEuicc(), |
| 8086 | cardId, |
| 8087 | cardState, |
| 8088 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8089 | slot.isExtendedApduSupported(), |
| 8090 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8091 | } |
| 8092 | return infos; |
| 8093 | } finally { |
| 8094 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8095 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8096 | } |
| 8097 | |
| 8098 | @Override |
| 8099 | public boolean switchSlots(int[] physicalSlots) { |
| 8100 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8101 | |
| 8102 | final long identity = Binder.clearCallingIdentity(); |
| 8103 | try { |
| 8104 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8105 | } finally { |
| 8106 | Binder.restoreCallingIdentity(identity); |
| 8107 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8108 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8109 | |
| 8110 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8111 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8112 | final long identity = Binder.clearCallingIdentity(); |
| 8113 | try { |
| 8114 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8115 | } finally { |
| 8116 | Binder.restoreCallingIdentity(identity); |
| 8117 | } |
| 8118 | } |
| 8119 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8120 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8121 | * A test API to reload the UICC profile. |
| 8122 | * |
| 8123 | * <p>Requires that the calling app has permission |
| 8124 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8125 | * @hide |
| 8126 | */ |
| 8127 | @Override |
| 8128 | public void refreshUiccProfile(int subId) { |
| 8129 | enforceModifyPermission(); |
| 8130 | |
| 8131 | final long identity = Binder.clearCallingIdentity(); |
| 8132 | try { |
| 8133 | Phone phone = getPhone(subId); |
| 8134 | if (phone == null) { |
| 8135 | return; |
| 8136 | } |
| 8137 | UiccCard uiccCard = phone.getUiccCard(); |
| 8138 | if (uiccCard == null) { |
| 8139 | return; |
| 8140 | } |
| 8141 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8142 | if (uiccProfile == null) { |
| 8143 | return; |
| 8144 | } |
| 8145 | uiccProfile.refresh(); |
| 8146 | } finally { |
| 8147 | Binder.restoreCallingIdentity(identity); |
| 8148 | } |
| 8149 | } |
| 8150 | |
| 8151 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8152 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8153 | */ |
| 8154 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8155 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8156 | } |
| 8157 | |
| 8158 | /** |
| 8159 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8160 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8161 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8162 | */ |
| 8163 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8164 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8165 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | faaa63d | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8166 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8167 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8168 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8169 | return isDataRoamingEnabled; |
| 8170 | } |
| 8171 | |
| 8172 | /** |
| 8173 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8174 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8175 | */ |
| 8176 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8177 | List<Integer> list = TelephonyProperties.default_network(); |
| 8178 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8179 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8180 | return list.get(phoneId); |
| 8181 | } |
| 8182 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8183 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8184 | |
| 8185 | @Override |
| 8186 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8187 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8188 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8189 | |
| 8190 | final long identity = Binder.clearCallingIdentity(); |
| 8191 | try { |
| 8192 | final Phone phone = getPhone(subId); |
| 8193 | if (phone == null) { |
| 8194 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8195 | return; |
| 8196 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8197 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8198 | carrierPrivilegeRules, apn); |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8199 | if (carrierPrivilegeRules == null) { |
| 8200 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8201 | } else { |
| 8202 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8203 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8204 | } finally { |
| 8205 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8206 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8207 | } |
| 8208 | |
| 8209 | @Override |
| 8210 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8211 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8212 | |
| 8213 | final long identity = Binder.clearCallingIdentity(); |
| 8214 | try { |
| 8215 | final Phone phone = getPhone(subId); |
| 8216 | if (phone == null) { |
| 8217 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 8218 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 8219 | } |
| 8220 | return phone.getCarrierIdListVersion(); |
| 8221 | } finally { |
| 8222 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8223 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8224 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8225 | |
| 8226 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8227 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 8228 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8229 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8230 | mApp, subId, callingPackage, callingFeatureId, |
| 8231 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8232 | return -1; |
| 8233 | } |
| 8234 | |
| 8235 | final long identity = Binder.clearCallingIdentity(); |
| 8236 | try { |
| 8237 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 8238 | } finally { |
| 8239 | Binder.restoreCallingIdentity(identity); |
| 8240 | } |
| 8241 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8242 | |
| 8243 | @Override |
| 8244 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 0723870 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 8245 | TelephonyPermissions |
| 8246 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8247 | mApp, subId, "getCdmaRoamingMode"); |
| 8248 | |
| 8249 | final long identity = Binder.clearCallingIdentity(); |
| 8250 | try { |
| 8251 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 8252 | } finally { |
| 8253 | Binder.restoreCallingIdentity(identity); |
| 8254 | } |
| 8255 | } |
| 8256 | |
| 8257 | @Override |
| 8258 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 8259 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8260 | mApp, subId, "setCdmaRoamingMode"); |
| 8261 | |
| 8262 | final long identity = Binder.clearCallingIdentity(); |
| 8263 | try { |
| 8264 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 8265 | } finally { |
| 8266 | Binder.restoreCallingIdentity(identity); |
| 8267 | } |
| 8268 | } |
| 8269 | |
| 8270 | @Override |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8271 | public int getCdmaSubscriptionMode(int subId) { |
| 8272 | TelephonyPermissions |
| 8273 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8274 | mApp, subId, "getCdmaSubscriptionMode"); |
| 8275 | |
| 8276 | final long identity = Binder.clearCallingIdentity(); |
| 8277 | try { |
| 8278 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 8279 | } finally { |
| 8280 | Binder.restoreCallingIdentity(identity); |
| 8281 | } |
| 8282 | } |
| 8283 | |
| 8284 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8285 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 8286 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8287 | mApp, subId, "setCdmaSubscriptionMode"); |
| 8288 | |
| 8289 | final long identity = Binder.clearCallingIdentity(); |
| 8290 | try { |
| 8291 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 8292 | } finally { |
| 8293 | Binder.restoreCallingIdentity(identity); |
| 8294 | } |
| 8295 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8296 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8297 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8298 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8299 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8300 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8301 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 8302 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8303 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8304 | } |
| 8305 | final long identity = Binder.clearCallingIdentity(); |
| 8306 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8307 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 8308 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8309 | if (phone.getEmergencyNumberTracker() != null |
| 8310 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 8311 | emergencyNumberListInternal.put( |
| 8312 | phone.getSubId(), |
| 8313 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 8314 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8315 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8316 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8317 | } finally { |
| 8318 | Binder.restoreCallingIdentity(identity); |
| 8319 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8320 | } |
| 8321 | |
| 8322 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8323 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8324 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8325 | if (!exactMatch) { |
| 8326 | TelephonyPermissions |
| 8327 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8328 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8329 | } |
| 8330 | final long identity = Binder.clearCallingIdentity(); |
| 8331 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8332 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8333 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8334 | && phone.getEmergencyNumberTracker() |
| 8335 | .isEmergencyNumber(number, exactMatch)) { |
| 8336 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8337 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8338 | } |
| 8339 | return false; |
| 8340 | } finally { |
| 8341 | Binder.restoreCallingIdentity(identity); |
| 8342 | } |
| 8343 | } |
| 8344 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8345 | /** |
| 8346 | * Update emergency number list for test mode. |
| 8347 | */ |
| 8348 | @Override |
| 8349 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 8350 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8351 | "updateEmergencyNumberListTestMode"); |
| 8352 | |
| 8353 | final long identity = Binder.clearCallingIdentity(); |
| 8354 | try { |
| 8355 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8356 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8357 | if (tracker != null) { |
| 8358 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 8359 | } |
| 8360 | } |
| 8361 | } finally { |
| 8362 | Binder.restoreCallingIdentity(identity); |
| 8363 | } |
| 8364 | } |
| 8365 | |
| 8366 | /** |
| 8367 | * Get the full emergency number list for test mode. |
| 8368 | */ |
| 8369 | @Override |
| 8370 | public List<String> getEmergencyNumberListTestMode() { |
| 8371 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8372 | "getEmergencyNumberListTestMode"); |
| 8373 | |
| 8374 | final long identity = Binder.clearCallingIdentity(); |
| 8375 | try { |
| 8376 | Set<String> emergencyNumbers = new HashSet<>(); |
| 8377 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8378 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8379 | if (tracker != null) { |
| 8380 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 8381 | emergencyNumbers.add(num.getNumber()); |
| 8382 | } |
| 8383 | } |
| 8384 | } |
| 8385 | return new ArrayList<>(emergencyNumbers); |
| 8386 | } finally { |
| 8387 | Binder.restoreCallingIdentity(identity); |
| 8388 | } |
| 8389 | } |
| 8390 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8391 | @Override |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8392 | public int getEmergencyNumberDbVersion(int subId) { |
| 8393 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 8394 | |
| 8395 | final long identity = Binder.clearCallingIdentity(); |
| 8396 | try { |
| 8397 | final Phone phone = getPhone(subId); |
| 8398 | if (phone == null) { |
| 8399 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 8400 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 8401 | } |
| 8402 | return phone.getEmergencyNumberDbVersion(); |
| 8403 | } finally { |
| 8404 | Binder.restoreCallingIdentity(identity); |
| 8405 | } |
| 8406 | } |
| 8407 | |
| 8408 | @Override |
| 8409 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 8410 | enforceModifyPermission(); |
| 8411 | |
| 8412 | final long identity = Binder.clearCallingIdentity(); |
| 8413 | try { |
| 8414 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8415 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8416 | if (tracker != null) { |
| 8417 | tracker.updateOtaEmergencyNumberDatabase(); |
| 8418 | } |
| 8419 | } |
| 8420 | } finally { |
| 8421 | Binder.restoreCallingIdentity(identity); |
| 8422 | } |
| 8423 | } |
| 8424 | |
| 8425 | @Override |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8426 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8427 | enforceActiveEmergencySessionPermission(); |
| 8428 | |
| 8429 | final long identity = Binder.clearCallingIdentity(); |
| 8430 | try { |
| 8431 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8432 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8433 | if (tracker != null) { |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8434 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 8435 | } |
| 8436 | } |
| 8437 | } finally { |
| 8438 | Binder.restoreCallingIdentity(identity); |
| 8439 | } |
| 8440 | } |
| 8441 | |
| 8442 | @Override |
| 8443 | public void resetOtaEmergencyNumberDbFilePath() { |
| 8444 | enforceActiveEmergencySessionPermission(); |
| 8445 | |
| 8446 | final long identity = Binder.clearCallingIdentity(); |
| 8447 | try { |
| 8448 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8449 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8450 | if (tracker != null) { |
| 8451 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8452 | } |
| 8453 | } |
| 8454 | } finally { |
| 8455 | Binder.restoreCallingIdentity(identity); |
| 8456 | } |
| 8457 | } |
| 8458 | |
| 8459 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8460 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 8461 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 8462 | Phone phone = getPhone(subId); |
| 8463 | if (phone == null) { |
| 8464 | return null; |
| 8465 | } |
| 8466 | final long identity = Binder.clearCallingIdentity(); |
| 8467 | try { |
| 8468 | UiccProfile profile = UiccController.getInstance() |
| 8469 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 8470 | if (profile != null) { |
| 8471 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 8472 | } |
| 8473 | } finally { |
| 8474 | Binder.restoreCallingIdentity(identity); |
| 8475 | } |
| 8476 | return null; |
| 8477 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 8478 | |
| 8479 | /** |
| 8480 | * Enable or disable a modem stack. |
| 8481 | */ |
| 8482 | @Override |
| 8483 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 8484 | enforceModifyPermission(); |
| 8485 | |
| 8486 | final long identity = Binder.clearCallingIdentity(); |
| 8487 | try { |
| 8488 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8489 | if (phone == null) { |
| 8490 | return false; |
| 8491 | } else { |
| 8492 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 8493 | } |
| 8494 | } finally { |
| 8495 | Binder.restoreCallingIdentity(identity); |
| 8496 | } |
| 8497 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8498 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8499 | /** |
| 8500 | * Whether a modem stack is enabled or not. |
| 8501 | */ |
| 8502 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8503 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 8504 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8505 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8506 | if (phone == null) return false; |
| 8507 | |
| 8508 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8509 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 8510 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8511 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8512 | } |
| 8513 | |
| 8514 | final long identity = Binder.clearCallingIdentity(); |
| 8515 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8516 | try { |
| 8517 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 8518 | } catch (NoSuchElementException ex) { |
| 8519 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 8520 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8521 | } finally { |
| 8522 | Binder.restoreCallingIdentity(identity); |
| 8523 | } |
| 8524 | } |
| 8525 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8526 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8527 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8528 | enforceModifyPermission(); |
| 8529 | |
| 8530 | final long identity = Binder.clearCallingIdentity(); |
| 8531 | try { |
| 8532 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8533 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8534 | .commit(); |
| 8535 | } finally { |
| 8536 | Binder.restoreCallingIdentity(identity); |
| 8537 | } |
| 8538 | } |
| 8539 | |
| 8540 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8541 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8542 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8543 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8544 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8545 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8546 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8547 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8548 | |
| 8549 | final long identity = Binder.clearCallingIdentity(); |
| 8550 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8551 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8552 | } finally { |
| 8553 | Binder.restoreCallingIdentity(identity); |
| 8554 | } |
| 8555 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8556 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8557 | @TelephonyManager.IsMultiSimSupportedResult |
| 8558 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8559 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8560 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8561 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8562 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8563 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8564 | } |
| 8565 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8566 | // supported by the modem, indicate that it is restricted. |
| 8567 | PhoneCapability staticCapability = |
| 8568 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8569 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8570 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8571 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8572 | } |
Sarah Chin | 09f38ee | 2020-02-25 00:13:10 +0000 | [diff] [blame] | 8573 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8574 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8575 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8576 | } |
| 8577 | // Check if support of multiple SIMs is restricted by carrier |
| 8578 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8579 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8580 | } |
| 8581 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8582 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8583 | } |
| 8584 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8585 | /** |
| 8586 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8587 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8588 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8589 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8590 | * @param numOfSims number of active sims we want to switch to |
| 8591 | */ |
| 8592 | @Override |
| 8593 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8594 | if (numOfSims == 1) { |
| 8595 | enforceModifyPermission(); |
| 8596 | } else { |
| 8597 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8598 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8599 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8600 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8601 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8602 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8603 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8604 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8605 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8606 | return; |
| 8607 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8608 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8609 | } finally { |
| 8610 | Binder.restoreCallingIdentity(identity); |
| 8611 | } |
| 8612 | } |
| 8613 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8614 | @Override |
| 8615 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8616 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8617 | Phone phone = getPhone(subId); |
| 8618 | if (phone == null) { |
| 8619 | return false; |
| 8620 | } |
| 8621 | final long identity = Binder.clearCallingIdentity(); |
| 8622 | try { |
| 8623 | UiccCard uiccCard = phone.getUiccCard(); |
| 8624 | if (uiccCard == null) { |
| 8625 | return false; |
| 8626 | } |
| 8627 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8628 | if (uiccProfile == null) { |
| 8629 | return false; |
| 8630 | } |
| 8631 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8632 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8633 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8634 | } |
| 8635 | return false; |
| 8636 | } finally { |
| 8637 | Binder.restoreCallingIdentity(identity); |
| 8638 | } |
| 8639 | } |
| 8640 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8641 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8642 | * Get whether making changes to modem configurations will trigger reboot. |
| 8643 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8644 | */ |
| 8645 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8646 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8647 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8648 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8649 | mApp, subId, callingPackage, callingFeatureId, |
| 8650 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8651 | return false; |
| 8652 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8653 | final long identity = Binder.clearCallingIdentity(); |
| 8654 | try { |
| 8655 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8656 | } finally { |
| 8657 | Binder.restoreCallingIdentity(identity); |
| 8658 | } |
| 8659 | } |
| 8660 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8661 | private void updateModemStateMetrics() { |
| 8662 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8663 | // TODO: check the state for each modem if the api is ready. |
| 8664 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8665 | } |
| 8666 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8667 | @Override |
| 8668 | public int[] getSlotsMapping() { |
| 8669 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8670 | |
| 8671 | final long identity = Binder.clearCallingIdentity(); |
| 8672 | try { |
| 8673 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8674 | // All logical slots should have a mapping to a physical slot. |
| 8675 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8676 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8677 | for (int i = 0; i < slotInfos.length; i++) { |
| 8678 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8679 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8680 | } |
| 8681 | } |
| 8682 | return logicalSlotsMapping; |
| 8683 | } finally { |
| 8684 | Binder.restoreCallingIdentity(identity); |
| 8685 | } |
| 8686 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8687 | |
| 8688 | /** |
| 8689 | * Get the IRadio HAL Version |
| 8690 | */ |
| 8691 | @Override |
| 8692 | public int getRadioHalVersion() { |
| 8693 | Phone phone = getDefaultPhone(); |
| 8694 | if (phone == null) return -1; |
| 8695 | HalVersion hv = phone.getHalVersion(); |
| 8696 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8697 | return hv.major * 100 + hv.minor; |
| 8698 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8699 | |
| 8700 | /** |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8701 | * Get the current calling package name. |
| 8702 | * @return the current calling package name |
| 8703 | */ |
| 8704 | @Override |
| 8705 | public String getCurrentPackageName() { |
| 8706 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8707 | } |
| 8708 | |
| 8709 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8710 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8711 | * corresponding network requests on a subId. |
| 8712 | * |
| 8713 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8714 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8715 | * 2) APN is un-metered for this subscription, or |
| 8716 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | b48cf45 | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 8717 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8718 | * |
| 8719 | * @return whether data is allowed for a apn type. |
| 8720 | * |
| 8721 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8722 | */ |
| 8723 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8724 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | f250974 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8725 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8726 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8727 | |
| 8728 | // Now that all security checks passes, perform the operation as ourselves. |
| 8729 | final long identity = Binder.clearCallingIdentity(); |
| 8730 | try { |
| 8731 | Phone phone = getPhone(subId); |
| 8732 | if (phone == null) return false; |
| 8733 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8734 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8735 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8736 | } finally { |
| 8737 | Binder.restoreCallingIdentity(identity); |
| 8738 | } |
| 8739 | } |
| 8740 | |
| 8741 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8742 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8743 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8744 | |
| 8745 | // Now that all security checks passes, perform the operation as ourselves. |
| 8746 | final long identity = Binder.clearCallingIdentity(); |
| 8747 | try { |
| 8748 | Phone phone = getPhone(subId); |
| 8749 | if (phone == null) return true; // By default return true. |
| 8750 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8751 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8752 | } finally { |
| 8753 | Binder.restoreCallingIdentity(identity); |
| 8754 | } |
| 8755 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8756 | |
| 8757 | @Override |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 8758 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 8759 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 8760 | enforceModifyPermission(); |
| 8761 | long token = Binder.clearCallingIdentity(); |
| 8762 | try { |
| 8763 | Phone phone = getPhone(subscriptionId); |
| 8764 | if (phone == null) { |
| 8765 | try { |
| 8766 | if (resultCallback != null) { |
| 8767 | resultCallback.accept(false); |
| 8768 | } |
| 8769 | } catch (RemoteException e) { |
| 8770 | // ignore |
| 8771 | } |
| 8772 | return; |
| 8773 | } |
| 8774 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 8775 | Pair.create(specifiers, (x) -> { |
| 8776 | try { |
| 8777 | if (resultCallback != null) { |
| 8778 | resultCallback.accept(x); |
| 8779 | } |
| 8780 | } catch (RemoteException e) { |
| 8781 | // ignore |
| 8782 | } |
| 8783 | }); |
| 8784 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 8785 | } finally { |
| 8786 | Binder.restoreCallingIdentity(token); |
| 8787 | } |
| 8788 | } |
| 8789 | |
| 8790 | @Override |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 8791 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 8792 | TelephonyPermissions |
| 8793 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8794 | mApp, subId, "getSystemSelectionChannels"); |
| 8795 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8796 | final long identity = Binder.clearCallingIdentity(); |
| 8797 | try { |
| 8798 | List<RadioAccessSpecifier> specifiers = |
| 8799 | (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, |
| 8800 | null, subId, workSource); |
| 8801 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 8802 | return specifiers; |
| 8803 | } finally { |
| 8804 | Binder.restoreCallingIdentity(identity); |
| 8805 | } |
| 8806 | } |
| 8807 | |
| 8808 | @Override |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8809 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 8810 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8811 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 8812 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 8813 | if (iccRecords == null) { |
| 8814 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 8815 | return false; |
| 8816 | } |
| 8817 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 8818 | } |
| 8819 | |
| 8820 | @Override |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8821 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 8822 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8823 | if (callingPackage == null) { |
| 8824 | callingPackage = getCurrentPackageName(); |
| 8825 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8826 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 8827 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8828 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 8829 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8830 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 8831 | } |
| 8832 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 8833 | Intent intent = new Intent(); |
| 8834 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 8835 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 8836 | // Bring up choose default SMS subscription dialog right now |
| 8837 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 8838 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 8839 | mApp.startActivity(intent); |
| 8840 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8841 | |
| 8842 | @Override |
| 8843 | public String getMmsUAProfUrl(int subId) { |
| 8844 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8845 | final long identity = Binder.clearCallingIdentity(); |
| 8846 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 8847 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 8848 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 8849 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 8850 | return carrierUAProfUrl; |
| 8851 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8852 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8853 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 8854 | } finally { |
| 8855 | Binder.restoreCallingIdentity(identity); |
| 8856 | } |
| 8857 | } |
| 8858 | |
| 8859 | @Override |
| 8860 | public String getMmsUserAgent(int subId) { |
| 8861 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8862 | final long identity = Binder.clearCallingIdentity(); |
| 8863 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 8864 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 8865 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 8866 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 8867 | return carrierUserAgent; |
| 8868 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8869 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8870 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 8871 | } finally { |
| 8872 | Binder.restoreCallingIdentity(identity); |
| 8873 | } |
| 8874 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8875 | |
| 8876 | @Override |
Hall Liu | c041a55 | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 8877 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 8878 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
| 8879 | |
| 8880 | final long identity = Binder.clearCallingIdentity(); |
| 8881 | try { |
| 8882 | Phone phone = getPhone(subscriptionId); |
| 8883 | if (phone == null) return false; |
| 8884 | |
| 8885 | switch (policy) { |
| 8886 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 8887 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 8888 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 8889 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 8890 | default: |
| 8891 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 8892 | } |
| 8893 | } finally { |
| 8894 | Binder.restoreCallingIdentity(identity); |
| 8895 | } |
| 8896 | } |
| 8897 | |
| 8898 | @Override |
| 8899 | public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy, |
| 8900 | boolean enabled) { |
| 8901 | enforceModifyPermission(); |
| 8902 | |
| 8903 | final long identity = Binder.clearCallingIdentity(); |
| 8904 | try { |
| 8905 | Phone phone = getPhone(subscriptionId); |
| 8906 | if (phone == null) return; |
| 8907 | |
| 8908 | switch (policy) { |
| 8909 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 8910 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 8911 | break; |
| 8912 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 8913 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 8914 | break; |
| 8915 | default: |
| 8916 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 8917 | } |
| 8918 | } finally { |
| 8919 | Binder.restoreCallingIdentity(identity); |
| 8920 | } |
| 8921 | } |
| 8922 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8923 | /** |
Hall Liu | b48cf45 | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 8924 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8925 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 8926 | * otherwise. |
| 8927 | */ |
| 8928 | @Override |
| 8929 | public void setCepEnabled(boolean isCepEnabled) { |
| 8930 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 8931 | |
| 8932 | final long identity = Binder.clearCallingIdentity(); |
| 8933 | try { |
| 8934 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 8935 | for (Phone phone : PhoneFactory.getPhones()) { |
| 8936 | Phone defaultPhone = phone.getImsPhone(); |
| 8937 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 8938 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 8939 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 8940 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 8941 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 8942 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 8943 | + imsPhone.getMsisdn()); |
| 8944 | } |
| 8945 | } |
| 8946 | } finally { |
| 8947 | Binder.restoreCallingIdentity(identity); |
| 8948 | } |
| 8949 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 8950 | |
| 8951 | /** |
| 8952 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 8953 | * |
| 8954 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 8955 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 8956 | * before being read. |
| 8957 | */ |
| 8958 | @Override |
| 8959 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 8960 | isCompressed) { |
| 8961 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8962 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
| 8963 | try { |
| 8964 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 8965 | if (configBinder == null) { |
| 8966 | Rlog.e(LOG_TAG, "null result for getImsConfig"); |
| 8967 | } else { |
| 8968 | configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed); |
| 8969 | } |
| 8970 | } catch (RemoteException e) { |
| 8971 | Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage()); |
| 8972 | } |
| 8973 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8974 | |
| 8975 | @Override |
| 8976 | public boolean isIccLockEnabled(int subId) { |
| 8977 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 8978 | |
| 8979 | // Now that all security checks passes, perform the operation as ourselves. |
| 8980 | final long identity = Binder.clearCallingIdentity(); |
| 8981 | try { |
| 8982 | Phone phone = getPhone(subId); |
| 8983 | if (phone != null && phone.getIccCard() != null) { |
| 8984 | return phone.getIccCard().getIccLockEnabled(); |
| 8985 | } else { |
| 8986 | return false; |
| 8987 | } |
| 8988 | } finally { |
| 8989 | Binder.restoreCallingIdentity(identity); |
| 8990 | } |
| 8991 | } |
| 8992 | |
| 8993 | /** |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8994 | * Set the ICC pin lock enabled or disabled. |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8995 | * |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8996 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 8997 | * three cases: |
| 8998 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 8999 | * successfully. |
| 9000 | * - Positive number and zero for remaining password attempts. |
| 9001 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9002 | * |
| 9003 | */ |
| 9004 | @Override |
| 9005 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9006 | enforceModifyPermission(); |
| 9007 | |
| 9008 | Phone phone = getPhone(subId); |
| 9009 | if (phone == null) { |
| 9010 | return 0; |
| 9011 | } |
| 9012 | // Now that all security checks passes, perform the operation as ourselves. |
| 9013 | final long identity = Binder.clearCallingIdentity(); |
| 9014 | try { |
| 9015 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9016 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9017 | return attemptsRemaining; |
| 9018 | |
| 9019 | } catch (Exception e) { |
| 9020 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9021 | } finally { |
| 9022 | Binder.restoreCallingIdentity(identity); |
| 9023 | } |
| 9024 | return 0; |
| 9025 | } |
| 9026 | |
| 9027 | /** |
| 9028 | * Change the ICC password used in ICC pin lock. |
| 9029 | * |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9030 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9031 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9032 | * - Positive number and zero for remaining password attempts. |
| 9033 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9034 | * |
| 9035 | */ |
| 9036 | @Override |
| 9037 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9038 | enforceModifyPermission(); |
| 9039 | |
| 9040 | Phone phone = getPhone(subId); |
| 9041 | if (phone == null) { |
| 9042 | return 0; |
| 9043 | } |
| 9044 | // Now that all security checks passes, perform the operation as ourselves. |
| 9045 | final long identity = Binder.clearCallingIdentity(); |
| 9046 | try { |
| 9047 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9048 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9049 | return attemptsRemaining; |
| 9050 | |
| 9051 | } catch (Exception e) { |
| 9052 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9053 | } finally { |
| 9054 | Binder.restoreCallingIdentity(identity); |
| 9055 | } |
| 9056 | return 0; |
| 9057 | } |
Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9058 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9059 | /** |
| 9060 | * Request for receiving user activity notification |
| 9061 | */ |
| 9062 | @Override |
| 9063 | public void requestUserActivityNotification() { |
| 9064 | if (!mNotifyUserActivity.get() |
| 9065 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9066 | mNotifyUserActivity.set(true); |
| 9067 | } |
| 9068 | } |
| 9069 | |
| 9070 | /** |
| 9071 | * Called when userActivity is signalled in the power manager. |
| 9072 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9073 | */ |
| 9074 | @Override |
| 9075 | public void userActivity() { |
| 9076 | // *************************************** |
| 9077 | // * Inherited from PhoneWindowManager * |
| 9078 | // *************************************** |
| 9079 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9080 | // WITH ITS LOCKS HELD. |
| 9081 | // |
| 9082 | // This code must be VERY careful about the locks |
| 9083 | // it acquires. |
| 9084 | // In fact, the current code acquires way too many, |
| 9085 | // and probably has lurking deadlocks. |
| 9086 | |
| 9087 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9088 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9089 | } |
| 9090 | |
| 9091 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9092 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9093 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9094 | } |
| 9095 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9096 | |
Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9097 | @Override |
| 9098 | public boolean canConnectTo5GInDsdsMode() { |
| 9099 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9100 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9101 | |
| 9102 | @Override |
| 9103 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 9104 | String callingFeatureId) { |
| 9105 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 9106 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 9107 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9108 | } |
| 9109 | |
| 9110 | Phone phone = getPhone(subId); |
| 9111 | if (phone == null) { |
| 9112 | throw new RuntimeException("phone is not available"); |
| 9113 | } |
| 9114 | // Now that all security checks passes, perform the operation as ourselves. |
| 9115 | final long identity = Binder.clearCallingIdentity(); |
| 9116 | try { |
| 9117 | return phone.getEquivalentHomePlmns(); |
| 9118 | } finally { |
| 9119 | Binder.restoreCallingIdentity(identity); |
| 9120 | } |
| 9121 | } |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame^] | 9122 | |
| 9123 | /** |
| 9124 | * Attempts to set the radio power state for thermal reason. This does not guarantee that the |
| 9125 | * requested radio power state will actually be set. See {@link |
| 9126 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 9127 | * |
| 9128 | * @param subId the subscription ID of the phone requesting to set the radio power state. |
| 9129 | * @param enable {@code true} if trying to turn radio on. |
| 9130 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 9131 | * false}. |
| 9132 | */ |
| 9133 | private boolean setRadioPowerForThermal(int subId, boolean enable) { |
| 9134 | Phone phone = getPhone(subId); |
| 9135 | if (phone != null) { |
| 9136 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 9137 | return true; |
| 9138 | } |
| 9139 | return false; |
| 9140 | } |
| 9141 | |
| 9142 | private int handleDataThrottlingRequest(int subId, |
| 9143 | DataThrottlingRequest dataThrottlingRequest) { |
| 9144 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 9145 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9146 | if (!setRadioPowerForThermal(subId, true)) { |
| 9147 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9148 | } |
| 9149 | |
| 9150 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 9151 | |
| 9152 | int thermalMitigationResult = |
| 9153 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
| 9154 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 9155 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 9156 | } |
| 9157 | return thermalMitigationResult; |
| 9158 | } |
| 9159 | |
| 9160 | /** |
| 9161 | * Thermal mitigation request to control functionalities at modem. |
| 9162 | * |
| 9163 | * @param subId the id of the subscription. |
| 9164 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
| 9165 | * |
| 9166 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 9167 | */ |
| 9168 | @Override |
| 9169 | @ThermalMitigationResult |
| 9170 | public int sendThermalMitigationRequest( |
| 9171 | int subId, |
| 9172 | ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException { |
| 9173 | enforceModifyPermission(); |
| 9174 | |
| 9175 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9176 | final long identity = Binder.clearCallingIdentity(); |
| 9177 | |
| 9178 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 9179 | try { |
| 9180 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 9181 | switch (thermalMitigationAction) { |
| 9182 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 9183 | thermalMitigationResult = |
| 9184 | handleDataThrottlingRequest(subId, |
| 9185 | thermalMitigationRequest.getDataThrottlingRequest()); |
| 9186 | break; |
| 9187 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 9188 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9189 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 9190 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 9191 | } |
| 9192 | |
| 9193 | // Ensure that radio is on. If not able to power on due to phone being |
| 9194 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9195 | if (!setRadioPowerForThermal(subId, true)) { |
| 9196 | thermalMitigationResult = |
| 9197 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9198 | break; |
| 9199 | } |
| 9200 | |
| 9201 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 9202 | false); |
| 9203 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9204 | break; |
| 9205 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 9206 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9207 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 9208 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 9209 | } |
| 9210 | |
| 9211 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 9212 | if (registry != null) { |
| 9213 | TelephonyConnectionService service = |
| 9214 | registry.getTelephonyConnectionService(); |
| 9215 | Phone phone = getPhone(subId); |
| 9216 | if (phone == null) { |
| 9217 | thermalMitigationResult = |
| 9218 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9219 | break; |
| 9220 | } |
| 9221 | |
| 9222 | if (PhoneConstantConversions.convertCallState(phone.getState()) |
| 9223 | != TelephonyManager.CALL_STATE_IDLE |
| 9224 | || phone.isInEmergencySmsMode() || phone.isInEcm() |
| 9225 | || (service != null && service.isEmergencyCallPending())) { |
| 9226 | String errorMessage = "Phone state is not valid. call state = " |
| 9227 | + PhoneConstantConversions.convertCallState(phone.getState()) |
| 9228 | + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode() |
| 9229 | + " isInEmergencyCallbackMode = " + phone.isInEcm(); |
| 9230 | errorMessage += service == null |
| 9231 | ? " TelephonyConnectionService is null" |
| 9232 | : " isEmergencyCallPending = " |
| 9233 | + service.isEmergencyCallPending(); |
| 9234 | Log.e(LOG_TAG, errorMessage); |
| 9235 | thermalMitigationResult = |
| 9236 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 9237 | break; |
| 9238 | } |
| 9239 | } else { |
| 9240 | thermalMitigationResult = |
| 9241 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9242 | break; |
| 9243 | } |
| 9244 | |
| 9245 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 9246 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9247 | if (!setRadioPowerForThermal(subId, false)) { |
| 9248 | thermalMitigationResult = |
| 9249 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9250 | break; |
| 9251 | } |
| 9252 | thermalMitigationResult = |
| 9253 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9254 | break; |
| 9255 | default: |
| 9256 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 9257 | + "not exist. Requested action: " + thermalMitigationAction); |
| 9258 | } |
| 9259 | } catch (IllegalArgumentException e) { |
| 9260 | throw e; |
| 9261 | } catch (Exception e) { |
| 9262 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 9263 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 9264 | } finally { |
| 9265 | Binder.restoreCallingIdentity(identity); |
| 9266 | } |
| 9267 | |
| 9268 | if (DBG) { |
| 9269 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 9270 | + thermalMitigationResult); |
| 9271 | } |
| 9272 | |
| 9273 | return thermalMitigationResult; |
| 9274 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 9275 | } |