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 | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5884 | Boolean success = (Boolean) sendRequest( |
| 5885 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
calvinpan | 03641a7 | 2020-08-18 16:53:59 +0800 | [diff] [blame] | 5886 | |
| 5887 | if (success) { |
| 5888 | Settings.Global.putInt(mApp.getContentResolver(), |
| 5889 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 5890 | } |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5891 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 5892 | return success; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5893 | } finally { |
| 5894 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5895 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5896 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5897 | |
| 5898 | /** |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5899 | * Get the allowed network types that store in the telephony provider. |
| 5900 | * |
| 5901 | * @param subId the id of the subscription. |
| 5902 | * @return allowedNetworkTypes the allowed network types. |
| 5903 | */ |
| 5904 | @Override |
| 5905 | public long getAllowedNetworkTypes(int subId) { |
| 5906 | TelephonyPermissions |
| 5907 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5908 | mApp, subId, "getAllowedNetworkTypes"); |
| 5909 | |
| 5910 | final long identity = Binder.clearCallingIdentity(); |
| 5911 | try { |
| 5912 | return SubscriptionManager.getLongSubscriptionProperty( |
| 5913 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5914 | } finally { |
| 5915 | Binder.restoreCallingIdentity(identity); |
| 5916 | } |
| 5917 | } |
| 5918 | |
| 5919 | /** |
| 5920 | * Set the allowed network types. |
| 5921 | * |
| 5922 | * @param subId the id of the subscription. |
| 5923 | * @param allowedNetworkTypes the allowed network types. |
| 5924 | * @return true on success; false on any failure. |
| 5925 | */ |
| 5926 | @Override |
| 5927 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 5928 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5929 | mApp, subId, "setAllowedNetworkTypes"); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5930 | |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5931 | SubscriptionManager.setSubscriptionProperty(subId, |
| 5932 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 5933 | String.valueOf(allowedNetworkTypes)); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5934 | |
calvinpan | 089c2a6 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5935 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 5936 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 5937 | RILConstants.PREFERRED_NETWORK_MODE); |
| 5938 | return setPreferredNetworkType(subId, preferredNetworkMode); |
calvinpan | 677fc2b | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5939 | } |
| 5940 | |
| 5941 | /** |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 5942 | * Get the allowed network types for certain reason. |
| 5943 | * |
| 5944 | * @param subId the id of the subscription. |
| 5945 | * @param reason the reason the allowed network type change is taking place |
| 5946 | * @return the allowed network types. |
| 5947 | */ |
| 5948 | @Override |
| 5949 | public long getAllowedNetworkTypesForReason(int subId, |
| 5950 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
| 5951 | TelephonyPermissions |
| 5952 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5953 | mApp, subId, "getAllowedNetworkTypesForReason"); |
| 5954 | final long identity = Binder.clearCallingIdentity(); |
| 5955 | try { |
| 5956 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 5957 | } finally { |
| 5958 | Binder.restoreCallingIdentity(identity); |
| 5959 | } |
| 5960 | } |
| 5961 | |
| 5962 | /** |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 5963 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 5964 | * @param subId subscription id of the sim card |
| 5965 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 5966 | * This can be passed following states |
| 5967 | * <ol> |
| 5968 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 5969 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 5970 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 5971 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 5972 | * </ol> |
| 5973 | * @return operation result. |
| 5974 | */ |
| 5975 | @Override |
| 5976 | public int setNrDualConnectivityState(int subId, |
| 5977 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 5978 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5979 | mApp, subId, "enableNRDualConnectivity"); |
| 5980 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 5981 | final long identity = Binder.clearCallingIdentity(); |
| 5982 | try { |
| 5983 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 5984 | nrDualConnectivityState, subId, |
| 5985 | workSource); |
| 5986 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 5987 | return result; |
| 5988 | } finally { |
| 5989 | Binder.restoreCallingIdentity(identity); |
| 5990 | } |
| 5991 | } |
| 5992 | |
| 5993 | /** |
| 5994 | * Is E-UTRA-NR Dual Connectivity enabled |
| 5995 | * @return true if dual connectivity is enabled else false |
| 5996 | */ |
| 5997 | @Override |
| 5998 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 5999 | TelephonyPermissions |
| 6000 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6001 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6002 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6003 | final long identity = Binder.clearCallingIdentity(); |
| 6004 | try { |
| 6005 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6006 | null, subId, workSource); |
| 6007 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6008 | return isEnabled; |
| 6009 | } finally { |
| 6010 | Binder.restoreCallingIdentity(identity); |
| 6011 | } |
| 6012 | } |
| 6013 | |
| 6014 | /** |
Sooraj Sasindran | 1f812e0 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 6015 | * get carrier bandwidth per primary and secondary carrier |
| 6016 | * @param subId subscription id of the sim card |
| 6017 | * @return CarrierBandwidth with bandwidth of both primary and secondary carrier.. |
| 6018 | */ |
| 6019 | @Override |
| 6020 | public CarrierBandwidth getCarrierBandwidth(int subId) { |
| 6021 | TelephonyPermissions |
| 6022 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6023 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6024 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6025 | final long identity = Binder.clearCallingIdentity(); |
| 6026 | try { |
| 6027 | CarrierBandwidth carrierBandwidth = |
| 6028 | getPhoneFromSubId(subId).getCarrierBandwidth(); |
| 6029 | if (DBG) log("getCarrierBandwidth: " + carrierBandwidth); |
| 6030 | return carrierBandwidth; |
| 6031 | } finally { |
| 6032 | Binder.restoreCallingIdentity(identity); |
| 6033 | } |
| 6034 | } |
| 6035 | |
| 6036 | /** |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6037 | * Get the effective allowed network types on the device. |
| 6038 | * This API will return an intersection of allowed network types for all reasons, |
| 6039 | * including the configuration done through setAllowedNetworkTypes |
| 6040 | * |
| 6041 | * @param subId the id of the subscription. |
| 6042 | * @return the allowed network types |
| 6043 | */ |
| 6044 | @Override |
| 6045 | public long getEffectiveAllowedNetworkTypes(int subId) { |
| 6046 | TelephonyPermissions |
| 6047 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6048 | mApp, subId, "getEffectiveAllowedNetworkTypes"); |
| 6049 | final long identity = Binder.clearCallingIdentity(); |
| 6050 | try { |
| 6051 | return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes(); |
| 6052 | } finally { |
| 6053 | Binder.restoreCallingIdentity(identity); |
| 6054 | } |
| 6055 | } |
| 6056 | |
| 6057 | /** |
| 6058 | * Set the allowed network types of the device and |
| 6059 | * provide the reason triggering the allowed network change. |
| 6060 | * |
| 6061 | * @param subId the id of the subscription. |
| 6062 | * @param reason the reason the allowed network type change is taking place |
| 6063 | * @param allowedNetworkTypes the allowed network types. |
| 6064 | * @return true on success; false on any failure. |
| 6065 | */ |
| 6066 | @Override |
| 6067 | public boolean setAllowedNetworkTypesForReason(int subId, |
| 6068 | @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) { |
| 6069 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6070 | mApp, subId, "setAllowedNetworkTypesForReason"); |
| 6071 | final long identity = Binder.clearCallingIdentity(); |
| 6072 | try { |
| 6073 | getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes); |
| 6074 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 6075 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 6076 | RILConstants.PREFERRED_NETWORK_MODE); |
| 6077 | return setPreferredNetworkType(subId, preferredNetworkMode); |
| 6078 | } finally { |
| 6079 | Binder.restoreCallingIdentity(identity); |
| 6080 | } |
| 6081 | } |
| 6082 | |
| 6083 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6084 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6085 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6086 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6087 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6088 | * @hide |
| 6089 | */ |
| 6090 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6091 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6092 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6093 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6094 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6095 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6096 | if (phone != null) { |
| 6097 | return phone.hasMatchedTetherApnSetting(); |
| 6098 | } else { |
| 6099 | return false; |
| 6100 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6101 | } finally { |
| 6102 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6103 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6104 | } |
| 6105 | |
| 6106 | /** |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6107 | * Enable or disable always reporting signal strength changes from radio. |
| 6108 | * |
| 6109 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 6110 | */ |
| 6111 | @Override |
| 6112 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 6113 | enforceModifyPermission(); |
| 6114 | enforceSystemCaller(); |
| 6115 | |
| 6116 | final long identity = Binder.clearCallingIdentity(); |
| 6117 | final Phone phone = getPhone(subId); |
| 6118 | try { |
| 6119 | if (phone != null) { |
| 6120 | if (DBG) { |
| 6121 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6122 | + " isEnable=" + isEnable); |
| 6123 | } |
| 6124 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6125 | } else { |
| 6126 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6127 | + subId); |
| 6128 | } |
| 6129 | } finally { |
| 6130 | Binder.restoreCallingIdentity(identity); |
| 6131 | } |
| 6132 | } |
| 6133 | |
| 6134 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6135 | * Get the user enabled state of Mobile Data. |
| 6136 | * |
| 6137 | * TODO: remove and use isUserDataEnabled. |
| 6138 | * This can't be removed now because some vendor codes |
| 6139 | * calls through ITelephony directly while they should |
| 6140 | * use TelephonyManager. |
| 6141 | * |
| 6142 | * @return true on enabled |
| 6143 | */ |
| 6144 | @Override |
| 6145 | public boolean getDataEnabled(int subId) { |
| 6146 | return isUserDataEnabled(subId); |
| 6147 | } |
| 6148 | |
| 6149 | /** |
| 6150 | * Get whether mobile data is enabled per user setting. |
| 6151 | * |
| 6152 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6153 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6154 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6155 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6156 | * |
| 6157 | * @return {@code true} if data is enabled else {@code false} |
| 6158 | */ |
| 6159 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6160 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6161 | try { |
| 6162 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6163 | null); |
| 6164 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6165 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6166 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6167 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6168 | |
| 6169 | final long identity = Binder.clearCallingIdentity(); |
| 6170 | try { |
| 6171 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6172 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6173 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6174 | if (phone != null) { |
| 6175 | boolean retVal = phone.isUserDataEnabled(); |
| 6176 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6177 | return retVal; |
| 6178 | } else { |
| 6179 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6180 | return false; |
| 6181 | } |
| 6182 | } finally { |
| 6183 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6184 | } |
| 6185 | } |
| 6186 | |
| 6187 | /** |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6188 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6189 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6190 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6191 | * |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6192 | * @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] | 6193 | */ |
| 6194 | @Override |
| 6195 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6196 | try { |
| 6197 | try { |
| 6198 | mApp.enforceCallingOrSelfPermission( |
| 6199 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6200 | null); |
| 6201 | } catch (Exception e) { |
| 6202 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6203 | "isDataEnabled"); |
| 6204 | } |
| 6205 | } catch (Exception e) { |
| 6206 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6207 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6208 | |
| 6209 | final long identity = Binder.clearCallingIdentity(); |
| 6210 | try { |
| 6211 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6212 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6213 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6214 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6215 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6216 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6217 | return retVal; |
| 6218 | } else { |
| 6219 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6220 | return false; |
| 6221 | } |
| 6222 | } finally { |
| 6223 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6224 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6225 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6226 | |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6227 | /** |
| 6228 | * Check if data is enabled for a specific reason |
| 6229 | * @param subId Subscription index |
| 6230 | * @param reason the reason the data enable change is taking place |
| 6231 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6232 | */ |
| 6233 | @Override |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6234 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6235 | @TelephonyManager.DataEnabledReason int reason) { |
| 6236 | try { |
| 6237 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6238 | null); |
| 6239 | } catch (Exception e) { |
| 6240 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6241 | "isDataEnabledForReason"); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6242 | } |
| 6243 | |
| 6244 | |
| 6245 | final long identity = Binder.clearCallingIdentity(); |
| 6246 | try { |
| 6247 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6248 | if (DBG) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6249 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6250 | + " reason=" + reason); |
| 6251 | } |
| 6252 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6253 | if (phone != null) { |
| 6254 | boolean retVal; |
| 6255 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6256 | retVal = phone.isUserDataEnabled(); |
| 6257 | } else { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6258 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6259 | } |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6260 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6261 | return retVal; |
| 6262 | } else { |
| 6263 | if (DBG) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6264 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6265 | + subId + " retVal=false"); |
| 6266 | } |
| 6267 | return false; |
| 6268 | } |
| 6269 | } finally { |
| 6270 | Binder.restoreCallingIdentity(identity); |
| 6271 | } |
| 6272 | } |
| 6273 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6274 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6275 | Phone phone) { |
Hall Liu | ce478d2 | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 6276 | if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) { |
| 6277 | // Skip the check if it's one of these special uids |
| 6278 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6279 | } |
| 6280 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6281 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6282 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6283 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6284 | || subController == null) return privilegeFromSim; |
| 6285 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6286 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6287 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6288 | |
| 6289 | final long identity = Binder.clearCallingIdentity(); |
| 6290 | try { |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6291 | int subId = phone.getSubId(); |
| 6292 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6293 | // A test override is in place for the privileges for this subId, so don't try to |
| 6294 | // read the subscription privileges. |
| 6295 | return privilegeFromSim; |
| 6296 | } |
| 6297 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6298 | SubscriptionManager subManager = (SubscriptionManager) |
| 6299 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6300 | for (String pkg : packages) { |
| 6301 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6302 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6303 | } |
| 6304 | } |
| 6305 | return privilegeFromSim; |
| 6306 | } finally { |
| 6307 | Binder.restoreCallingIdentity(identity); |
| 6308 | } |
| 6309 | } |
| 6310 | |
| 6311 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6312 | String pkgName) { |
| 6313 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6314 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6315 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6316 | || subController == null) return privilegeFromSim; |
| 6317 | |
| 6318 | final long identity = Binder.clearCallingIdentity(); |
| 6319 | try { |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6320 | int subId = phone.getSubId(); |
| 6321 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6322 | // A test override is in place for the privileges for this subId, so don't try to |
| 6323 | // read the subscription privileges. |
| 6324 | return privilegeFromSim; |
| 6325 | } |
| 6326 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6327 | SubscriptionManager subManager = (SubscriptionManager) |
| 6328 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6329 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6330 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6331 | } finally { |
| 6332 | Binder.restoreCallingIdentity(identity); |
| 6333 | } |
| 6334 | } |
| 6335 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6336 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6337 | public int getCarrierPrivilegeStatus(int subId) { |
| 6338 | final Phone phone = getPhone(subId); |
| 6339 | if (phone == null) { |
| 6340 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6341 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6342 | } |
| 6343 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6344 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6345 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6346 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6347 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6348 | |
| 6349 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6350 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6351 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6352 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6353 | |
| 6354 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6355 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6356 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6357 | final Phone phone = getPhone(subId); |
| 6358 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6359 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6360 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6361 | } |
| 6362 | UiccProfile profile = |
| 6363 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6364 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6365 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6366 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6367 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6368 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6369 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6370 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6371 | } |
| 6372 | |
| 6373 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6374 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 6375 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6376 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6377 | } |
| 6378 | |
| 6379 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 6380 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6381 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6382 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6383 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6384 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6385 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6386 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6387 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6388 | } |
| 6389 | |
| 6390 | @Override |
| 6391 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6392 | if (TextUtils.isEmpty(pkgName)) |
| 6393 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6394 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6395 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6396 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 6397 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6398 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6399 | continue; |
| 6400 | } |
| 6401 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6402 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6403 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6404 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6405 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6406 | break; |
| 6407 | } |
| 6408 | } |
| 6409 | |
| 6410 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6411 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6412 | |
| 6413 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6414 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 6415 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6416 | loge("phoneId " + phoneId + " is not valid."); |
| 6417 | return null; |
| 6418 | } |
| 6419 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6420 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6421 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6422 | return null ; |
| 6423 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6424 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6425 | } |
| 6426 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6427 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6428 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6429 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6430 | List<String> privilegedPackages = new ArrayList<>(); |
| 6431 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6432 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 6433 | // has UICC in that slot. |
| 6434 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6435 | if (card.hasCarrierPrivilegeRules()) { |
| 6436 | if (packages == null) { |
| 6437 | // Only check packages in user 0 for now |
| 6438 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6439 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6440 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6441 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6442 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6443 | } |
| 6444 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6445 | PackageInfo pkgInfo = packages.get(p); |
| 6446 | if (pkgInfo != null && pkgInfo.packageName != null |
| 6447 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6448 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6449 | privilegedPackages.add(pkgInfo.packageName); |
| 6450 | } |
| 6451 | } |
| 6452 | } |
| 6453 | } |
| 6454 | return privilegedPackages; |
| 6455 | } |
| 6456 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6457 | @Override |
| 6458 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6459 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6460 | |
| 6461 | final long identity = Binder.clearCallingIdentity(); |
| 6462 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6463 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6464 | try { |
| 6465 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6466 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6467 | } |
| 6468 | } finally { |
| 6469 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6470 | } |
| 6471 | return privilegedPackages; |
| 6472 | } |
| 6473 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6474 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6475 | final Phone phone = getPhone(subId); |
| 6476 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6477 | if (card == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6478 | return null; |
| 6479 | } |
| 6480 | String iccId = card.getIccId(); |
| 6481 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6482 | return null; |
| 6483 | } |
| 6484 | return iccId; |
| 6485 | } |
| 6486 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6487 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6488 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6489 | String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6490 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6491 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6492 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6493 | final long identity = Binder.clearCallingIdentity(); |
| 6494 | try { |
| 6495 | final String iccId = getIccId(subId); |
| 6496 | final Phone phone = getPhone(subId); |
| 6497 | if (phone == null) { |
| 6498 | return false; |
| 6499 | } |
| 6500 | final String subscriberId = phone.getSubscriberId(); |
| 6501 | |
| 6502 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6503 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6504 | + subscriberId + " to " + number); |
| 6505 | } |
| 6506 | |
| 6507 | if (TextUtils.isEmpty(iccId)) { |
| 6508 | return false; |
| 6509 | } |
| 6510 | |
| 6511 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6512 | |
| 6513 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6514 | if (alphaTag == null) { |
| 6515 | editor.remove(alphaTagPrefKey); |
| 6516 | } else { |
| 6517 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6518 | } |
| 6519 | |
| 6520 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6521 | // track all merged IMSIs based on line number |
| 6522 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6523 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6524 | if (number == null) { |
| 6525 | editor.remove(numberPrefKey); |
| 6526 | editor.remove(subscriberPrefKey); |
| 6527 | } else { |
| 6528 | editor.putString(numberPrefKey, number); |
| 6529 | editor.putString(subscriberPrefKey, subscriberId); |
| 6530 | } |
| 6531 | |
| 6532 | editor.commit(); |
| 6533 | return true; |
| 6534 | } finally { |
| 6535 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6536 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6537 | } |
| 6538 | |
| 6539 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6540 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6541 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6542 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6543 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6544 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6545 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6546 | return null; |
| 6547 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6548 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6549 | final long identity = Binder.clearCallingIdentity(); |
| 6550 | try { |
| 6551 | String iccId = getIccId(subId); |
| 6552 | if (iccId != null) { |
| 6553 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6554 | if (DBG_MERGE) { |
| 6555 | log("getLine1NumberForDisplay returning " |
| 6556 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6557 | } |
| 6558 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6559 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6560 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6561 | return null; |
| 6562 | } finally { |
| 6563 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6564 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6565 | } |
| 6566 | |
| 6567 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6568 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6569 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6570 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6571 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6572 | return null; |
| 6573 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6574 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6575 | final long identity = Binder.clearCallingIdentity(); |
| 6576 | try { |
| 6577 | String iccId = getIccId(subId); |
| 6578 | if (iccId != null) { |
| 6579 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6580 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6581 | } |
| 6582 | return null; |
| 6583 | } finally { |
| 6584 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6585 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6586 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6587 | |
| 6588 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6589 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6590 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6591 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6592 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6593 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6594 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6595 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6596 | return null; |
| 6597 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6598 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6599 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6600 | // the process, where TelephonyManager was instantiated. |
| 6601 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6602 | final long identity = Binder.clearCallingIdentity(); |
| 6603 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6604 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6605 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6606 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6607 | |
| 6608 | // Figure out what subscribers are currently active |
| 6609 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6610 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6611 | // Only consider subs which match the current subId |
| 6612 | // This logic can be simplified. See b/131189269 for progress. |
| 6613 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6614 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6615 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6616 | |
| 6617 | // First pass, find a number override for an active subscriber |
| 6618 | String mergeNumber = null; |
| 6619 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6620 | for (String key : prefs.keySet()) { |
| 6621 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6622 | final String subscriberId = (String) prefs.get(key); |
| 6623 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6624 | final String iccId = key.substring( |
| 6625 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6626 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6627 | mergeNumber = (String) prefs.get(numberKey); |
| 6628 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6629 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6630 | + " for active subscriber " + subscriberId); |
| 6631 | } |
| 6632 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6633 | break; |
| 6634 | } |
| 6635 | } |
| 6636 | } |
| 6637 | } |
| 6638 | |
| 6639 | // Shortcut when no active merged subscribers |
| 6640 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6641 | return null; |
| 6642 | } |
| 6643 | |
| 6644 | // Second pass, find all subscribers under that line override |
| 6645 | final ArraySet<String> result = new ArraySet<>(); |
| 6646 | for (String key : prefs.keySet()) { |
| 6647 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6648 | final String number = (String) prefs.get(key); |
| 6649 | if (mergeNumber.equals(number)) { |
| 6650 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6651 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6652 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6653 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6654 | result.add(subscriberId); |
| 6655 | } |
| 6656 | } |
| 6657 | } |
| 6658 | } |
| 6659 | |
| 6660 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6661 | Arrays.sort(resultArray); |
| 6662 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6663 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6664 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6665 | } |
| 6666 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6667 | } finally { |
| 6668 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6669 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6670 | } |
| 6671 | |
| 6672 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6673 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6674 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6675 | |
| 6676 | final long identity = Binder.clearCallingIdentity(); |
| 6677 | try { |
| 6678 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6679 | TelephonyManager.class); |
| 6680 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6681 | if (subscriberId == null) { |
| 6682 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6683 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6684 | + subId); |
| 6685 | } |
| 6686 | return null; |
| 6687 | } |
| 6688 | |
| 6689 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6690 | .getSubscriptionInfo(subId); |
| 6691 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6692 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6693 | if (groupUuid == null) { |
| 6694 | return new String[]{subscriberId}; |
| 6695 | } |
| 6696 | |
| 6697 | // Get all subscriberIds from the group. |
| 6698 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6699 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6700 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6701 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6702 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6703 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6704 | if (subscriberId != null) { |
| 6705 | mergedSubscriberIds.add(subscriberId); |
| 6706 | } |
| 6707 | } |
| 6708 | |
| 6709 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6710 | } finally { |
| 6711 | Binder.restoreCallingIdentity(identity); |
| 6712 | |
| 6713 | } |
| 6714 | } |
| 6715 | |
| 6716 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6717 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6718 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6719 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6720 | |
| 6721 | final long identity = Binder.clearCallingIdentity(); |
| 6722 | try { |
| 6723 | final Phone phone = getPhone(subId); |
| 6724 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6725 | } finally { |
| 6726 | Binder.restoreCallingIdentity(identity); |
| 6727 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6728 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6729 | |
| 6730 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6731 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6732 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6733 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6734 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6735 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6736 | |
| 6737 | final long identity = Binder.clearCallingIdentity(); |
| 6738 | try { |
| 6739 | final Phone phone = getPhone(subId); |
| 6740 | if (phone == null) { |
| 6741 | return false; |
| 6742 | } |
| 6743 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6744 | cdmaNonRoamingList); |
| 6745 | } finally { |
| 6746 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6747 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6748 | } |
| 6749 | |
| 6750 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6751 | @Deprecated |
| 6752 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6753 | enforceModifyPermission(); |
| 6754 | |
| 6755 | int returnValue = 0; |
| 6756 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6757 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6758 | if(result.exception == null) { |
| 6759 | if (result.result != null) { |
| 6760 | byte[] responseData = (byte[])(result.result); |
| 6761 | if(responseData.length > oemResp.length) { |
| 6762 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6763 | responseData.length + "bytes. Buffer Size is " + |
| 6764 | oemResp.length + "bytes."); |
| 6765 | } |
| 6766 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6767 | returnValue = responseData.length; |
| 6768 | } |
| 6769 | } else { |
| 6770 | CommandException ex = (CommandException) result.exception; |
| 6771 | returnValue = ex.getCommandError().ordinal(); |
| 6772 | if(returnValue > 0) returnValue *= -1; |
| 6773 | } |
| 6774 | } catch (RuntimeException e) { |
| 6775 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6776 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6777 | if(returnValue > 0) returnValue *= -1; |
| 6778 | } |
| 6779 | |
| 6780 | return returnValue; |
| 6781 | } |
| 6782 | |
| 6783 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6784 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6785 | try { |
| 6786 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6787 | } catch (RuntimeException e) { |
| 6788 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6789 | } |
| 6790 | } |
| 6791 | |
| 6792 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6793 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6794 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 6795 | try { |
| 6796 | TelephonyPermissions |
| 6797 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6798 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6799 | } catch (SecurityException e) { |
| 6800 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 6801 | throw e; |
| 6802 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6803 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6804 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6805 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6806 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6807 | final long identity = Binder.clearCallingIdentity(); |
| 6808 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6809 | TelephonyPermissions |
| 6810 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6811 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6812 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6813 | } finally { |
| 6814 | Binder.restoreCallingIdentity(identity); |
| 6815 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6816 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6817 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6818 | |
| 6819 | @Override |
| 6820 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6821 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6822 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6823 | |
| 6824 | final long identity = Binder.clearCallingIdentity(); |
| 6825 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6826 | ImsManager.getInstance(defaultPhone.getContext(), |
| 6827 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6828 | } finally { |
| 6829 | Binder.restoreCallingIdentity(identity); |
| 6830 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6831 | } |
| 6832 | |
| 6833 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6834 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6835 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6836 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 6837 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6838 | return false; |
| 6839 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6840 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6841 | final long identity = Binder.clearCallingIdentity(); |
| 6842 | try { |
| 6843 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 6844 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 6845 | // In the long run, we may instead need to check if there exists a connection service |
| 6846 | // which can support video calling. |
| 6847 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6848 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6849 | return imsManager.isVtEnabledByPlatform() |
| 6850 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 6851 | && imsManager.isVtEnabledByUser(); |
| 6852 | } finally { |
| 6853 | Binder.restoreCallingIdentity(identity); |
| 6854 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6855 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 6856 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6857 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6858 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 6859 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6860 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6861 | mApp, subId, callingPackage, callingFeatureId, |
| 6862 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6863 | return false; |
| 6864 | } |
| 6865 | |
| 6866 | final long identity = Binder.clearCallingIdentity(); |
| 6867 | try { |
| 6868 | CarrierConfigManager configManager = |
| 6869 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6870 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6871 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 6872 | } finally { |
| 6873 | Binder.restoreCallingIdentity(identity); |
| 6874 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6875 | } |
| 6876 | |
| 6877 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6878 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6879 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6880 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6881 | return false; |
| 6882 | } |
| 6883 | |
| 6884 | final long identity = Binder.clearCallingIdentity(); |
| 6885 | try { |
| 6886 | CarrierConfigManager configManager = |
| 6887 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6888 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6889 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 6890 | } finally { |
| 6891 | Binder.restoreCallingIdentity(identity); |
| 6892 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6893 | } |
| 6894 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6895 | @Override |
| 6896 | public boolean isTtyModeSupported() { |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 6897 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 6898 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6899 | } |
| 6900 | |
| 6901 | @Override |
| 6902 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6903 | final long identity = Binder.clearCallingIdentity(); |
| 6904 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6905 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6906 | } finally { |
| 6907 | Binder.restoreCallingIdentity(identity); |
| 6908 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 6909 | } |
| 6910 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6911 | /** |
| 6912 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 6913 | * support for the feature and device firmware support. |
| 6914 | * |
| 6915 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 6916 | */ |
| 6917 | @Override |
| 6918 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6919 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6920 | final Phone phone = getPhone(subscriptionId); |
| 6921 | if (phone == null) { |
| 6922 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 6923 | return false; |
| 6924 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6925 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6926 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6927 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 6928 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6929 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6930 | return isCarrierSupported && isDeviceSupported; |
| 6931 | } finally { |
| 6932 | Binder.restoreCallingIdentity(identity); |
| 6933 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 6934 | } |
| 6935 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 6936 | /** |
Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 6937 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 6938 | * RTT setting, will return true if the device and carrier both support RTT. |
| 6939 | * 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] | 6940 | */ |
| 6941 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6942 | final long identity = Binder.clearCallingIdentity(); |
| 6943 | try { |
Hall Liu | 63767ec | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 6944 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 6945 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 6946 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 6947 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 6948 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 6949 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6950 | } finally { |
| 6951 | Binder.restoreCallingIdentity(identity); |
| 6952 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 6953 | } |
| 6954 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6955 | @Deprecated |
| 6956 | @Override |
| 6957 | public String getDeviceId(String callingPackage) { |
| 6958 | return getDeviceIdWithFeature(callingPackage, null); |
| 6959 | } |
| 6960 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6961 | /** |
| 6962 | * Returns the unique device ID of phone, for example, the IMEI for |
| 6963 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 6964 | * |
| 6965 | * <p>Requires Permission: |
| 6966 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 6967 | */ |
| 6968 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6969 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6970 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6971 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6972 | return null; |
| 6973 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6974 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 6975 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6976 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6977 | return null; |
| 6978 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6979 | |
| 6980 | final long identity = Binder.clearCallingIdentity(); |
| 6981 | try { |
| 6982 | return phone.getDeviceId(); |
| 6983 | } finally { |
| 6984 | Binder.restoreCallingIdentity(identity); |
| 6985 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 6986 | } |
| 6987 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6988 | /** |
| 6989 | * {@hide} |
| 6990 | * Returns the IMS Registration Status on a particular subid |
| 6991 | * |
| 6992 | * @param subId |
| 6993 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 6994 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 6995 | Phone phone = getPhone(subId); |
| 6996 | if (phone != null) { |
| 6997 | return phone.isImsRegistered(); |
| 6998 | } else { |
| 6999 | return false; |
| 7000 | } |
| 7001 | } |
| 7002 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7003 | @Override |
| 7004 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7005 | final long identity = Binder.clearCallingIdentity(); |
| 7006 | try { |
| 7007 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 7008 | } finally { |
| 7009 | Binder.restoreCallingIdentity(identity); |
| 7010 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7011 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 7012 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7013 | @Override |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7014 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7015 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7016 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7017 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7018 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7019 | } |
| 7020 | final long identity = Binder.clearCallingIdentity(); |
| 7021 | try { |
| 7022 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7023 | } finally { |
| 7024 | Binder.restoreCallingIdentity(identity); |
| 7025 | } |
| 7026 | } |
| 7027 | |
| 7028 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7029 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
duki.hong | fd96bde | 2020-07-22 17:32:19 +0900 | [diff] [blame] | 7030 | enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, " |
| 7031 | + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7032 | final long identity = Binder.clearCallingIdentity(); |
| 7033 | try { |
| 7034 | Phone phone = getPhone(subscriptionId); |
| 7035 | if (phone == null) { |
| 7036 | return null; |
| 7037 | } |
| 7038 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7039 | } finally { |
| 7040 | Binder.restoreCallingIdentity(identity); |
| 7041 | } |
| 7042 | } |
| 7043 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7044 | /** |
| 7045 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7046 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7047 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7048 | final long identity = Binder.clearCallingIdentity(); |
| 7049 | try { |
| 7050 | Phone phone = getPhone(subId); |
| 7051 | if (phone != null) { |
| 7052 | return phone.isWifiCallingEnabled(); |
| 7053 | } else { |
| 7054 | return false; |
| 7055 | } |
| 7056 | } finally { |
| 7057 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7058 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7059 | } |
| 7060 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7061 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7062 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7063 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7064 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7065 | final long identity = Binder.clearCallingIdentity(); |
| 7066 | try { |
| 7067 | Phone phone = getPhone(subId); |
| 7068 | if (phone != null) { |
| 7069 | return phone.isVideoEnabled(); |
| 7070 | } else { |
| 7071 | return false; |
| 7072 | } |
| 7073 | } finally { |
| 7074 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7075 | } |
| 7076 | } |
| 7077 | |
| 7078 | /** |
| 7079 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7080 | * defined in {@link ImsRegistrationImplBase}. |
| 7081 | */ |
| 7082 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7083 | final long identity = Binder.clearCallingIdentity(); |
| 7084 | try { |
| 7085 | Phone phone = getPhone(subId); |
| 7086 | if (phone != null) { |
| 7087 | return phone.getImsRegistrationTech(); |
| 7088 | } else { |
| 7089 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7090 | } |
| 7091 | } finally { |
| 7092 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7093 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7094 | } |
| 7095 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7096 | @Override |
| 7097 | public void factoryReset(int subId) { |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7098 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7099 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7100 | return; |
| 7101 | } |
| 7102 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7103 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7104 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7105 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7106 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7107 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7108 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7109 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7110 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7111 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7112 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 7113 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7114 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7115 | // There has been issues when Sms raw table somehow stores orphan |
| 7116 | // fragments. They lead to garbled message when new fragments come |
| 7117 | // in and combined with those stale ones. In case this happens again, |
| 7118 | // user can reset all network settings which will clean up this table. |
| 7119 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7120 | // Clean up IMS settings as well here. |
| 7121 | int slotId = getSlotIndex(subId); |
| 7122 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7123 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7124 | } |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7125 | |
| 7126 | // Erase modem config if erase modem on network setting is enabled. |
| 7127 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7128 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7129 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 7130 | sendEraseModemConfig(getDefaultPhone()); |
| 7131 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7132 | } finally { |
| 7133 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7134 | } |
| 7135 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7136 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7137 | private void cleanUpSmsRawTable(Context context) { |
| 7138 | ContentResolver resolver = context.getContentResolver(); |
| 7139 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7140 | resolver.delete(uri, null, null); |
| 7141 | } |
| 7142 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7143 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7144 | public String getSimLocaleForSubscriber(int subId) { |
| 7145 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7146 | final Phone phone = getPhone(subId); |
| 7147 | if (phone == null) { |
| 7148 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7149 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7150 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7151 | final long identity = Binder.clearCallingIdentity(); |
| 7152 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7153 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7154 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7155 | if (info == null) { |
| 7156 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7157 | return null; |
| 7158 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7159 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7160 | // preferences (EF-PL and EF-LI)... |
| 7161 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7162 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7163 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7164 | if (localeFromDefaultSim != null) { |
| 7165 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7166 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7167 | + localeFromDefaultSim); |
| 7168 | return localeFromDefaultSim.toLanguageTag(); |
| 7169 | } else { |
| 7170 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7171 | } |
| 7172 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7173 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7174 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7175 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7176 | // the SIM and carrier preferences does not include a country we add the country |
| 7177 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7178 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7179 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7180 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7181 | return mccLocale.toLanguageTag(); |
| 7182 | } |
| 7183 | |
| 7184 | if (DBG) log("No locale found - returning null"); |
| 7185 | return null; |
| 7186 | } finally { |
| 7187 | Binder.restoreCallingIdentity(identity); |
| 7188 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7189 | } |
| 7190 | |
| 7191 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7192 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7193 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7194 | } |
| 7195 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7196 | /** |
| 7197 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7198 | */ |
| 7199 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7200 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7201 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7202 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7203 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7204 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7205 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7206 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7207 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7208 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7209 | * representing the state of the modem. |
| 7210 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7211 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7212 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7213 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7214 | */ |
| 7215 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7216 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7217 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7218 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7219 | |
| 7220 | final long identity = Binder.clearCallingIdentity(); |
| 7221 | try { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 7222 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7223 | } finally { |
| 7224 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7225 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7226 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7227 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7228 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7229 | // less than total activity duration. |
| 7230 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7231 | if (info == null) { |
| 7232 | return false; |
| 7233 | } |
| 7234 | int activityDurationMs = |
| 7235 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 7236 | int totalTxTimeMs = 0; |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7237 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 7238 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 7239 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7240 | } |
| 7241 | return (info.isValid() |
| 7242 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7243 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7244 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7245 | && (totalTxTimeMs <= activityDurationMs)); |
| 7246 | } |
| 7247 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7248 | /** |
| 7249 | * {@hide} |
| 7250 | * Returns the service state information on specified subscription. |
| 7251 | */ |
| 7252 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7253 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7254 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7255 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7256 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7257 | return null; |
| 7258 | } |
| 7259 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7260 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7261 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7262 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7263 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7264 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7265 | .setCallingPid(Binder.getCallingPid()) |
| 7266 | .setCallingUid(Binder.getCallingUid()) |
| 7267 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7268 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7269 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7270 | .build()); |
| 7271 | |
| 7272 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7273 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7274 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7275 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7276 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7277 | .setCallingPid(Binder.getCallingPid()) |
| 7278 | .setCallingUid(Binder.getCallingUid()) |
| 7279 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7280 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7281 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7282 | .build()); |
| 7283 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7284 | boolean hasFinePermission = |
| 7285 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7286 | boolean hasCoarsePermission = |
| 7287 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7288 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7289 | final long identity = Binder.clearCallingIdentity(); |
| 7290 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7291 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7292 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7293 | Rlog.d(LOG_TAG, |
| 7294 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7295 | return null; |
| 7296 | } |
| 7297 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7298 | final Phone phone = getPhone(subId); |
| 7299 | if (phone == null) { |
| 7300 | return null; |
| 7301 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7302 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7303 | ServiceState ss = phone.getServiceState(); |
| 7304 | |
| 7305 | // Scrub out the location info in ServiceState depending on what level of access |
| 7306 | // the caller has. |
| 7307 | if (hasFinePermission) return ss; |
Malcolm Chen | db33797 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7308 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7309 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7310 | } finally { |
| 7311 | Binder.restoreCallingIdentity(identity); |
| 7312 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7313 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7314 | |
| 7315 | /** |
| 7316 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7317 | * |
| 7318 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7319 | * voicemail ringtone. |
| 7320 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7321 | * PhoneAccount. |
| 7322 | */ |
| 7323 | @Override |
| 7324 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7325 | final long identity = Binder.clearCallingIdentity(); |
| 7326 | try { |
| 7327 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7328 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7329 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7330 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7331 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7332 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7333 | } finally { |
| 7334 | Binder.restoreCallingIdentity(identity); |
| 7335 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7336 | } |
| 7337 | |
| 7338 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7339 | * Sets the per-account voicemail ringtone. |
| 7340 | * |
| 7341 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7342 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7343 | * |
| 7344 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7345 | * voicemail ringtone. |
| 7346 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7347 | * PhoneAccount. |
| 7348 | */ |
| 7349 | @Override |
| 7350 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7351 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7352 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7353 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7354 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7355 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7356 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7357 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7358 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7359 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7360 | |
| 7361 | final long identity = Binder.clearCallingIdentity(); |
| 7362 | try { |
| 7363 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7364 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7365 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7366 | } |
| 7367 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7368 | } finally { |
| 7369 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7370 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7371 | } |
| 7372 | |
| 7373 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7374 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7375 | * |
| 7376 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7377 | * voicemail vibration setting. |
| 7378 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7379 | */ |
| 7380 | @Override |
| 7381 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7382 | final long identity = Binder.clearCallingIdentity(); |
| 7383 | try { |
| 7384 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7385 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7386 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7387 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7388 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7389 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7390 | } finally { |
| 7391 | Binder.restoreCallingIdentity(identity); |
| 7392 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7393 | } |
| 7394 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7395 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7396 | * Sets the per-account voicemail vibration. |
| 7397 | * |
| 7398 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7399 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7400 | * |
| 7401 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7402 | * voicemail vibration setting. |
| 7403 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7404 | * specific PhoneAccount. |
| 7405 | */ |
| 7406 | @Override |
| 7407 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7408 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7409 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7410 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7411 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7412 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7413 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7414 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7415 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7416 | } |
| 7417 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7418 | final long identity = Binder.clearCallingIdentity(); |
| 7419 | try { |
| 7420 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7421 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7422 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7423 | } |
| 7424 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7425 | } finally { |
| 7426 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7427 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7428 | } |
| 7429 | |
| 7430 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7431 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 7432 | * |
| 7433 | * @throws SecurityException if the caller does not have the required permission |
| 7434 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7435 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7436 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7437 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7438 | } |
| 7439 | |
| 7440 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7441 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 7442 | * permission. |
| 7443 | * |
| 7444 | * @throws SecurityException if the caller does not have the required permission |
| 7445 | */ |
| 7446 | private void enforceSendSmsPermission() { |
| 7447 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 7448 | } |
| 7449 | |
| 7450 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7451 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7452 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7453 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7454 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7455 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7456 | final long identity = Binder.clearCallingIdentity(); |
| 7457 | try { |
| 7458 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7459 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7460 | if (componentName == null) { |
| 7461 | throw new SecurityException( |
| 7462 | "Caller not current active visual voicemail package[null]"); |
| 7463 | } |
| 7464 | String vvmPackage = componentName.getPackageName(); |
| 7465 | if (!callingPackage.equals(vvmPackage)) { |
| 7466 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 7467 | + vvmPackage + "]"); |
| 7468 | } |
| 7469 | } finally { |
| 7470 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7471 | } |
| 7472 | } |
| 7473 | |
| 7474 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7475 | * Return the application ID for the app type. |
| 7476 | * |
| 7477 | * @param subId the subscription ID that this request applies to. |
| 7478 | * @param appType the uicc app type. |
| 7479 | * @return Application ID for specificied app type, or null if no uicc. |
| 7480 | */ |
| 7481 | @Override |
| 7482 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7483 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7484 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7485 | |
| 7486 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7487 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7488 | if (phone == null) { |
| 7489 | return null; |
| 7490 | } |
| 7491 | String aid = null; |
| 7492 | try { |
| 7493 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 7494 | .getApplicationByType(appType).getAid(); |
| 7495 | } catch (Exception e) { |
| 7496 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 7497 | } |
| 7498 | return aid; |
| 7499 | } finally { |
| 7500 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7501 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7502 | } |
| 7503 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7504 | /** |
| 7505 | * Return the Electronic Serial Number. |
| 7506 | * |
| 7507 | * @param subId the subscription ID that this request applies to. |
| 7508 | * @return ESN or null if error. |
| 7509 | */ |
| 7510 | @Override |
| 7511 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7512 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7513 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7514 | |
| 7515 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7516 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7517 | if (phone == null) { |
| 7518 | return null; |
| 7519 | } |
| 7520 | String esn = null; |
| 7521 | try { |
| 7522 | esn = phone.getEsn(); |
| 7523 | } catch (Exception e) { |
| 7524 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 7525 | } |
| 7526 | return esn; |
| 7527 | } finally { |
| 7528 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7529 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7530 | } |
| 7531 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7532 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7533 | * Return the Preferred Roaming List Version. |
| 7534 | * |
| 7535 | * @param subId the subscription ID that this request applies to. |
| 7536 | * @return PRLVersion or null if error. |
| 7537 | */ |
| 7538 | @Override |
| 7539 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7540 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7541 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7542 | |
| 7543 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7544 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7545 | if (phone == null) { |
| 7546 | return null; |
| 7547 | } |
| 7548 | String cdmaPrlVersion = null; |
| 7549 | try { |
| 7550 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7551 | } catch (Exception e) { |
| 7552 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7553 | } |
| 7554 | return cdmaPrlVersion; |
| 7555 | } finally { |
| 7556 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7557 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7558 | } |
| 7559 | |
| 7560 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7561 | * Get snapshot of Telephony histograms |
| 7562 | * @return List of Telephony histograms |
| 7563 | * @hide |
| 7564 | */ |
| 7565 | @Override |
| 7566 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7567 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7568 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7569 | |
| 7570 | final long identity = Binder.clearCallingIdentity(); |
| 7571 | try { |
| 7572 | return RIL.getTelephonyRILTimingHistograms(); |
| 7573 | } finally { |
| 7574 | Binder.restoreCallingIdentity(identity); |
| 7575 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7576 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7577 | |
| 7578 | /** |
| 7579 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7580 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7581 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7582 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7583 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7584 | * @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] | 7585 | */ |
| 7586 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7587 | @TelephonyManager.SetCarrierRestrictionResult |
| 7588 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7589 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7590 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7591 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7592 | if (carrierRestrictionRules == null) { |
| 7593 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7594 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7595 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7596 | final long identity = Binder.clearCallingIdentity(); |
| 7597 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7598 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7599 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7600 | } finally { |
| 7601 | Binder.restoreCallingIdentity(identity); |
| 7602 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7603 | } |
| 7604 | |
| 7605 | /** |
| 7606 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7607 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7608 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7609 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7610 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7611 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7612 | */ |
| 7613 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7614 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7615 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7616 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7617 | |
| 7618 | final long identity = Binder.clearCallingIdentity(); |
| 7619 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7620 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7621 | if (response instanceof CarrierRestrictionRules) { |
| 7622 | return (CarrierRestrictionRules) response; |
| 7623 | } |
| 7624 | // Response is an Exception of some kind, |
| 7625 | // which is signalled to the user as a NULL retval |
| 7626 | return null; |
| 7627 | } catch (Exception e) { |
| 7628 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7629 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7630 | } finally { |
| 7631 | Binder.restoreCallingIdentity(identity); |
| 7632 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7633 | } |
| 7634 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7635 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7636 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7637 | * @param subId the subscription ID that this action applies to. |
| 7638 | * @param enabled control enable or disable radio. |
| 7639 | * {@hide} |
| 7640 | */ |
| 7641 | @Override |
| 7642 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7643 | enforceModifyPermission(); |
| 7644 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7645 | |
| 7646 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7647 | if (phone == null) { |
| 7648 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7649 | return; |
| 7650 | } |
| 7651 | try { |
| 7652 | phone.carrierActionSetRadioEnabled(enabled); |
| 7653 | } catch (Exception e) { |
| 7654 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7655 | } finally { |
| 7656 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7657 | } |
| 7658 | } |
| 7659 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7660 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7661 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7662 | * network status based on which carrier apps could apply actions accordingly, |
| 7663 | * enable/disable default url handler for example. |
| 7664 | * |
| 7665 | * @param subId the subscription ID that this action applies to. |
| 7666 | * @param report control start/stop reporting the default network status. |
| 7667 | * {@hide} |
| 7668 | */ |
| 7669 | @Override |
| 7670 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7671 | enforceModifyPermission(); |
| 7672 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7673 | |
| 7674 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7675 | if (phone == null) { |
| 7676 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7677 | return; |
| 7678 | } |
| 7679 | try { |
| 7680 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7681 | } catch (Exception e) { |
| 7682 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7683 | } finally { |
| 7684 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7685 | } |
| 7686 | } |
| 7687 | |
| 7688 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7689 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7690 | * @param subId the subscription ID that this action applies to. |
| 7691 | * {@hide} |
| 7692 | */ |
| 7693 | @Override |
| 7694 | public void carrierActionResetAll(int subId) { |
| 7695 | enforceModifyPermission(); |
| 7696 | final Phone phone = getPhone(subId); |
| 7697 | if (phone == null) { |
| 7698 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7699 | return; |
| 7700 | } |
| 7701 | try { |
| 7702 | phone.carrierActionResetAll(); |
| 7703 | } catch (Exception e) { |
| 7704 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7705 | } |
| 7706 | } |
| 7707 | |
| 7708 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7709 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7710 | * bug report is being generated. |
| 7711 | */ |
| 7712 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7713 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7714 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7715 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7716 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7717 | + Binder.getCallingPid() |
| 7718 | + ", uid=" + Binder.getCallingUid() |
| 7719 | + "without permission " |
| 7720 | + android.Manifest.permission.DUMP); |
| 7721 | return; |
| 7722 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7723 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7724 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7725 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7726 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 7727 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 7728 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 7729 | @NonNull String[] args) { |
| 7730 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 7731 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 7732 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7733 | } |
| 7734 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7735 | /** |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7736 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7737 | * @param subId Subscription index |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7738 | * @param reason the reason the data enable change is taking place |
| 7739 | * @param enabled True if enabling the data, otherwise disabling. |
| 7740 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7741 | */ |
| 7742 | @Override |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7743 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7744 | boolean enabled) { |
| 7745 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 7746 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7747 | try { |
| 7748 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7749 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7750 | } catch (SecurityException se) { |
| 7751 | enforceModifyPermission(); |
| 7752 | } |
| 7753 | } else { |
| 7754 | enforceModifyPermission(); |
| 7755 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7756 | |
| 7757 | final long identity = Binder.clearCallingIdentity(); |
| 7758 | try { |
| 7759 | Phone phone = getPhone(subId); |
| 7760 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7761 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7762 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7763 | } else { |
| 7764 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 7765 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7766 | } |
| 7767 | } finally { |
| 7768 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7769 | } |
| 7770 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7771 | |
| 7772 | /** |
| 7773 | * Get Client request stats |
| 7774 | * @return List of Client Request Stats |
| 7775 | * @hide |
| 7776 | */ |
| 7777 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7778 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7779 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7780 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7781 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7782 | return null; |
| 7783 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7784 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7785 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7786 | final long identity = Binder.clearCallingIdentity(); |
| 7787 | try { |
| 7788 | if (phone != null) { |
| 7789 | return phone.getClientRequestStats(); |
| 7790 | } |
| 7791 | |
| 7792 | return null; |
| 7793 | } finally { |
| 7794 | Binder.restoreCallingIdentity(identity); |
| 7795 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7796 | } |
| 7797 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7798 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7799 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7800 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7801 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7802 | |
| 7803 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7804 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7805 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7806 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7807 | * @param state State of SIM (power down, power up, pass through) |
| 7808 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7809 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7810 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7811 | * |
| 7812 | **/ |
| 7813 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7814 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7815 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7816 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7817 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7818 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7819 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7820 | final long identity = Binder.clearCallingIdentity(); |
| 7821 | try { |
| 7822 | if (phone != null) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7823 | phone.setSimPowerState(state, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7824 | } |
| 7825 | } finally { |
| 7826 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7827 | } |
| 7828 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7829 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7830 | private boolean isUssdApiAllowed(int subId) { |
| 7831 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7832 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7833 | if (configManager == null) { |
| 7834 | return false; |
| 7835 | } |
| 7836 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 7837 | if (pb == null) { |
| 7838 | return false; |
| 7839 | } |
| 7840 | return pb.getBoolean( |
| 7841 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 7842 | } |
| 7843 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7844 | /** |
| 7845 | * Check if phone is in emergency callback mode |
| 7846 | * @return true if phone is in emergency callback mode |
| 7847 | * @param subId sub id |
| 7848 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 7849 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7850 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7851 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7852 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7853 | |
| 7854 | final long identity = Binder.clearCallingIdentity(); |
| 7855 | try { |
| 7856 | if (phone != null) { |
| 7857 | return phone.isInEcm(); |
| 7858 | } else { |
| 7859 | return false; |
| 7860 | } |
| 7861 | } finally { |
| 7862 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7863 | } |
| 7864 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7865 | |
| 7866 | /** |
| 7867 | * Get the current signal strength information for the given subscription. |
| 7868 | * Because this information is not updated when the device is in a low power state |
| 7869 | * it should not be relied-upon to be current. |
| 7870 | * @param subId Subscription index |
| 7871 | * @return the most recent cached signal strength info from the modem |
| 7872 | */ |
| 7873 | @Override |
| 7874 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7875 | final long identity = Binder.clearCallingIdentity(); |
| 7876 | try { |
| 7877 | Phone p = getPhone(subId); |
| 7878 | if (p == null) { |
| 7879 | return null; |
| 7880 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7881 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7882 | return p.getSignalStrength(); |
| 7883 | } finally { |
| 7884 | Binder.restoreCallingIdentity(identity); |
| 7885 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 7886 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7887 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7888 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7889 | * Get the current modem radio state for the given slot. |
| 7890 | * @param slotIndex slot index. |
| 7891 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7892 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7893 | * @return the current radio power state from the modem |
| 7894 | */ |
| 7895 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7896 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7897 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7898 | if (phone != null) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7899 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 7900 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 7901 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7902 | } |
| 7903 | |
| 7904 | final long identity = Binder.clearCallingIdentity(); |
| 7905 | try { |
| 7906 | return phone.getRadioPowerState(); |
| 7907 | } finally { |
| 7908 | Binder.restoreCallingIdentity(identity); |
| 7909 | } |
| 7910 | } |
| 7911 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 7912 | } |
| 7913 | |
| 7914 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7915 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 7916 | * |
| 7917 | * <p>Requires one of the following permissions: |
| 7918 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 7919 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 7920 | * privileges. |
| 7921 | * |
| 7922 | * @param subId subscription id |
| 7923 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 7924 | * {@code false}. |
| 7925 | */ |
| 7926 | @Override |
| 7927 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 11263f3 | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 7928 | try { |
| 7929 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 7930 | null); |
| 7931 | } catch (Exception e) { |
| 7932 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 7933 | mApp, subId, "isDataRoamingEnabled"); |
| 7934 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7935 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7936 | boolean isEnabled = false; |
| 7937 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7938 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7939 | Phone phone = getPhone(subId); |
| 7940 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7941 | } finally { |
| 7942 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7943 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7944 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7945 | } |
| 7946 | |
| 7947 | |
| 7948 | /** |
| 7949 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 7950 | * |
| 7951 | * <p> Requires permission: |
| 7952 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 7953 | * privileges. |
| 7954 | * |
| 7955 | * @param subId subscription id |
| 7956 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 7957 | */ |
| 7958 | @Override |
| 7959 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7960 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7961 | mApp, subId, "setDataRoamingEnabled"); |
| 7962 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7963 | final long identity = Binder.clearCallingIdentity(); |
| 7964 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 7965 | Phone phone = getPhone(subId); |
| 7966 | if (phone != null) { |
| 7967 | phone.setDataRoamingEnabled(isEnabled); |
| 7968 | } |
| 7969 | } finally { |
| 7970 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 7971 | } |
| 7972 | } |
| 7973 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 7974 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7975 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 7976 | TelephonyPermissions |
| 7977 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 7978 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 7979 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7980 | boolean isAllowed = true; |
| 7981 | final long identity = Binder.clearCallingIdentity(); |
| 7982 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 7983 | Phone phone = getPhone(subId); |
| 7984 | if (phone != null) { |
| 7985 | isAllowed = phone.isCspPlmnEnabled(); |
| 7986 | } |
| 7987 | } finally { |
| 7988 | Binder.restoreCallingIdentity(identity); |
| 7989 | } |
| 7990 | return isAllowed; |
| 7991 | } |
| 7992 | |
| 7993 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 7994 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | cfdfe3a | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 7995 | // Verify that tha callingPackage belongs to the calling UID |
| 7996 | mApp.getSystemService(AppOpsManager.class) |
| 7997 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 7998 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 7999 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8000 | try { |
| 8001 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8002 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8003 | } catch (SecurityException e) { |
| 8004 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8005 | // has carrier privileges on an active UICC |
| 8006 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8007 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8008 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8009 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8010 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8011 | |
| 8012 | final long identity = Binder.clearCallingIdentity(); |
| 8013 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8014 | UiccController uiccController = UiccController.getInstance(); |
| 8015 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8016 | if (hasReadPermission) { |
| 8017 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8018 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8019 | |
| 8020 | // Remove private info if the caller doesn't have access |
| 8021 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8022 | for (UiccCardInfo cardInfo : cardInfos) { |
| 8023 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8024 | // is available |
| 8025 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 8026 | if (card == null || card.getUiccProfile() == null) { |
| 8027 | // assume no access if the card or profile is unavailable |
| 8028 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8029 | continue; |
| 8030 | } |
| 8031 | UiccProfile profile = card.getUiccProfile(); |
| 8032 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8033 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8034 | filteredInfos.add(cardInfo); |
| 8035 | } else { |
| 8036 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8037 | } |
| 8038 | } |
| 8039 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8040 | } finally { |
| 8041 | Binder.restoreCallingIdentity(identity); |
| 8042 | } |
| 8043 | } |
| 8044 | |
| 8045 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8046 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8047 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8048 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8049 | final long identity = Binder.clearCallingIdentity(); |
| 8050 | try { |
| 8051 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8052 | if (slots == null) { |
| 8053 | Rlog.i(LOG_TAG, "slots is null."); |
| 8054 | return null; |
| 8055 | } |
| 8056 | |
| 8057 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8058 | for (int i = 0; i < slots.length; i++) { |
| 8059 | UiccSlot slot = slots[i]; |
| 8060 | if (slot == null) { |
| 8061 | continue; |
| 8062 | } |
| 8063 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8064 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8065 | UiccCard card = slot.getUiccCard(); |
| 8066 | if (card != null) { |
| 8067 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8068 | } else { |
Jordan Liu | d96b529 | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8069 | cardId = slot.getEid(); |
| 8070 | if (TextUtils.isEmpty(cardId)) { |
| 8071 | cardId = slot.getIccId(); |
| 8072 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8073 | } |
| 8074 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8075 | if (cardId != null) { |
| 8076 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8077 | // if cardId is an EID, it's all digits so this is fine |
| 8078 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8079 | } |
| 8080 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8081 | int cardState = 0; |
| 8082 | switch (slot.getCardState()) { |
| 8083 | case CARDSTATE_ABSENT: |
| 8084 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8085 | break; |
| 8086 | case CARDSTATE_PRESENT: |
| 8087 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8088 | break; |
| 8089 | case CARDSTATE_ERROR: |
| 8090 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8091 | break; |
| 8092 | case CARDSTATE_RESTRICTED: |
| 8093 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8094 | break; |
| 8095 | default: |
| 8096 | break; |
| 8097 | |
| 8098 | } |
| 8099 | |
| 8100 | infos[i] = new UiccSlotInfo( |
| 8101 | slot.isActive(), |
| 8102 | slot.isEuicc(), |
| 8103 | cardId, |
| 8104 | cardState, |
| 8105 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8106 | slot.isExtendedApduSupported(), |
| 8107 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8108 | } |
| 8109 | return infos; |
| 8110 | } finally { |
| 8111 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8112 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8113 | } |
| 8114 | |
| 8115 | @Override |
| 8116 | public boolean switchSlots(int[] physicalSlots) { |
| 8117 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8118 | |
| 8119 | final long identity = Binder.clearCallingIdentity(); |
| 8120 | try { |
| 8121 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8122 | } finally { |
| 8123 | Binder.restoreCallingIdentity(identity); |
| 8124 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8125 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8126 | |
| 8127 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8128 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8129 | final long identity = Binder.clearCallingIdentity(); |
| 8130 | try { |
| 8131 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8132 | } finally { |
| 8133 | Binder.restoreCallingIdentity(identity); |
| 8134 | } |
| 8135 | } |
| 8136 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8137 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8138 | * A test API to reload the UICC profile. |
| 8139 | * |
| 8140 | * <p>Requires that the calling app has permission |
| 8141 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8142 | * @hide |
| 8143 | */ |
| 8144 | @Override |
| 8145 | public void refreshUiccProfile(int subId) { |
| 8146 | enforceModifyPermission(); |
| 8147 | |
| 8148 | final long identity = Binder.clearCallingIdentity(); |
| 8149 | try { |
| 8150 | Phone phone = getPhone(subId); |
| 8151 | if (phone == null) { |
| 8152 | return; |
| 8153 | } |
| 8154 | UiccCard uiccCard = phone.getUiccCard(); |
| 8155 | if (uiccCard == null) { |
| 8156 | return; |
| 8157 | } |
| 8158 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8159 | if (uiccProfile == null) { |
| 8160 | return; |
| 8161 | } |
| 8162 | uiccProfile.refresh(); |
| 8163 | } finally { |
| 8164 | Binder.restoreCallingIdentity(identity); |
| 8165 | } |
| 8166 | } |
| 8167 | |
| 8168 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8169 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8170 | */ |
| 8171 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8172 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8173 | } |
| 8174 | |
| 8175 | /** |
| 8176 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8177 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8178 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8179 | */ |
| 8180 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8181 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8182 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | faaa63d | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8183 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8184 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8185 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8186 | return isDataRoamingEnabled; |
| 8187 | } |
| 8188 | |
| 8189 | /** |
| 8190 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8191 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8192 | */ |
| 8193 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8194 | List<Integer> list = TelephonyProperties.default_network(); |
| 8195 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8196 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8197 | return list.get(phoneId); |
| 8198 | } |
| 8199 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8200 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8201 | |
| 8202 | @Override |
| 8203 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8204 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8205 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8206 | |
| 8207 | final long identity = Binder.clearCallingIdentity(); |
| 8208 | try { |
| 8209 | final Phone phone = getPhone(subId); |
| 8210 | if (phone == null) { |
| 8211 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8212 | return; |
| 8213 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8214 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8215 | carrierPrivilegeRules, apn); |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8216 | if (carrierPrivilegeRules == null) { |
| 8217 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8218 | } else { |
| 8219 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8220 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 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 | } |
| 8225 | |
| 8226 | @Override |
| 8227 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8228 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8229 | |
| 8230 | final long identity = Binder.clearCallingIdentity(); |
| 8231 | try { |
| 8232 | final Phone phone = getPhone(subId); |
| 8233 | if (phone == null) { |
| 8234 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 8235 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 8236 | } |
| 8237 | return phone.getCarrierIdListVersion(); |
| 8238 | } finally { |
| 8239 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8240 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8241 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8242 | |
| 8243 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8244 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 8245 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8246 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8247 | mApp, subId, callingPackage, callingFeatureId, |
| 8248 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8249 | return -1; |
| 8250 | } |
| 8251 | |
| 8252 | final long identity = Binder.clearCallingIdentity(); |
| 8253 | try { |
| 8254 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 8255 | } finally { |
| 8256 | Binder.restoreCallingIdentity(identity); |
| 8257 | } |
| 8258 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8259 | |
| 8260 | @Override |
| 8261 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 0723870 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 8262 | TelephonyPermissions |
| 8263 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8264 | mApp, subId, "getCdmaRoamingMode"); |
| 8265 | |
| 8266 | final long identity = Binder.clearCallingIdentity(); |
| 8267 | try { |
| 8268 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 8269 | } finally { |
| 8270 | Binder.restoreCallingIdentity(identity); |
| 8271 | } |
| 8272 | } |
| 8273 | |
| 8274 | @Override |
| 8275 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 8276 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8277 | mApp, subId, "setCdmaRoamingMode"); |
| 8278 | |
| 8279 | final long identity = Binder.clearCallingIdentity(); |
| 8280 | try { |
| 8281 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 8282 | } finally { |
| 8283 | Binder.restoreCallingIdentity(identity); |
| 8284 | } |
| 8285 | } |
| 8286 | |
| 8287 | @Override |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8288 | public int getCdmaSubscriptionMode(int subId) { |
| 8289 | TelephonyPermissions |
| 8290 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8291 | mApp, subId, "getCdmaSubscriptionMode"); |
| 8292 | |
| 8293 | final long identity = Binder.clearCallingIdentity(); |
| 8294 | try { |
| 8295 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 8296 | } finally { |
| 8297 | Binder.restoreCallingIdentity(identity); |
| 8298 | } |
| 8299 | } |
| 8300 | |
| 8301 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8302 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 8303 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8304 | mApp, subId, "setCdmaSubscriptionMode"); |
| 8305 | |
| 8306 | final long identity = Binder.clearCallingIdentity(); |
| 8307 | try { |
| 8308 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 8309 | } finally { |
| 8310 | Binder.restoreCallingIdentity(identity); |
| 8311 | } |
| 8312 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8313 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8314 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8315 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8316 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8317 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8318 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 8319 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8320 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8321 | } |
| 8322 | final long identity = Binder.clearCallingIdentity(); |
| 8323 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8324 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 8325 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8326 | if (phone.getEmergencyNumberTracker() != null |
| 8327 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 8328 | emergencyNumberListInternal.put( |
| 8329 | phone.getSubId(), |
| 8330 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 8331 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8332 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8333 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8334 | } finally { |
| 8335 | Binder.restoreCallingIdentity(identity); |
| 8336 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8337 | } |
| 8338 | |
| 8339 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8340 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8341 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8342 | if (!exactMatch) { |
| 8343 | TelephonyPermissions |
| 8344 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8345 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8346 | } |
| 8347 | final long identity = Binder.clearCallingIdentity(); |
| 8348 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8349 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8350 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8351 | && phone.getEmergencyNumberTracker() |
| 8352 | .isEmergencyNumber(number, exactMatch)) { |
| 8353 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8354 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8355 | } |
| 8356 | return false; |
| 8357 | } finally { |
| 8358 | Binder.restoreCallingIdentity(identity); |
| 8359 | } |
| 8360 | } |
| 8361 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8362 | /** |
| 8363 | * Update emergency number list for test mode. |
| 8364 | */ |
| 8365 | @Override |
| 8366 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 8367 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8368 | "updateEmergencyNumberListTestMode"); |
| 8369 | |
| 8370 | final long identity = Binder.clearCallingIdentity(); |
| 8371 | try { |
| 8372 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8373 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8374 | if (tracker != null) { |
| 8375 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 8376 | } |
| 8377 | } |
| 8378 | } finally { |
| 8379 | Binder.restoreCallingIdentity(identity); |
| 8380 | } |
| 8381 | } |
| 8382 | |
| 8383 | /** |
| 8384 | * Get the full emergency number list for test mode. |
| 8385 | */ |
| 8386 | @Override |
| 8387 | public List<String> getEmergencyNumberListTestMode() { |
| 8388 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8389 | "getEmergencyNumberListTestMode"); |
| 8390 | |
| 8391 | final long identity = Binder.clearCallingIdentity(); |
| 8392 | try { |
| 8393 | Set<String> emergencyNumbers = new HashSet<>(); |
| 8394 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8395 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8396 | if (tracker != null) { |
| 8397 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 8398 | emergencyNumbers.add(num.getNumber()); |
| 8399 | } |
| 8400 | } |
| 8401 | } |
| 8402 | return new ArrayList<>(emergencyNumbers); |
| 8403 | } finally { |
| 8404 | Binder.restoreCallingIdentity(identity); |
| 8405 | } |
| 8406 | } |
| 8407 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8408 | @Override |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8409 | public int getEmergencyNumberDbVersion(int subId) { |
| 8410 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 8411 | |
| 8412 | final long identity = Binder.clearCallingIdentity(); |
| 8413 | try { |
| 8414 | final Phone phone = getPhone(subId); |
| 8415 | if (phone == null) { |
| 8416 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 8417 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 8418 | } |
| 8419 | return phone.getEmergencyNumberDbVersion(); |
| 8420 | } finally { |
| 8421 | Binder.restoreCallingIdentity(identity); |
| 8422 | } |
| 8423 | } |
| 8424 | |
| 8425 | @Override |
| 8426 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 8427 | enforceModifyPermission(); |
| 8428 | |
| 8429 | final long identity = Binder.clearCallingIdentity(); |
| 8430 | try { |
| 8431 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8432 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8433 | if (tracker != null) { |
| 8434 | tracker.updateOtaEmergencyNumberDatabase(); |
| 8435 | } |
| 8436 | } |
| 8437 | } finally { |
| 8438 | Binder.restoreCallingIdentity(identity); |
| 8439 | } |
| 8440 | } |
| 8441 | |
| 8442 | @Override |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8443 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 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) { |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8451 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 8452 | } |
| 8453 | } |
| 8454 | } finally { |
| 8455 | Binder.restoreCallingIdentity(identity); |
| 8456 | } |
| 8457 | } |
| 8458 | |
| 8459 | @Override |
| 8460 | public void resetOtaEmergencyNumberDbFilePath() { |
| 8461 | enforceActiveEmergencySessionPermission(); |
| 8462 | |
| 8463 | final long identity = Binder.clearCallingIdentity(); |
| 8464 | try { |
| 8465 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8466 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8467 | if (tracker != null) { |
| 8468 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8469 | } |
| 8470 | } |
| 8471 | } finally { |
| 8472 | Binder.restoreCallingIdentity(identity); |
| 8473 | } |
| 8474 | } |
| 8475 | |
| 8476 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8477 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 8478 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 8479 | Phone phone = getPhone(subId); |
| 8480 | if (phone == null) { |
| 8481 | return null; |
| 8482 | } |
| 8483 | final long identity = Binder.clearCallingIdentity(); |
| 8484 | try { |
| 8485 | UiccProfile profile = UiccController.getInstance() |
| 8486 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 8487 | if (profile != null) { |
| 8488 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 8489 | } |
| 8490 | } finally { |
| 8491 | Binder.restoreCallingIdentity(identity); |
| 8492 | } |
| 8493 | return null; |
| 8494 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 8495 | |
| 8496 | /** |
| 8497 | * Enable or disable a modem stack. |
| 8498 | */ |
| 8499 | @Override |
| 8500 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 8501 | enforceModifyPermission(); |
| 8502 | |
| 8503 | final long identity = Binder.clearCallingIdentity(); |
| 8504 | try { |
| 8505 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8506 | if (phone == null) { |
| 8507 | return false; |
| 8508 | } else { |
| 8509 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 8510 | } |
| 8511 | } finally { |
| 8512 | Binder.restoreCallingIdentity(identity); |
| 8513 | } |
| 8514 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8515 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8516 | /** |
| 8517 | * Whether a modem stack is enabled or not. |
| 8518 | */ |
| 8519 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8520 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 8521 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8522 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8523 | if (phone == null) return false; |
| 8524 | |
| 8525 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8526 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 8527 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8528 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8529 | } |
| 8530 | |
| 8531 | final long identity = Binder.clearCallingIdentity(); |
| 8532 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8533 | try { |
| 8534 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 8535 | } catch (NoSuchElementException ex) { |
| 8536 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 8537 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8538 | } finally { |
| 8539 | Binder.restoreCallingIdentity(identity); |
| 8540 | } |
| 8541 | } |
| 8542 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8543 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8544 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8545 | enforceModifyPermission(); |
| 8546 | |
| 8547 | final long identity = Binder.clearCallingIdentity(); |
| 8548 | try { |
| 8549 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8550 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8551 | .commit(); |
| 8552 | } finally { |
| 8553 | Binder.restoreCallingIdentity(identity); |
| 8554 | } |
| 8555 | } |
| 8556 | |
| 8557 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8558 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8559 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8560 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8561 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8562 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8563 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8564 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8565 | |
| 8566 | final long identity = Binder.clearCallingIdentity(); |
| 8567 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8568 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8569 | } finally { |
| 8570 | Binder.restoreCallingIdentity(identity); |
| 8571 | } |
| 8572 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8573 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8574 | @TelephonyManager.IsMultiSimSupportedResult |
| 8575 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8576 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8577 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8578 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8579 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8580 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8581 | } |
| 8582 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8583 | // supported by the modem, indicate that it is restricted. |
| 8584 | PhoneCapability staticCapability = |
| 8585 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8586 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8587 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8588 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8589 | } |
Sarah Chin | 09f38ee | 2020-02-25 00:13:10 +0000 | [diff] [blame] | 8590 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8591 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8592 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8593 | } |
| 8594 | // Check if support of multiple SIMs is restricted by carrier |
| 8595 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8596 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8597 | } |
| 8598 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8599 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8600 | } |
| 8601 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8602 | /** |
| 8603 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8604 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8605 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8606 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8607 | * @param numOfSims number of active sims we want to switch to |
| 8608 | */ |
| 8609 | @Override |
| 8610 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8611 | if (numOfSims == 1) { |
| 8612 | enforceModifyPermission(); |
| 8613 | } else { |
| 8614 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8615 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8616 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8617 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8618 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8619 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8620 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8621 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8622 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8623 | return; |
| 8624 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8625 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8626 | } finally { |
| 8627 | Binder.restoreCallingIdentity(identity); |
| 8628 | } |
| 8629 | } |
| 8630 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8631 | @Override |
| 8632 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8633 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8634 | Phone phone = getPhone(subId); |
| 8635 | if (phone == null) { |
| 8636 | return false; |
| 8637 | } |
| 8638 | final long identity = Binder.clearCallingIdentity(); |
| 8639 | try { |
| 8640 | UiccCard uiccCard = phone.getUiccCard(); |
| 8641 | if (uiccCard == null) { |
| 8642 | return false; |
| 8643 | } |
| 8644 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8645 | if (uiccProfile == null) { |
| 8646 | return false; |
| 8647 | } |
| 8648 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8649 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8650 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8651 | } |
| 8652 | return false; |
| 8653 | } finally { |
| 8654 | Binder.restoreCallingIdentity(identity); |
| 8655 | } |
| 8656 | } |
| 8657 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8658 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8659 | * Get whether making changes to modem configurations will trigger reboot. |
| 8660 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8661 | */ |
| 8662 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8663 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8664 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8665 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8666 | mApp, subId, callingPackage, callingFeatureId, |
| 8667 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8668 | return false; |
| 8669 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8670 | final long identity = Binder.clearCallingIdentity(); |
| 8671 | try { |
| 8672 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8673 | } finally { |
| 8674 | Binder.restoreCallingIdentity(identity); |
| 8675 | } |
| 8676 | } |
| 8677 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8678 | private void updateModemStateMetrics() { |
| 8679 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8680 | // TODO: check the state for each modem if the api is ready. |
| 8681 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8682 | } |
| 8683 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8684 | @Override |
| 8685 | public int[] getSlotsMapping() { |
| 8686 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8687 | |
| 8688 | final long identity = Binder.clearCallingIdentity(); |
| 8689 | try { |
| 8690 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8691 | // All logical slots should have a mapping to a physical slot. |
| 8692 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8693 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8694 | for (int i = 0; i < slotInfos.length; i++) { |
| 8695 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8696 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8697 | } |
| 8698 | } |
| 8699 | return logicalSlotsMapping; |
| 8700 | } finally { |
| 8701 | Binder.restoreCallingIdentity(identity); |
| 8702 | } |
| 8703 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8704 | |
| 8705 | /** |
| 8706 | * Get the IRadio HAL Version |
| 8707 | */ |
| 8708 | @Override |
| 8709 | public int getRadioHalVersion() { |
| 8710 | Phone phone = getDefaultPhone(); |
| 8711 | if (phone == null) return -1; |
| 8712 | HalVersion hv = phone.getHalVersion(); |
| 8713 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8714 | return hv.major * 100 + hv.minor; |
| 8715 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8716 | |
| 8717 | /** |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8718 | * Get the current calling package name. |
| 8719 | * @return the current calling package name |
| 8720 | */ |
| 8721 | @Override |
| 8722 | public String getCurrentPackageName() { |
| 8723 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8724 | } |
| 8725 | |
| 8726 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8727 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8728 | * corresponding network requests on a subId. |
| 8729 | * |
| 8730 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8731 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8732 | * 2) APN is un-metered for this subscription, or |
| 8733 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | b48cf45 | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 8734 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8735 | * |
| 8736 | * @return whether data is allowed for a apn type. |
| 8737 | * |
| 8738 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8739 | */ |
| 8740 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8741 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | f250974 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8742 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8743 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 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 false; |
| 8750 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8751 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8752 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8753 | } finally { |
| 8754 | Binder.restoreCallingIdentity(identity); |
| 8755 | } |
| 8756 | } |
| 8757 | |
| 8758 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8759 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8760 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8761 | |
| 8762 | // Now that all security checks passes, perform the operation as ourselves. |
| 8763 | final long identity = Binder.clearCallingIdentity(); |
| 8764 | try { |
| 8765 | Phone phone = getPhone(subId); |
| 8766 | if (phone == null) return true; // By default return true. |
| 8767 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8768 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8769 | } finally { |
| 8770 | Binder.restoreCallingIdentity(identity); |
| 8771 | } |
| 8772 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8773 | |
| 8774 | @Override |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 8775 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 8776 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 8777 | enforceModifyPermission(); |
| 8778 | long token = Binder.clearCallingIdentity(); |
| 8779 | try { |
| 8780 | Phone phone = getPhone(subscriptionId); |
| 8781 | if (phone == null) { |
| 8782 | try { |
| 8783 | if (resultCallback != null) { |
| 8784 | resultCallback.accept(false); |
| 8785 | } |
| 8786 | } catch (RemoteException e) { |
| 8787 | // ignore |
| 8788 | } |
| 8789 | return; |
| 8790 | } |
| 8791 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 8792 | Pair.create(specifiers, (x) -> { |
| 8793 | try { |
| 8794 | if (resultCallback != null) { |
| 8795 | resultCallback.accept(x); |
| 8796 | } |
| 8797 | } catch (RemoteException e) { |
| 8798 | // ignore |
| 8799 | } |
| 8800 | }); |
| 8801 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 8802 | } finally { |
| 8803 | Binder.restoreCallingIdentity(token); |
| 8804 | } |
| 8805 | } |
| 8806 | |
| 8807 | @Override |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 8808 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 8809 | TelephonyPermissions |
| 8810 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8811 | mApp, subId, "getSystemSelectionChannels"); |
| 8812 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8813 | final long identity = Binder.clearCallingIdentity(); |
| 8814 | try { |
| 8815 | List<RadioAccessSpecifier> specifiers = |
| 8816 | (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, |
| 8817 | null, subId, workSource); |
| 8818 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 8819 | return specifiers; |
| 8820 | } finally { |
| 8821 | Binder.restoreCallingIdentity(identity); |
| 8822 | } |
| 8823 | } |
| 8824 | |
| 8825 | @Override |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8826 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 8827 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8828 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 8829 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 8830 | if (iccRecords == null) { |
| 8831 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 8832 | return false; |
| 8833 | } |
| 8834 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 8835 | } |
| 8836 | |
| 8837 | @Override |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8838 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 8839 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8840 | if (callingPackage == null) { |
| 8841 | callingPackage = getCurrentPackageName(); |
| 8842 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8843 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 8844 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8845 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 8846 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8847 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 8848 | } |
| 8849 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 8850 | Intent intent = new Intent(); |
| 8851 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 8852 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 8853 | // Bring up choose default SMS subscription dialog right now |
| 8854 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 8855 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 8856 | mApp.startActivity(intent); |
| 8857 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8858 | |
| 8859 | @Override |
| 8860 | public String getMmsUAProfUrl(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 carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 8865 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 8866 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 8867 | return carrierUAProfUrl; |
| 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_profile_url); |
| 8871 | } finally { |
| 8872 | Binder.restoreCallingIdentity(identity); |
| 8873 | } |
| 8874 | } |
| 8875 | |
| 8876 | @Override |
| 8877 | public String getMmsUserAgent(int subId) { |
| 8878 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 8879 | final long identity = Binder.clearCallingIdentity(); |
| 8880 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 8881 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 8882 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 8883 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 8884 | return carrierUserAgent; |
| 8885 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 8886 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 8887 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 8888 | } finally { |
| 8889 | Binder.restoreCallingIdentity(identity); |
| 8890 | } |
| 8891 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 8892 | |
| 8893 | @Override |
Hall Liu | c041a55 | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 8894 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 8895 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
| 8896 | |
| 8897 | final long identity = Binder.clearCallingIdentity(); |
| 8898 | try { |
| 8899 | Phone phone = getPhone(subscriptionId); |
| 8900 | if (phone == null) return false; |
| 8901 | |
| 8902 | switch (policy) { |
| 8903 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 8904 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 8905 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 8906 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 8907 | default: |
| 8908 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 8909 | } |
| 8910 | } finally { |
| 8911 | Binder.restoreCallingIdentity(identity); |
| 8912 | } |
| 8913 | } |
| 8914 | |
| 8915 | @Override |
| 8916 | public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy, |
| 8917 | boolean enabled) { |
| 8918 | enforceModifyPermission(); |
| 8919 | |
| 8920 | final long identity = Binder.clearCallingIdentity(); |
| 8921 | try { |
| 8922 | Phone phone = getPhone(subscriptionId); |
| 8923 | if (phone == null) return; |
| 8924 | |
| 8925 | switch (policy) { |
| 8926 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 8927 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 8928 | break; |
| 8929 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 8930 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 8931 | break; |
| 8932 | default: |
| 8933 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 8934 | } |
| 8935 | } finally { |
| 8936 | Binder.restoreCallingIdentity(identity); |
| 8937 | } |
| 8938 | } |
| 8939 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8940 | /** |
Hall Liu | b48cf45 | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 8941 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 8942 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 8943 | * otherwise. |
| 8944 | */ |
| 8945 | @Override |
| 8946 | public void setCepEnabled(boolean isCepEnabled) { |
| 8947 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 8948 | |
| 8949 | final long identity = Binder.clearCallingIdentity(); |
| 8950 | try { |
| 8951 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 8952 | for (Phone phone : PhoneFactory.getPhones()) { |
| 8953 | Phone defaultPhone = phone.getImsPhone(); |
| 8954 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 8955 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 8956 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 8957 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 8958 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 8959 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 8960 | + imsPhone.getMsisdn()); |
| 8961 | } |
| 8962 | } |
| 8963 | } finally { |
| 8964 | Binder.restoreCallingIdentity(identity); |
| 8965 | } |
| 8966 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 8967 | |
| 8968 | /** |
| 8969 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 8970 | * |
| 8971 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 8972 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 8973 | * before being read. |
| 8974 | */ |
| 8975 | @Override |
| 8976 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 8977 | isCompressed) { |
| 8978 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8979 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
| 8980 | try { |
| 8981 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 8982 | if (configBinder == null) { |
| 8983 | Rlog.e(LOG_TAG, "null result for getImsConfig"); |
| 8984 | } else { |
| 8985 | configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed); |
| 8986 | } |
| 8987 | } catch (RemoteException e) { |
| 8988 | Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage()); |
| 8989 | } |
| 8990 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 8991 | |
| 8992 | @Override |
| 8993 | public boolean isIccLockEnabled(int subId) { |
| 8994 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 8995 | |
| 8996 | // Now that all security checks passes, perform the operation as ourselves. |
| 8997 | final long identity = Binder.clearCallingIdentity(); |
| 8998 | try { |
| 8999 | Phone phone = getPhone(subId); |
| 9000 | if (phone != null && phone.getIccCard() != null) { |
| 9001 | return phone.getIccCard().getIccLockEnabled(); |
| 9002 | } else { |
| 9003 | return false; |
| 9004 | } |
| 9005 | } finally { |
| 9006 | Binder.restoreCallingIdentity(identity); |
| 9007 | } |
| 9008 | } |
| 9009 | |
| 9010 | /** |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9011 | * Set the ICC pin lock enabled or disabled. |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9012 | * |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9013 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9014 | * three cases: |
| 9015 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9016 | * successfully. |
| 9017 | * - Positive number and zero for remaining password attempts. |
| 9018 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9019 | * |
| 9020 | */ |
| 9021 | @Override |
| 9022 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9023 | enforceModifyPermission(); |
| 9024 | |
| 9025 | Phone phone = getPhone(subId); |
| 9026 | if (phone == null) { |
| 9027 | return 0; |
| 9028 | } |
| 9029 | // Now that all security checks passes, perform the operation as ourselves. |
| 9030 | final long identity = Binder.clearCallingIdentity(); |
| 9031 | try { |
| 9032 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9033 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9034 | return attemptsRemaining; |
| 9035 | |
| 9036 | } catch (Exception e) { |
| 9037 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9038 | } finally { |
| 9039 | Binder.restoreCallingIdentity(identity); |
| 9040 | } |
| 9041 | return 0; |
| 9042 | } |
| 9043 | |
| 9044 | /** |
| 9045 | * Change the ICC password used in ICC pin lock. |
| 9046 | * |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9047 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9048 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9049 | * - Positive number and zero for remaining password attempts. |
| 9050 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9051 | * |
| 9052 | */ |
| 9053 | @Override |
| 9054 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9055 | enforceModifyPermission(); |
| 9056 | |
| 9057 | Phone phone = getPhone(subId); |
| 9058 | if (phone == null) { |
| 9059 | return 0; |
| 9060 | } |
| 9061 | // Now that all security checks passes, perform the operation as ourselves. |
| 9062 | final long identity = Binder.clearCallingIdentity(); |
| 9063 | try { |
| 9064 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9065 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9066 | return attemptsRemaining; |
| 9067 | |
| 9068 | } catch (Exception e) { |
| 9069 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9070 | } finally { |
| 9071 | Binder.restoreCallingIdentity(identity); |
| 9072 | } |
| 9073 | return 0; |
| 9074 | } |
Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9075 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9076 | /** |
| 9077 | * Request for receiving user activity notification |
| 9078 | */ |
| 9079 | @Override |
| 9080 | public void requestUserActivityNotification() { |
| 9081 | if (!mNotifyUserActivity.get() |
| 9082 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9083 | mNotifyUserActivity.set(true); |
| 9084 | } |
| 9085 | } |
| 9086 | |
| 9087 | /** |
| 9088 | * Called when userActivity is signalled in the power manager. |
| 9089 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9090 | */ |
| 9091 | @Override |
| 9092 | public void userActivity() { |
| 9093 | // *************************************** |
| 9094 | // * Inherited from PhoneWindowManager * |
| 9095 | // *************************************** |
| 9096 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9097 | // WITH ITS LOCKS HELD. |
| 9098 | // |
| 9099 | // This code must be VERY careful about the locks |
| 9100 | // it acquires. |
| 9101 | // In fact, the current code acquires way too many, |
| 9102 | // and probably has lurking deadlocks. |
| 9103 | |
| 9104 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9105 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9106 | } |
| 9107 | |
| 9108 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9109 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9110 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9111 | } |
| 9112 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9113 | |
Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9114 | @Override |
| 9115 | public boolean canConnectTo5GInDsdsMode() { |
| 9116 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9117 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9118 | |
| 9119 | @Override |
| 9120 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 9121 | String callingFeatureId) { |
| 9122 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 9123 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 9124 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9125 | } |
| 9126 | |
| 9127 | Phone phone = getPhone(subId); |
| 9128 | if (phone == null) { |
| 9129 | throw new RuntimeException("phone is not available"); |
| 9130 | } |
| 9131 | // Now that all security checks passes, perform the operation as ourselves. |
| 9132 | final long identity = Binder.clearCallingIdentity(); |
| 9133 | try { |
| 9134 | return phone.getEquivalentHomePlmns(); |
| 9135 | } finally { |
| 9136 | Binder.restoreCallingIdentity(identity); |
| 9137 | } |
| 9138 | } |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9139 | |
| 9140 | /** |
| 9141 | * Attempts to set the radio power state for thermal reason. This does not guarantee that the |
| 9142 | * requested radio power state will actually be set. See {@link |
| 9143 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 9144 | * |
| 9145 | * @param subId the subscription ID of the phone requesting to set the radio power state. |
| 9146 | * @param enable {@code true} if trying to turn radio on. |
| 9147 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 9148 | * false}. |
| 9149 | */ |
| 9150 | private boolean setRadioPowerForThermal(int subId, boolean enable) { |
| 9151 | Phone phone = getPhone(subId); |
| 9152 | if (phone != null) { |
| 9153 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 9154 | return true; |
| 9155 | } |
| 9156 | return false; |
| 9157 | } |
| 9158 | |
| 9159 | private int handleDataThrottlingRequest(int subId, |
| 9160 | DataThrottlingRequest dataThrottlingRequest) { |
| 9161 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 9162 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9163 | if (!setRadioPowerForThermal(subId, true)) { |
| 9164 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9165 | } |
| 9166 | |
| 9167 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 9168 | |
| 9169 | int thermalMitigationResult = |
| 9170 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
| 9171 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 9172 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 9173 | } |
| 9174 | return thermalMitigationResult; |
| 9175 | } |
| 9176 | |
| 9177 | /** |
| 9178 | * Thermal mitigation request to control functionalities at modem. |
| 9179 | * |
| 9180 | * @param subId the id of the subscription. |
| 9181 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
| 9182 | * |
| 9183 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 9184 | */ |
| 9185 | @Override |
| 9186 | @ThermalMitigationResult |
| 9187 | public int sendThermalMitigationRequest( |
| 9188 | int subId, |
| 9189 | ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException { |
| 9190 | enforceModifyPermission(); |
| 9191 | |
| 9192 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9193 | final long identity = Binder.clearCallingIdentity(); |
| 9194 | |
| 9195 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 9196 | try { |
| 9197 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 9198 | switch (thermalMitigationAction) { |
| 9199 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 9200 | thermalMitigationResult = |
| 9201 | handleDataThrottlingRequest(subId, |
| 9202 | thermalMitigationRequest.getDataThrottlingRequest()); |
| 9203 | break; |
| 9204 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 9205 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9206 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 9207 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 9208 | } |
| 9209 | |
| 9210 | // Ensure that radio is on. If not able to power on due to phone being |
| 9211 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9212 | if (!setRadioPowerForThermal(subId, true)) { |
| 9213 | thermalMitigationResult = |
| 9214 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9215 | break; |
| 9216 | } |
| 9217 | |
| 9218 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 9219 | false); |
| 9220 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9221 | break; |
| 9222 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 9223 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9224 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 9225 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 9226 | } |
| 9227 | |
| 9228 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 9229 | if (registry != null) { |
| 9230 | TelephonyConnectionService service = |
| 9231 | registry.getTelephonyConnectionService(); |
| 9232 | Phone phone = getPhone(subId); |
| 9233 | if (phone == null) { |
| 9234 | thermalMitigationResult = |
| 9235 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9236 | break; |
| 9237 | } |
| 9238 | |
| 9239 | if (PhoneConstantConversions.convertCallState(phone.getState()) |
| 9240 | != TelephonyManager.CALL_STATE_IDLE |
| 9241 | || phone.isInEmergencySmsMode() || phone.isInEcm() |
| 9242 | || (service != null && service.isEmergencyCallPending())) { |
| 9243 | String errorMessage = "Phone state is not valid. call state = " |
| 9244 | + PhoneConstantConversions.convertCallState(phone.getState()) |
| 9245 | + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode() |
| 9246 | + " isInEmergencyCallbackMode = " + phone.isInEcm(); |
| 9247 | errorMessage += service == null |
| 9248 | ? " TelephonyConnectionService is null" |
| 9249 | : " isEmergencyCallPending = " |
| 9250 | + service.isEmergencyCallPending(); |
| 9251 | Log.e(LOG_TAG, errorMessage); |
| 9252 | thermalMitigationResult = |
| 9253 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 9254 | break; |
| 9255 | } |
| 9256 | } else { |
| 9257 | thermalMitigationResult = |
| 9258 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9259 | break; |
| 9260 | } |
| 9261 | |
| 9262 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 9263 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9264 | if (!setRadioPowerForThermal(subId, false)) { |
| 9265 | thermalMitigationResult = |
| 9266 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9267 | break; |
| 9268 | } |
| 9269 | thermalMitigationResult = |
| 9270 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9271 | break; |
| 9272 | default: |
| 9273 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 9274 | + "not exist. Requested action: " + thermalMitigationAction); |
| 9275 | } |
| 9276 | } catch (IllegalArgumentException e) { |
| 9277 | throw e; |
| 9278 | } catch (Exception e) { |
| 9279 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 9280 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 9281 | } finally { |
| 9282 | Binder.restoreCallingIdentity(identity); |
| 9283 | } |
| 9284 | |
| 9285 | if (DBG) { |
| 9286 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 9287 | + thermalMitigationResult); |
| 9288 | } |
| 9289 | |
| 9290 | return thermalMitigationResult; |
| 9291 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 9292 | } |