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; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -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; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -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 | cd19c46 | 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 | d63128d | 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 | 14bb3d0 | 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 | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 66 | import android.telephony.Annotation.ApnType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 67 | import android.telephony.Annotation.ThermalMitigationResult; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 68 | import android.telephony.CallForwardingInfo; |
Sooraj Sasindran | 4deb887 | 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 | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 72 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 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 | b0b8764 | 2020-11-12 15:04:39 -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; |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 90 | import android.telephony.RadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 91 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 92 | import android.telephony.SignalStrength; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 93 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 94 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 95 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 96 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 97 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 98 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 99 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 100 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 101 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 102 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 103 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 104 | import android.telephony.data.ApnSetting; |
| 105 | import android.telephony.emergency.EmergencyNumber; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 106 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 107 | import android.telephony.ims.ProvisioningManager; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 108 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 109 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 110 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 111 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 112 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 113 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 114 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 115 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 116 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 117 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 118 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 119 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 120 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 121 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 122 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 123 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 124 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 125 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 126 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 127 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 128 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 129 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 130 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 131 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 132 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 134 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 136 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 137 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 140 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 142 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 148 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 157 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 158 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 159 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 161 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 163 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 164 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 165 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 169 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 171 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 172 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 173 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 175 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 176 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 177 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 178 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 179 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 180 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 181 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 182 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 183 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 184 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 185 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 186 | import com.android.services.telephony.TelecomAccountRegistry; |
| 187 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 188 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 189 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 190 | import java.io.FileDescriptor; |
| 191 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 192 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 193 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 194 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 195 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 196 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 197 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 198 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 199 | import java.util.NoSuchElementException; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 200 | import java.util.Set; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 201 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 202 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 203 | |
| 204 | /** |
| 205 | * Implementation of the ITelephony interface. |
| 206 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 207 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 208 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 209 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 210 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 211 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 212 | |
| 213 | // Message codes used with mMainThreadHandler |
| 214 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 215 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 216 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 217 | private static final int CMD_OPEN_CHANNEL = 9; |
| 218 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 219 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 220 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 221 | private static final int CMD_NV_READ_ITEM = 13; |
| 222 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 223 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 224 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 225 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 226 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 227 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 228 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 229 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 230 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 231 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 232 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 233 | private static final int CMD_SEND_ENVELOPE = 25; |
| 234 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 235 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 236 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 237 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 238 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 239 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 240 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 241 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 242 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 243 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 244 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 245 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 246 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 247 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 248 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 249 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 250 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 251 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 252 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 253 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 254 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 255 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 256 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 257 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 258 | private static final int CMD_SWITCH_SLOTS = 50; |
| 259 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 260 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 261 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 262 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 263 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 264 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 265 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 266 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 267 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 268 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 269 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 270 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 271 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 272 | private static final int CMD_MODEM_REBOOT = 64; |
| 273 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 274 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 275 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 276 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 277 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 278 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 279 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 280 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 281 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 282 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 283 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 284 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 285 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 286 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 287 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 288 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 289 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 290 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 291 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 292 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 293 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 294 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 295 | private static final int CMD_GET_CALL_WAITING = 87; |
| 296 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 297 | private static final int CMD_SET_CALL_WAITING = 89; |
| 298 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 299 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 300 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 301 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 302 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 303 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 304 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 305 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 306 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 307 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 308 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 309 | private static final int CMD_SET_SIM_POWER = 101; |
| 310 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 311 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 312 | // Parameters of select command. |
| 313 | private static final int SELECT_COMMAND = 0xA4; |
| 314 | private static final int SELECT_P1 = 0x04; |
| 315 | private static final int SELECT_P2 = 0; |
| 316 | private static final int SELECT_P3 = 0x10; |
| 317 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 318 | /** The singleton instance. */ |
| 319 | private static PhoneInterfaceManager sInstance; |
| 320 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 321 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 322 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 323 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 324 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 325 | private AppOpsManager mAppOps; |
| 326 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 327 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 328 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 329 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 330 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 331 | /** User Activity */ |
| 332 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 333 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 334 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 335 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 336 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 337 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 338 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 339 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 340 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 341 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 342 | // String to store multi SIM allowed |
| 343 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 344 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 345 | // The AID of ISD-R. |
| 346 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 347 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 348 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 349 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 350 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 351 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 352 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 353 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
| 354 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 355 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 356 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 357 | */ |
| 358 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 359 | "reset_network_erase_modem_config_enabled"; |
| 360 | |
| 361 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 362 | * A request object to use for transmitting data to an ICC. |
| 363 | */ |
| 364 | private static final class IccAPDUArgument { |
| 365 | public int channel, cla, command, p1, p2, p3; |
| 366 | public String data; |
| 367 | |
| 368 | public IccAPDUArgument(int channel, int cla, int command, |
| 369 | int p1, int p2, int p3, String data) { |
| 370 | this.channel = channel; |
| 371 | this.cla = cla; |
| 372 | this.command = command; |
| 373 | this.p1 = p1; |
| 374 | this.p2 = p2; |
| 375 | this.p3 = p3; |
| 376 | this.data = data; |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 381 | * A request object to use for transmitting data to an ICC. |
| 382 | */ |
| 383 | private static final class ManualNetworkSelectionArgument { |
| 384 | public OperatorInfo operatorInfo; |
| 385 | public boolean persistSelection; |
| 386 | |
| 387 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 388 | this.operatorInfo = operatorInfo; |
| 389 | this.persistSelection = persistSelection; |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 394 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 395 | * request after sending. The main thread will notify the request when it is complete. |
| 396 | */ |
| 397 | private static final class MainThreadRequest { |
| 398 | /** The argument to use for the request */ |
| 399 | public Object argument; |
| 400 | /** The result of the request that is run on the main thread */ |
| 401 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 402 | // The subscriber id that this request applies to. Defaults to |
| 403 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 404 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 405 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 406 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 407 | public Phone phone; |
| 408 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 409 | public WorkSource workSource; |
| 410 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 411 | public MainThreadRequest(Object argument) { |
| 412 | this.argument = argument; |
| 413 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 414 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 415 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 416 | this.argument = argument; |
| 417 | if (phone != null) { |
| 418 | this.phone = phone; |
| 419 | } |
| 420 | this.workSource = workSource; |
| 421 | } |
| 422 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 423 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 424 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 425 | if (subId != null) { |
| 426 | this.subId = subId; |
| 427 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 428 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 429 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 430 | } |
| 431 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 432 | private static final class IncomingThirdPartyCallArgs { |
| 433 | public final ComponentName component; |
| 434 | public final String callId; |
| 435 | public final String callerDisplayName; |
| 436 | |
| 437 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 438 | String callerDisplayName) { |
| 439 | this.component = component; |
| 440 | this.callId = callId; |
| 441 | this.callerDisplayName = callerDisplayName; |
| 442 | } |
| 443 | } |
| 444 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 445 | /** |
| 446 | * A handler that processes messages on the main thread in the phone process. Since many |
| 447 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 448 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 449 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 450 | * on, which will be notified when the operation completes and will contain the result of the |
| 451 | * request. |
| 452 | * |
| 453 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 454 | * note that request.result must be set to something non-null for the calling thread to |
| 455 | * unblock. |
| 456 | */ |
| 457 | private final class MainThreadHandler extends Handler { |
| 458 | @Override |
| 459 | public void handleMessage(Message msg) { |
| 460 | MainThreadRequest request; |
| 461 | Message onCompleted; |
| 462 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 463 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 464 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 465 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 466 | |
| 467 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 468 | case CMD_HANDLE_USSD_REQUEST: { |
| 469 | request = (MainThreadRequest) msg.obj; |
| 470 | final Phone phone = getPhoneFromRequest(request); |
| 471 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 472 | String ussdRequest = ussdObject.first; |
| 473 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 474 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 475 | if (!isUssdApiAllowed(request.subId)) { |
| 476 | // Carrier does not support use of this API, return failure. |
| 477 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 478 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 479 | Bundle returnData = new Bundle(); |
| 480 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 481 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 482 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 483 | request.result = true; |
| 484 | notifyRequester(request); |
| 485 | return; |
| 486 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 487 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 488 | try { |
| 489 | request.result = phone != null |
| 490 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 491 | } catch (CallStateException cse) { |
| 492 | request.result = false; |
| 493 | } |
| 494 | // Wake up the requesting thread |
| 495 | notifyRequester(request); |
| 496 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 497 | } |
| 498 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 499 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 500 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 501 | final Phone phone = getPhoneFromRequest(request); |
| 502 | request.result = phone != null ? |
| 503 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 504 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 505 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 506 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 507 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 508 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 509 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 510 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 511 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 512 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 513 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 514 | if (uiccCard == null) { |
| 515 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 516 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 517 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 518 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 519 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 520 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 521 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 522 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 523 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 524 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 525 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 526 | break; |
| 527 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 528 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 529 | ar = (AsyncResult) msg.obj; |
| 530 | request = (MainThreadRequest) ar.userObj; |
| 531 | if (ar.exception == null && ar.result != null) { |
| 532 | request.result = ar.result; |
| 533 | } else { |
| 534 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 535 | if (ar.result == null) { |
| 536 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 537 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 538 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 539 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 540 | } else { |
| 541 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 542 | } |
| 543 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 544 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 545 | break; |
| 546 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 547 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 548 | request = (MainThreadRequest) msg.obj; |
| 549 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 550 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 551 | if (uiccCard == null) { |
| 552 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 553 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 554 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 555 | } else { |
| 556 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 557 | request); |
| 558 | uiccCard.iccTransmitApduBasicChannel( |
| 559 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 560 | iccArgument.p3, iccArgument.data, onCompleted); |
| 561 | } |
| 562 | break; |
| 563 | |
| 564 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 565 | ar = (AsyncResult) msg.obj; |
| 566 | request = (MainThreadRequest) ar.userObj; |
| 567 | if (ar.exception == null && ar.result != null) { |
| 568 | request.result = ar.result; |
| 569 | } else { |
| 570 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 571 | if (ar.result == null) { |
| 572 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 573 | } else if (ar.exception instanceof CommandException) { |
| 574 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 575 | ar.exception); |
| 576 | } else { |
| 577 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 578 | } |
| 579 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 580 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 581 | break; |
| 582 | |
| 583 | case CMD_EXCHANGE_SIM_IO: |
| 584 | request = (MainThreadRequest) msg.obj; |
| 585 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 586 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 587 | if (uiccCard == null) { |
| 588 | loge("iccExchangeSimIO: No UICC"); |
| 589 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 590 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 591 | } else { |
| 592 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 593 | request); |
| 594 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 595 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 596 | iccArgument.data, onCompleted); |
| 597 | } |
| 598 | break; |
| 599 | |
| 600 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 601 | ar = (AsyncResult) msg.obj; |
| 602 | request = (MainThreadRequest) ar.userObj; |
| 603 | if (ar.exception == null && ar.result != null) { |
| 604 | request.result = ar.result; |
| 605 | } else { |
| 606 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 607 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 608 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 609 | break; |
| 610 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 611 | case CMD_SEND_ENVELOPE: |
| 612 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 613 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 614 | if (uiccCard == null) { |
| 615 | loge("sendEnvelopeWithStatus: No UICC"); |
| 616 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 617 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 618 | } else { |
| 619 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 620 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 621 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 622 | break; |
| 623 | |
| 624 | case EVENT_SEND_ENVELOPE_DONE: |
| 625 | ar = (AsyncResult) msg.obj; |
| 626 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 627 | if (ar.exception == null && ar.result != null) { |
| 628 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 629 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 630 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 631 | if (ar.result == null) { |
| 632 | loge("sendEnvelopeWithStatus: Empty response"); |
| 633 | } else if (ar.exception instanceof CommandException) { |
| 634 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 635 | ar.exception); |
| 636 | } else { |
| 637 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 638 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 639 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 640 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 641 | break; |
| 642 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 643 | case CMD_OPEN_CHANNEL: |
| 644 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 645 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 646 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 647 | if (uiccCard == null) { |
| 648 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 649 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 650 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 651 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 652 | } else { |
| 653 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 654 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 655 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 656 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 657 | break; |
| 658 | |
| 659 | case EVENT_OPEN_CHANNEL_DONE: |
| 660 | ar = (AsyncResult) msg.obj; |
| 661 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 662 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 663 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 664 | int[] result = (int[]) ar.result; |
| 665 | int channelId = result[0]; |
| 666 | byte[] selectResponse = null; |
| 667 | if (result.length > 1) { |
| 668 | selectResponse = new byte[result.length - 1]; |
| 669 | for (int i = 1; i < result.length; ++i) { |
| 670 | selectResponse[i - 1] = (byte) result[i]; |
| 671 | } |
| 672 | } |
| 673 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 674 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 675 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 676 | if (ar.result == null) { |
| 677 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 678 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 679 | if (ar.exception != null) { |
| 680 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 681 | } |
| 682 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 683 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 684 | if (ar.exception instanceof CommandException) { |
| 685 | CommandException.Error error = |
| 686 | ((CommandException) (ar.exception)).getCommandError(); |
| 687 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 688 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 689 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 690 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 691 | } |
| 692 | } |
| 693 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 694 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 695 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 696 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 697 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 698 | break; |
| 699 | |
| 700 | case CMD_CLOSE_CHANNEL: |
| 701 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 702 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 703 | if (uiccCard == null) { |
| 704 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 705 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 706 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 707 | } else { |
| 708 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 709 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 710 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 711 | break; |
| 712 | |
| 713 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 714 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 715 | break; |
| 716 | |
| 717 | case CMD_NV_READ_ITEM: |
| 718 | request = (MainThreadRequest) msg.obj; |
| 719 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 720 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 721 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 722 | break; |
| 723 | |
| 724 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 725 | ar = (AsyncResult) msg.obj; |
| 726 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 727 | if (ar.exception == null && ar.result != null) { |
| 728 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 729 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 730 | request.result = ""; |
| 731 | if (ar.result == null) { |
| 732 | loge("nvReadItem: Empty response"); |
| 733 | } else if (ar.exception instanceof CommandException) { |
| 734 | loge("nvReadItem: CommandException: " + |
| 735 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 736 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 737 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 738 | } |
| 739 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 740 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 741 | break; |
| 742 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 743 | case CMD_NV_WRITE_ITEM: |
| 744 | request = (MainThreadRequest) msg.obj; |
| 745 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 746 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 747 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 748 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 749 | break; |
| 750 | |
| 751 | case EVENT_NV_WRITE_ITEM_DONE: |
| 752 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 753 | break; |
| 754 | |
| 755 | case CMD_NV_WRITE_CDMA_PRL: |
| 756 | request = (MainThreadRequest) msg.obj; |
| 757 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 758 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 759 | break; |
| 760 | |
| 761 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 762 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 763 | break; |
| 764 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 765 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 766 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 767 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 768 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 769 | break; |
| 770 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 771 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 772 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 773 | break; |
| 774 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 775 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 776 | request = (MainThreadRequest) msg.obj; |
| 777 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 778 | request); |
| 779 | Phone phone = getPhoneFromRequest(request); |
| 780 | if (phone != null) { |
| 781 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 782 | } else { |
| 783 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 784 | request.result = false; |
| 785 | notifyRequester(request); |
| 786 | } |
| 787 | break; |
| 788 | } |
| 789 | |
| 790 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 791 | ar = (AsyncResult) msg.obj; |
| 792 | request = (MainThreadRequest) ar.userObj; |
| 793 | if (ar.exception == null && ar.result != null) { |
| 794 | request.result = ar.result; |
| 795 | } else { |
| 796 | // request.result must be set to something non-null |
| 797 | // for the calling thread to unblock |
| 798 | if (request.result != null) { |
| 799 | request.result = ar.result; |
| 800 | } else { |
| 801 | request.result = false; |
| 802 | } |
| 803 | if (ar.result == null) { |
| 804 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 805 | } else if (ar.exception instanceof CommandException) { |
| 806 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 807 | + ar.exception); |
| 808 | } else { |
| 809 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 810 | } |
| 811 | } |
| 812 | notifyRequester(request); |
| 813 | break; |
| 814 | |
| 815 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 816 | request = (MainThreadRequest) msg.obj; |
| 817 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 818 | Phone phone = getPhoneFromRequest(request); |
| 819 | if (phone != null) { |
| 820 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 821 | request.workSource); |
| 822 | } else { |
| 823 | loge("enableNrDualConnectivity: No phone object"); |
| 824 | request.result = |
| 825 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 826 | notifyRequester(request); |
| 827 | } |
| 828 | break; |
| 829 | } |
| 830 | |
| 831 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 832 | ar = (AsyncResult) msg.obj; |
| 833 | request = (MainThreadRequest) ar.userObj; |
| 834 | if (ar.exception == null) { |
| 835 | request.result = |
| 836 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 837 | } else { |
| 838 | request.result = |
| 839 | TelephonyManager |
| 840 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 841 | if (ar.exception instanceof CommandException) { |
| 842 | CommandException.Error error = |
| 843 | ((CommandException) (ar.exception)).getCommandError(); |
| 844 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 845 | request.result = |
| 846 | TelephonyManager |
| 847 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 848 | } |
| 849 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 850 | + ar.exception); |
| 851 | } else { |
| 852 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 853 | } |
| 854 | } |
| 855 | notifyRequester(request); |
| 856 | break; |
| 857 | } |
| 858 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 859 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 860 | request = (MainThreadRequest) msg.obj; |
| 861 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 862 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 863 | break; |
| 864 | |
| 865 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 866 | ar = (AsyncResult) msg.obj; |
| 867 | request = (MainThreadRequest) ar.userObj; |
| 868 | if (ar.exception == null && ar.result != null) { |
| 869 | request.result = ar.result; // Integer |
| 870 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 871 | // request.result must be set to something non-null |
| 872 | // for the calling thread to unblock |
| 873 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 874 | if (ar.result == null) { |
| 875 | loge("getPreferredNetworkType: Empty response"); |
| 876 | } else if (ar.exception instanceof CommandException) { |
| 877 | loge("getPreferredNetworkType: CommandException: " + |
| 878 | ar.exception); |
| 879 | } else { |
| 880 | loge("getPreferredNetworkType: Unknown exception"); |
| 881 | } |
| 882 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 883 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 884 | break; |
| 885 | |
| 886 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 887 | request = (MainThreadRequest) msg.obj; |
| 888 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 889 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 890 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 891 | break; |
| 892 | |
| 893 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 894 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 895 | break; |
| 896 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 897 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 898 | request = (MainThreadRequest)msg.obj; |
| 899 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 900 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 901 | break; |
| 902 | |
| 903 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 904 | ar = (AsyncResult)msg.obj; |
| 905 | request = (MainThreadRequest)ar.userObj; |
| 906 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 907 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 908 | break; |
| 909 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 910 | case CMD_SET_VOICEMAIL_NUMBER: |
| 911 | request = (MainThreadRequest) msg.obj; |
| 912 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 913 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 914 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 915 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 916 | break; |
| 917 | |
| 918 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 919 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 920 | break; |
| 921 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 922 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 923 | request = (MainThreadRequest) msg.obj; |
| 924 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 925 | request); |
| 926 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 927 | break; |
| 928 | |
| 929 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 930 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 931 | break; |
| 932 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 933 | case CMD_PERFORM_NETWORK_SCAN: |
| 934 | request = (MainThreadRequest) msg.obj; |
| 935 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 936 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 937 | break; |
| 938 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 939 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 940 | request = (MainThreadRequest) msg.obj; |
| 941 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 942 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 943 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 944 | request.argument; |
| 945 | int callForwardingReason = args.first; |
| 946 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 947 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 948 | } |
| 949 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 950 | ar = (AsyncResult) msg.obj; |
| 951 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 952 | TelephonyManager.CallForwardingInfoCallback callback = |
| 953 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 954 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 955 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 956 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 957 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 958 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 959 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 960 | // any service for voice call. |
| 961 | if ((callForwardInfo.serviceClass |
| 962 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 963 | callForwardingInfo = new CallForwardingInfo(true, |
| 964 | callForwardInfo.reason, |
| 965 | callForwardInfo.number, |
| 966 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 967 | break; |
| 968 | } |
| 969 | } |
| 970 | // Didn't find a call forward info for voice call. |
| 971 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 972 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 973 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 974 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 975 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 976 | } else { |
| 977 | if (ar.result == null) { |
| 978 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 979 | } |
| 980 | if (ar.exception != null) { |
| 981 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 982 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 983 | int errorCode = TelephonyManager |
| 984 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 985 | if (ar.exception instanceof CommandException) { |
| 986 | CommandException.Error error = |
| 987 | ((CommandException) (ar.exception)).getCommandError(); |
| 988 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 989 | errorCode = TelephonyManager |
| 990 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 991 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 992 | errorCode = TelephonyManager |
| 993 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 994 | } |
| 995 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 996 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 997 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 998 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 999 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1000 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1001 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1002 | request = (MainThreadRequest) msg.obj; |
| 1003 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1004 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1005 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1006 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1007 | request.argument).first; |
| 1008 | request.phone.setCallForwardingOption( |
| 1009 | callForwardingInfoToSet.isEnabled() |
| 1010 | ? CommandsInterface.CF_ACTION_ENABLE |
| 1011 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1012 | callForwardingInfoToSet.getReason(), |
| 1013 | callForwardingInfoToSet.getNumber(), |
| 1014 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1015 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1016 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1017 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1018 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1019 | ar = (AsyncResult) msg.obj; |
| 1020 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1021 | Consumer<Integer> callback = |
| 1022 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1023 | request.argument).second; |
| 1024 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1025 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1026 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1027 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1028 | if (ar.exception instanceof CommandException) { |
| 1029 | CommandException.Error error = |
| 1030 | ((CommandException) (ar.exception)).getCommandError(); |
| 1031 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1032 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1033 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1034 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1035 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1036 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1037 | } |
| 1038 | } |
| 1039 | callback.accept(errorCode); |
| 1040 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1041 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1042 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1043 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1044 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1045 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1046 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1047 | request = (MainThreadRequest) msg.obj; |
| 1048 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1049 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1050 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1051 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1052 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1053 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1054 | ar = (AsyncResult) msg.obj; |
| 1055 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1056 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1057 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1058 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1059 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1060 | // Service Class is a bit mask per 3gpp 27.007. |
| 1061 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1062 | if (callForwardResults.length > 1 |
| 1063 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1064 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1065 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1066 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1067 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1068 | } else { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1069 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1070 | } |
| 1071 | } else { |
| 1072 | if (ar.result == null) { |
| 1073 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1074 | } |
| 1075 | if (ar.exception != null) { |
| 1076 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1077 | } |
| 1078 | if (ar.exception instanceof CommandException) { |
| 1079 | CommandException.Error error = |
| 1080 | ((CommandException) (ar.exception)).getCommandError(); |
| 1081 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1082 | callForwardingStatus = |
| 1083 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1084 | } |
| 1085 | } |
| 1086 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1087 | callback.accept(callForwardingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1088 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1089 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1090 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1091 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1092 | request = (MainThreadRequest) msg.obj; |
| 1093 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1094 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1095 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1096 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1097 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1098 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1099 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1100 | ar = (AsyncResult) msg.obj; |
| 1101 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1102 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1103 | Consumer<Integer> callback = |
| 1104 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1105 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1106 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1107 | if (ar.exception instanceof CommandException) { |
| 1108 | CommandException.Error error = |
| 1109 | ((CommandException) (ar.exception)).getCommandError(); |
| 1110 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1111 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1112 | } else { |
| 1113 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1114 | } |
| 1115 | } else { |
| 1116 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1117 | } |
| 1118 | } else { |
| 1119 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1120 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1121 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1122 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1123 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1124 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1125 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1126 | ar = (AsyncResult) msg.obj; |
| 1127 | request = (MainThreadRequest) ar.userObj; |
| 1128 | CellNetworkScanResult cellScanResult; |
| 1129 | if (ar.exception == null && ar.result != null) { |
| 1130 | cellScanResult = new CellNetworkScanResult( |
| 1131 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1132 | (List<OperatorInfo>) ar.result); |
| 1133 | } else { |
| 1134 | if (ar.result == null) { |
| 1135 | loge("getCellNetworkScanResults: Empty response"); |
| 1136 | } |
| 1137 | if (ar.exception != null) { |
| 1138 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1139 | } |
| 1140 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1141 | if (ar.exception instanceof CommandException) { |
| 1142 | CommandException.Error error = |
| 1143 | ((CommandException) (ar.exception)).getCommandError(); |
| 1144 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1145 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1146 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1147 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1148 | } |
| 1149 | } |
| 1150 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1151 | } |
| 1152 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1153 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1154 | break; |
| 1155 | |
| 1156 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1157 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1158 | ManualNetworkSelectionArgument selArg = |
| 1159 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1160 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1161 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1162 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1163 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1164 | break; |
| 1165 | |
| 1166 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1167 | ar = (AsyncResult) msg.obj; |
| 1168 | request = (MainThreadRequest) ar.userObj; |
| 1169 | if (ar.exception == null) { |
| 1170 | request.result = true; |
| 1171 | } else { |
| 1172 | request.result = false; |
| 1173 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1174 | } |
| 1175 | notifyRequester(request); |
| 1176 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1177 | break; |
| 1178 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1179 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1180 | request = (MainThreadRequest) msg.obj; |
| 1181 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1182 | if (defaultPhone != null) { |
| 1183 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1184 | } else { |
| 1185 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1186 | Bundle bundle = new Bundle(); |
| 1187 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1188 | new ModemActivityInfo(0, 0, 0, |
| 1189 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1190 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1191 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1192 | break; |
| 1193 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1194 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1195 | ar = (AsyncResult) msg.obj; |
| 1196 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1197 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1198 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1199 | ModemActivityInfo ret = null; |
| 1200 | int error = 0; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1201 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1202 | // Update the last modem activity info and the result of the request. |
| 1203 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1204 | if (isModemActivityInfoValid(info)) { |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1205 | int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()]; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1206 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1207 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1208 | .getTransmitTimeMillis(); |
| 1209 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1210 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1211 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1212 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1213 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1214 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1215 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1216 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1217 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1218 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1219 | info.getReceiveTimeMillis() |
| 1220 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1221 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1222 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(), |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1223 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1224 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1225 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1226 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1227 | } else { |
| 1228 | if (ar.result == null) { |
| 1229 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1230 | error = TelephonyManager.ModemActivityInfoException |
| 1231 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1232 | } else if (ar.exception instanceof CommandException) { |
| 1233 | loge("queryModemActivityInfo: CommandException: " + |
| 1234 | ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1235 | error = TelephonyManager.ModemActivityInfoException |
| 1236 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1237 | } else { |
| 1238 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1239 | error = TelephonyManager.ModemActivityInfoException |
| 1240 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1241 | } |
| 1242 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1243 | Bundle bundle = new Bundle(); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1244 | if (ret != null) { |
| 1245 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1246 | } else { |
| 1247 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1248 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1249 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1250 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1251 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1252 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1253 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1254 | case CMD_SET_ALLOWED_CARRIERS: |
| 1255 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1256 | CarrierRestrictionRules argument = |
| 1257 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1258 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1259 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1260 | break; |
| 1261 | |
| 1262 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1263 | ar = (AsyncResult) msg.obj; |
| 1264 | request = (MainThreadRequest) ar.userObj; |
| 1265 | if (ar.exception == null && ar.result != null) { |
| 1266 | request.result = ar.result; |
| 1267 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1268 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1269 | if (ar.exception instanceof CommandException) { |
| 1270 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1271 | CommandException.Error error = |
| 1272 | ((CommandException) (ar.exception)).getCommandError(); |
| 1273 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1274 | request.result = |
| 1275 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1276 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1277 | } else { |
| 1278 | loge("setAllowedCarriers: Unknown exception"); |
| 1279 | } |
| 1280 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1281 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1282 | break; |
| 1283 | |
| 1284 | case CMD_GET_ALLOWED_CARRIERS: |
| 1285 | request = (MainThreadRequest) msg.obj; |
| 1286 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1287 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1288 | break; |
| 1289 | |
| 1290 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1291 | ar = (AsyncResult) msg.obj; |
| 1292 | request = (MainThreadRequest) ar.userObj; |
| 1293 | if (ar.exception == null && ar.result != null) { |
| 1294 | request.result = ar.result; |
| 1295 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1296 | request.result = new IllegalStateException( |
| 1297 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1298 | if (ar.result == null) { |
| 1299 | loge("getAllowedCarriers: Empty response"); |
| 1300 | } else if (ar.exception instanceof CommandException) { |
| 1301 | loge("getAllowedCarriers: CommandException: " + |
| 1302 | ar.exception); |
| 1303 | } else { |
| 1304 | loge("getAllowedCarriers: Unknown exception"); |
| 1305 | } |
| 1306 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1307 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1308 | break; |
| 1309 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1310 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1311 | ar = (AsyncResult) msg.obj; |
| 1312 | request = (MainThreadRequest) ar.userObj; |
| 1313 | if (ar.exception == null && ar.result != null) { |
| 1314 | request.result = ar.result; |
| 1315 | } else { |
| 1316 | request.result = new IllegalArgumentException( |
| 1317 | "Failed to retrieve Forbidden Plmns"); |
| 1318 | if (ar.result == null) { |
| 1319 | loge("getForbiddenPlmns: Empty response"); |
| 1320 | } else { |
| 1321 | loge("getForbiddenPlmns: Unknown exception"); |
| 1322 | } |
| 1323 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1324 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1325 | break; |
| 1326 | |
| 1327 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1328 | request = (MainThreadRequest) msg.obj; |
| 1329 | uiccCard = getUiccCardFromRequest(request); |
| 1330 | if (uiccCard == null) { |
| 1331 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1332 | request.result = new IllegalArgumentException( |
| 1333 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1334 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1335 | break; |
| 1336 | } |
| 1337 | Integer appType = (Integer) request.argument; |
| 1338 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1339 | if (uiccApp == null) { |
| 1340 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1341 | + appType); |
| 1342 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1343 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1344 | break; |
| 1345 | } else { |
| 1346 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1347 | + " specified type -- " + appType); |
| 1348 | } |
| 1349 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1350 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1351 | onCompleted); |
| 1352 | break; |
| 1353 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1354 | case CMD_SWITCH_SLOTS: |
| 1355 | request = (MainThreadRequest) msg.obj; |
| 1356 | int[] physicalSlots = (int[]) request.argument; |
| 1357 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1358 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1359 | break; |
| 1360 | |
| 1361 | case EVENT_SWITCH_SLOTS_DONE: |
| 1362 | ar = (AsyncResult) msg.obj; |
| 1363 | request = (MainThreadRequest) ar.userObj; |
| 1364 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1365 | notifyRequester(request); |
| 1366 | break; |
| 1367 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1368 | request = (MainThreadRequest) msg.obj; |
| 1369 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1370 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1371 | break; |
| 1372 | |
| 1373 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1374 | ar = (AsyncResult) msg.obj; |
| 1375 | request = (MainThreadRequest) ar.userObj; |
| 1376 | if (ar.exception != null) { |
| 1377 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1378 | } else { |
| 1379 | int mode = ((int[]) ar.result)[0]; |
| 1380 | if (mode == 0) { |
| 1381 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1382 | } else { |
| 1383 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1384 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1385 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1386 | notifyRequester(request); |
| 1387 | break; |
| 1388 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1389 | request = (MainThreadRequest) msg.obj; |
| 1390 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1391 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1392 | break; |
| 1393 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1394 | ar = (AsyncResult) msg.obj; |
| 1395 | request = (MainThreadRequest) ar.userObj; |
| 1396 | if (ar.exception != null) { |
| 1397 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1398 | } else { |
| 1399 | request.result = ((int[]) ar.result)[0]; |
| 1400 | } |
| 1401 | notifyRequester(request); |
| 1402 | break; |
| 1403 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1404 | request = (MainThreadRequest) msg.obj; |
| 1405 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1406 | int mode = (int) request.argument; |
| 1407 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1408 | break; |
| 1409 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1410 | ar = (AsyncResult) msg.obj; |
| 1411 | request = (MainThreadRequest) ar.userObj; |
| 1412 | request.result = ar.exception == null; |
| 1413 | notifyRequester(request); |
| 1414 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1415 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1416 | request = (MainThreadRequest) msg.obj; |
| 1417 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1418 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1419 | break; |
| 1420 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1421 | ar = (AsyncResult) msg.obj; |
| 1422 | request = (MainThreadRequest) ar.userObj; |
| 1423 | if (ar.exception != null) { |
| 1424 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1425 | } else { |
| 1426 | request.result = ((int[]) ar.result)[0]; |
| 1427 | } |
| 1428 | notifyRequester(request); |
| 1429 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1430 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1431 | request = (MainThreadRequest) msg.obj; |
| 1432 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1433 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1434 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1435 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1436 | break; |
| 1437 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1438 | ar = (AsyncResult) msg.obj; |
| 1439 | request = (MainThreadRequest) ar.userObj; |
| 1440 | request.result = ar.exception == null; |
| 1441 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1442 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1443 | case CMD_GET_ALL_CELL_INFO: |
| 1444 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1445 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1446 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1447 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1448 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1449 | ar = (AsyncResult) msg.obj; |
| 1450 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1451 | // If a timeout occurs, the response will be null |
| 1452 | request.result = (ar.exception == null && ar.result != null) |
| 1453 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1454 | synchronized (request) { |
| 1455 | request.notifyAll(); |
| 1456 | } |
| 1457 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1458 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1459 | request = (MainThreadRequest) msg.obj; |
| 1460 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1461 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1462 | break; |
| 1463 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1464 | ar = (AsyncResult) msg.obj; |
| 1465 | request = (MainThreadRequest) ar.userObj; |
| 1466 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1467 | try { |
| 1468 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1469 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1470 | cb.onError( |
| 1471 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1472 | ar.exception.getClass().getName(), |
| 1473 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1474 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1475 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1476 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1477 | } else { |
| 1478 | // use the result as returned |
| 1479 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1480 | } |
| 1481 | } catch (RemoteException re) { |
| 1482 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1483 | } |
| 1484 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1485 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1486 | request = (MainThreadRequest) msg.obj; |
| 1487 | WorkSource ws = (WorkSource) request.argument; |
| 1488 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1489 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1490 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1491 | } |
| 1492 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1493 | ar = (AsyncResult) msg.obj; |
| 1494 | request = (MainThreadRequest) ar.userObj; |
| 1495 | if (ar.exception == null) { |
| 1496 | request.result = ar.result; |
| 1497 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1498 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1499 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1500 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1501 | } |
| 1502 | |
| 1503 | synchronized (request) { |
| 1504 | request.notifyAll(); |
| 1505 | } |
| 1506 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1507 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1508 | case CMD_MODEM_REBOOT: |
| 1509 | request = (MainThreadRequest) msg.obj; |
| 1510 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1511 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1512 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1513 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1514 | handleNullReturnEvent(msg, "rebootModem"); |
| 1515 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1516 | case CMD_REQUEST_ENABLE_MODEM: |
| 1517 | request = (MainThreadRequest) msg.obj; |
| 1518 | boolean enable = (boolean) request.argument; |
| 1519 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1520 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1521 | PhoneConfigurationManager.getInstance() |
| 1522 | .enablePhone(request.phone, enable, onCompleted); |
| 1523 | break; |
| 1524 | case EVENT_ENABLE_MODEM_DONE: |
| 1525 | ar = (AsyncResult) msg.obj; |
| 1526 | request = (MainThreadRequest) ar.userObj; |
| 1527 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1528 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1529 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1530 | if ((boolean) request.result) { |
| 1531 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1532 | updateModemStateMetrics(); |
| 1533 | } else { |
| 1534 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1535 | + ar.exception); |
| 1536 | } |
| 1537 | notifyRequester(request); |
| 1538 | break; |
| 1539 | case CMD_GET_MODEM_STATUS: |
| 1540 | request = (MainThreadRequest) msg.obj; |
| 1541 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1542 | PhoneConfigurationManager.getInstance() |
| 1543 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1544 | break; |
| 1545 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1546 | ar = (AsyncResult) msg.obj; |
| 1547 | request = (MainThreadRequest) ar.userObj; |
| 1548 | int id = request.phone.getPhoneId(); |
| 1549 | if (ar.exception == null && ar.result != null) { |
| 1550 | request.result = ar.result; |
| 1551 | //update the cache as modem status has changed |
| 1552 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1553 | (boolean) request.result); |
| 1554 | } else { |
| 1555 | // Return true if modem status cannot be retrieved. For most cases, |
| 1556 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1557 | // and disable modem are not supported. Modem is always on. |
| 1558 | // TODO: this should be fixed in R to support a third |
| 1559 | // status UNKNOWN b/131631629 |
| 1560 | request.result = true; |
| 1561 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1562 | + ar.exception); |
| 1563 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1564 | notifyRequester(request); |
| 1565 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1566 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1567 | request = (MainThreadRequest) msg.obj; |
| 1568 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1569 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1570 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1571 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1572 | break; |
| 1573 | } |
| 1574 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1575 | ar = (AsyncResult) msg.obj; |
| 1576 | request = (MainThreadRequest) ar.userObj; |
| 1577 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1578 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1579 | args.second.accept(ar.exception == null); |
| 1580 | notifyRequester(request); |
| 1581 | break; |
| 1582 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1583 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1584 | request = (MainThreadRequest) msg.obj; |
| 1585 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1586 | Phone phone = getPhoneFromRequest(request); |
| 1587 | if (phone != null) { |
| 1588 | phone.getSystemSelectionChannels(onCompleted); |
| 1589 | } else { |
| 1590 | loge("getSystemSelectionChannels: No phone object"); |
| 1591 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1592 | notifyRequester(request); |
| 1593 | } |
| 1594 | break; |
| 1595 | } |
| 1596 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_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 = new IllegalArgumentException( |
| 1603 | "Failed to retrieve system selection channels"); |
| 1604 | if (ar.result == null) { |
| 1605 | loge("getSystemSelectionChannels: Empty response"); |
| 1606 | } else { |
| 1607 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1608 | } |
| 1609 | } |
| 1610 | notifyRequester(request); |
| 1611 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1612 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1613 | ar = (AsyncResult) msg.obj; |
| 1614 | request = (MainThreadRequest) ar.userObj; |
| 1615 | if (ar.exception == null && ar.result != null) { |
| 1616 | request.result = ar.result; |
| 1617 | } else { |
| 1618 | request.result = -1; |
| 1619 | loge("Failed to set Forbidden Plmns"); |
| 1620 | if (ar.result == null) { |
| 1621 | loge("setForbidenPlmns: Empty response"); |
| 1622 | } else if (ar.exception != null) { |
| 1623 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1624 | request.result = -1; |
| 1625 | } else { |
| 1626 | loge("setForbiddenPlmns: Unknown exception"); |
| 1627 | } |
| 1628 | } |
| 1629 | notifyRequester(request); |
| 1630 | break; |
| 1631 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1632 | request = (MainThreadRequest) msg.obj; |
| 1633 | uiccCard = getUiccCardFromRequest(request); |
| 1634 | if (uiccCard == null) { |
| 1635 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1636 | request.result = -1; |
| 1637 | notifyRequester(request); |
| 1638 | break; |
| 1639 | } |
| 1640 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1641 | (Pair<Integer, List<String>>) request.argument; |
| 1642 | appType = setFplmnsArgs.first; |
| 1643 | List<String> fplmns = setFplmnsArgs.second; |
| 1644 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1645 | if (uiccApp == null) { |
| 1646 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1647 | request.result = -1; |
| 1648 | loge("Failed to get UICC App"); |
| 1649 | notifyRequester(request); |
| 1650 | } else { |
| 1651 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1652 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1653 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1654 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1655 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1656 | case CMD_ERASE_MODEM_CONFIG: |
| 1657 | request = (MainThreadRequest) msg.obj; |
| 1658 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1659 | defaultPhone.eraseModemConfig(onCompleted); |
| 1660 | break; |
| 1661 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1662 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1663 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1664 | |
| 1665 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1666 | request = (MainThreadRequest) msg.obj; |
| 1667 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1668 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1669 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1670 | changed.first, changed.second, onCompleted); |
| 1671 | break; |
| 1672 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1673 | ar = (AsyncResult) msg.obj; |
| 1674 | request = (MainThreadRequest) ar.userObj; |
| 1675 | if (ar.exception == null) { |
| 1676 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1677 | } else { |
| 1678 | request.result = msg.arg1; |
| 1679 | } |
| 1680 | notifyRequester(request); |
| 1681 | break; |
| 1682 | |
| 1683 | case CMD_SET_ICC_LOCK_ENABLED: |
| 1684 | request = (MainThreadRequest) msg.obj; |
| 1685 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1686 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1687 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1688 | enabled.first, enabled.second, onCompleted); |
| 1689 | break; |
| 1690 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1691 | ar = (AsyncResult) msg.obj; |
| 1692 | request = (MainThreadRequest) ar.userObj; |
| 1693 | if (ar.exception == null) { |
| 1694 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1695 | } else { |
| 1696 | request.result = msg.arg1; |
| 1697 | } |
| 1698 | notifyRequester(request); |
| 1699 | break; |
| 1700 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1701 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1702 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1703 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1704 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1705 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1706 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1707 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1708 | |
| 1709 | case CMD_SET_DATA_THROTTLING: { |
| 1710 | request = (MainThreadRequest) msg.obj; |
| 1711 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1712 | DataThrottlingRequest dataThrottlingRequest = |
| 1713 | (DataThrottlingRequest) request.argument; |
| 1714 | Phone phone = getPhoneFromRequest(request); |
| 1715 | if (phone != null) { |
| 1716 | phone.setDataThrottling(onCompleted, |
| 1717 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1718 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1719 | } else { |
| 1720 | loge("setDataThrottling: No phone object"); |
| 1721 | request.result = |
| 1722 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1723 | notifyRequester(request); |
| 1724 | } |
| 1725 | |
| 1726 | break; |
| 1727 | } |
| 1728 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1729 | ar = (AsyncResult) msg.obj; |
| 1730 | request = (MainThreadRequest) ar.userObj; |
| 1731 | |
| 1732 | if (ar.exception == null) { |
| 1733 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1734 | } else if (ar.exception instanceof CommandException) { |
| 1735 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1736 | CommandException.Error error = |
| 1737 | ((CommandException) (ar.exception)).getCommandError(); |
| 1738 | |
| 1739 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1740 | request.result = TelephonyManager |
| 1741 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1742 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1743 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
| 1744 | } else { |
| 1745 | request.result = |
| 1746 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1747 | } |
| 1748 | } else { |
| 1749 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1750 | } |
| 1751 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1752 | notifyRequester(request); |
| 1753 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1754 | |
| 1755 | case CMD_SET_SIM_POWER: { |
| 1756 | request = (MainThreadRequest) msg.obj; |
| 1757 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1758 | request = (MainThreadRequest) msg.obj; |
| 1759 | int stateToSet = |
| 1760 | ((Pair<Integer, IIntegerConsumer>) |
| 1761 | request.argument).first; |
| 1762 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1763 | break; |
| 1764 | } |
| 1765 | case EVENT_SET_SIM_POWER_DONE: { |
| 1766 | ar = (AsyncResult) msg.obj; |
| 1767 | request = (MainThreadRequest) ar.userObj; |
| 1768 | IIntegerConsumer callback = |
| 1769 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 1770 | if (ar.exception != null) { |
| 1771 | loge("setSimPower exception: " + ar.exception); |
| 1772 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1773 | .RESULT_ERROR_UNKNOWN; |
| 1774 | if (ar.exception instanceof CommandException) { |
| 1775 | CommandException.Error error = |
| 1776 | ((CommandException) (ar.exception)).getCommandError(); |
| 1777 | if (error == CommandException.Error.SIM_ERR) { |
| 1778 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 1779 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1780 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 1781 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1782 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 1783 | } else { |
| 1784 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 1785 | } |
| 1786 | } |
| 1787 | try { |
| 1788 | callback.accept(errorCode); |
| 1789 | } catch (RemoteException e) { |
| 1790 | // Ignore if the remote process is no longer available to call back. |
| 1791 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1792 | } |
| 1793 | } else { |
| 1794 | try { |
| 1795 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 1796 | } catch (RemoteException e) { |
| 1797 | // Ignore if the remote process is no longer available to call back. |
| 1798 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1799 | } |
| 1800 | } |
| 1801 | break; |
| 1802 | } |
| 1803 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1804 | default: |
| 1805 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1806 | break; |
| 1807 | } |
| 1808 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1809 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1810 | private void notifyRequester(MainThreadRequest request) { |
| 1811 | synchronized (request) { |
| 1812 | request.notifyAll(); |
| 1813 | } |
| 1814 | } |
| 1815 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1816 | private void handleNullReturnEvent(Message msg, String command) { |
| 1817 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1818 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1819 | if (ar.exception == null) { |
| 1820 | request.result = true; |
| 1821 | } else { |
| 1822 | request.result = false; |
| 1823 | if (ar.exception instanceof CommandException) { |
| 1824 | loge(command + ": CommandException: " + ar.exception); |
| 1825 | } else { |
| 1826 | loge(command + ": Unknown exception"); |
| 1827 | } |
| 1828 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1829 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1830 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1831 | } |
| 1832 | |
| 1833 | /** |
| 1834 | * Posts the specified command to be executed on the main thread, |
| 1835 | * waits for the request to complete, and returns the result. |
| 1836 | * @see #sendRequestAsync |
| 1837 | */ |
| 1838 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1839 | return sendRequest( |
| 1840 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1841 | } |
| 1842 | |
| 1843 | /** |
| 1844 | * Posts the specified command to be executed on the main thread, |
| 1845 | * waits for the request to complete, and returns the result. |
| 1846 | * @see #sendRequestAsync |
| 1847 | */ |
| 1848 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1849 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1850 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1851 | } |
| 1852 | |
| 1853 | /** |
| 1854 | * Posts the specified command to be executed on the main thread, |
| 1855 | * waits for the request to complete, and returns the result. |
| 1856 | * @see #sendRequestAsync |
| 1857 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1858 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1859 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1860 | } |
| 1861 | |
| 1862 | /** |
| 1863 | * Posts the specified command to be executed on the main thread, |
| 1864 | * waits for the request to complete, and returns the result. |
| 1865 | * @see #sendRequestAsync |
| 1866 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1867 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1868 | return sendRequest(command, argument, subId, null, workSource); |
| 1869 | } |
| 1870 | |
| 1871 | /** |
| 1872 | * Posts the specified command to be executed on the main thread, |
| 1873 | * waits for the request to complete, and returns the result. |
| 1874 | * @see #sendRequestAsync |
| 1875 | */ |
| 1876 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1877 | return sendRequest( |
| 1878 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1879 | } |
| 1880 | |
| 1881 | /** |
| 1882 | * Posts the specified command to be executed on the main thread, |
| 1883 | * waits for the request to complete, and returns the result. |
| 1884 | * @see #sendRequestAsync |
| 1885 | */ |
| 1886 | private Object sendRequest( |
| 1887 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1888 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1889 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1890 | } |
| 1891 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1892 | MainThreadRequest request = null; |
| 1893 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1894 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1895 | } else if (phone != null) { |
| 1896 | request = new MainThreadRequest(argument, phone, workSource); |
| 1897 | } else { |
| 1898 | request = new MainThreadRequest(argument, subId, workSource); |
| 1899 | } |
| 1900 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1901 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1902 | msg.sendToTarget(); |
| 1903 | |
| 1904 | // Wait for the request to complete |
| 1905 | synchronized (request) { |
| 1906 | while (request.result == null) { |
| 1907 | try { |
| 1908 | request.wait(); |
| 1909 | } catch (InterruptedException e) { |
| 1910 | // Do nothing, go back and wait until the request is complete |
| 1911 | } |
| 1912 | } |
| 1913 | } |
| 1914 | return request.result; |
| 1915 | } |
| 1916 | |
| 1917 | /** |
| 1918 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1919 | * Posts the specified command to be executed on the main thread, and |
| 1920 | * returns immediately. |
| 1921 | * @see #sendRequest |
| 1922 | */ |
| 1923 | private void sendRequestAsync(int command) { |
| 1924 | mMainThreadHandler.sendEmptyMessage(command); |
| 1925 | } |
| 1926 | |
| 1927 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1928 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1929 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1930 | */ |
| 1931 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1932 | sendRequestAsync(command, argument, null, null); |
| 1933 | } |
| 1934 | |
| 1935 | /** |
| 1936 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1937 | * @see {@link #sendRequest(int,Object)} |
| 1938 | */ |
| 1939 | private void sendRequestAsync( |
| 1940 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1941 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1942 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1943 | msg.sendToTarget(); |
| 1944 | } |
| 1945 | |
| 1946 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1947 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1948 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1949 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1950 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1951 | synchronized (PhoneInterfaceManager.class) { |
| 1952 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1953 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1954 | } else { |
| 1955 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1956 | } |
| 1957 | return sInstance; |
| 1958 | } |
| 1959 | } |
| 1960 | |
| 1961 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 1962 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1963 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1964 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1965 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1966 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1967 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1968 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1969 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1970 | mTelephonySharedPreferences = |
| 1971 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1972 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1973 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 1974 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1975 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1976 | publish(); |
| 1977 | } |
| 1978 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1979 | private Phone getDefaultPhone() { |
| 1980 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1981 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1982 | } |
| 1983 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1984 | private void publish() { |
| 1985 | if (DBG) log("publish: " + this); |
| 1986 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 1987 | TelephonyFrameworkInitializer |
| 1988 | .getTelephonyServiceManager() |
| 1989 | .getTelephonyServiceRegisterer() |
| 1990 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1991 | } |
| 1992 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 1993 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 1994 | if (request.phone != null) { |
| 1995 | return request.phone; |
| 1996 | } else { |
| 1997 | return getPhoneFromSubId(request.subId); |
| 1998 | } |
| 1999 | } |
| 2000 | |
| 2001 | private Phone getPhoneFromSubId(int subId) { |
| 2002 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2003 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2004 | } |
| 2005 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2006 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 2007 | Phone phone = getPhoneFromRequest(request); |
| 2008 | return phone == null ? null : |
| 2009 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 2010 | } |
| 2011 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2012 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2013 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2014 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2015 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2016 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2017 | private void sendEraseModemConfig(Phone phone) { |
| 2018 | if (phone != null) { |
| 2019 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2020 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 2021 | final long identity = Binder.clearCallingIdentity(); |
| 2022 | try { |
| 2023 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2024 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2025 | } finally { |
| 2026 | Binder.restoreCallingIdentity(identity); |
| 2027 | } |
| 2028 | } |
| 2029 | } |
| 2030 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2031 | private boolean isImsAvailableOnDevice() { |
| 2032 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2033 | if (pm == null) { |
| 2034 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2035 | // so do not throw error and allow. |
| 2036 | return true; |
| 2037 | } |
| 2038 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2039 | } |
| 2040 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2041 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2042 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2043 | } |
| 2044 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2045 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2046 | if (DBG) log("dial: " + number); |
| 2047 | // No permission check needed here: This is just a wrapper around the |
| 2048 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2049 | // the UI before it does anything. |
| 2050 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2051 | final long identity = Binder.clearCallingIdentity(); |
| 2052 | try { |
| 2053 | String url = createTelUrl(number); |
| 2054 | if (url == null) { |
| 2055 | return; |
| 2056 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2057 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2058 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2059 | PhoneConstants.State state = mCM.getState(subId); |
| 2060 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2061 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2062 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2063 | mApp.startActivity(intent); |
| 2064 | } |
| 2065 | } finally { |
| 2066 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2067 | } |
| 2068 | } |
| 2069 | |
| 2070 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2071 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2072 | } |
| 2073 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2074 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2075 | if (DBG) log("call: " + number); |
| 2076 | |
| 2077 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2078 | // need to do a permission check since we're calling startActivity() |
| 2079 | // from the context of the phone app. |
| 2080 | enforceCallPermission(); |
| 2081 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2082 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2083 | != AppOpsManager.MODE_ALLOWED) { |
| 2084 | return; |
| 2085 | } |
| 2086 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2087 | final long identity = Binder.clearCallingIdentity(); |
| 2088 | try { |
| 2089 | String url = createTelUrl(number); |
| 2090 | if (url == null) { |
| 2091 | return; |
| 2092 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2093 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2094 | boolean isValid = false; |
| 2095 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2096 | if (slist != null) { |
| 2097 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2098 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2099 | isValid = true; |
| 2100 | break; |
| 2101 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2102 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2103 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2104 | if (!isValid) { |
| 2105 | return; |
| 2106 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2107 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2108 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2109 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2110 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2111 | mApp.startActivity(intent); |
| 2112 | } finally { |
| 2113 | Binder.restoreCallingIdentity(identity); |
| 2114 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2115 | } |
| 2116 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2117 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2118 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2119 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2120 | } |
| 2121 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2122 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2123 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2124 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2125 | } |
| 2126 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2127 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2128 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2129 | |
| 2130 | final long identity = Binder.clearCallingIdentity(); |
| 2131 | try { |
| 2132 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 2133 | checkSimPin.start(); |
| 2134 | return checkSimPin.unlockSim(null, pin); |
| 2135 | } finally { |
| 2136 | Binder.restoreCallingIdentity(identity); |
| 2137 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2138 | } |
| 2139 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2140 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2141 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2142 | |
| 2143 | final long identity = Binder.clearCallingIdentity(); |
| 2144 | try { |
| 2145 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 2146 | checkSimPuk.start(); |
| 2147 | return checkSimPuk.unlockSim(puk, pin); |
| 2148 | } finally { |
| 2149 | Binder.restoreCallingIdentity(identity); |
| 2150 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2151 | } |
| 2152 | |
| 2153 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2154 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2155 | * a synchronous one. |
| 2156 | */ |
| 2157 | private static class UnlockSim extends Thread { |
| 2158 | |
| 2159 | private final IccCard mSimCard; |
| 2160 | |
| 2161 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2162 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2163 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2164 | |
| 2165 | // For replies from SimCard interface |
| 2166 | private Handler mHandler; |
| 2167 | |
| 2168 | // For async handler to identify request type |
| 2169 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2170 | |
| 2171 | public UnlockSim(IccCard simCard) { |
| 2172 | mSimCard = simCard; |
| 2173 | } |
| 2174 | |
| 2175 | @Override |
| 2176 | public void run() { |
| 2177 | Looper.prepare(); |
| 2178 | synchronized (UnlockSim.this) { |
| 2179 | mHandler = new Handler() { |
| 2180 | @Override |
| 2181 | public void handleMessage(Message msg) { |
| 2182 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2183 | switch (msg.what) { |
| 2184 | case SUPPLY_PIN_COMPLETE: |
| 2185 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2186 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2187 | mRetryCount = msg.arg1; |
| 2188 | if (ar.exception != null) { |
| 2189 | if (ar.exception instanceof CommandException && |
| 2190 | ((CommandException)(ar.exception)).getCommandError() |
| 2191 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2192 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2193 | } //When UiccCardApp dispose,handle message and return exception |
| 2194 | else if (ar.exception instanceof CommandException && |
| 2195 | ((CommandException) (ar.exception)).getCommandError() |
| 2196 | == CommandException.Error.ABORTED) { |
| 2197 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2198 | } else { |
| 2199 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2200 | } |
| 2201 | } else { |
| 2202 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2203 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2204 | mDone = true; |
| 2205 | UnlockSim.this.notifyAll(); |
| 2206 | } |
| 2207 | break; |
| 2208 | } |
| 2209 | } |
| 2210 | }; |
| 2211 | UnlockSim.this.notifyAll(); |
| 2212 | } |
| 2213 | Looper.loop(); |
| 2214 | } |
| 2215 | |
| 2216 | /* |
| 2217 | * Use PIN or PUK to unlock SIM card |
| 2218 | * |
| 2219 | * If PUK is null, unlock SIM card with PIN |
| 2220 | * |
| 2221 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2222 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2223 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2224 | |
| 2225 | while (mHandler == null) { |
| 2226 | try { |
| 2227 | wait(); |
| 2228 | } catch (InterruptedException e) { |
| 2229 | Thread.currentThread().interrupt(); |
| 2230 | } |
| 2231 | } |
| 2232 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2233 | |
| 2234 | if (puk == null) { |
| 2235 | mSimCard.supplyPin(pin, callback); |
| 2236 | } else { |
| 2237 | mSimCard.supplyPuk(puk, pin, callback); |
| 2238 | } |
| 2239 | |
| 2240 | while (!mDone) { |
| 2241 | try { |
| 2242 | Log.d(LOG_TAG, "wait for done"); |
| 2243 | wait(); |
| 2244 | } catch (InterruptedException e) { |
| 2245 | // Restore the interrupted status |
| 2246 | Thread.currentThread().interrupt(); |
| 2247 | } |
| 2248 | } |
| 2249 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2250 | int[] resultArray = new int[2]; |
| 2251 | resultArray[0] = mResult; |
| 2252 | resultArray[1] = mRetryCount; |
| 2253 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2254 | } |
| 2255 | } |
| 2256 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2257 | /** |
| 2258 | * This method has been removed due to privacy and stability concerns. |
| 2259 | */ |
| 2260 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2261 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2262 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2263 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2264 | } |
| 2265 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2266 | @Override |
| 2267 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2268 | mApp.getSystemService(AppOpsManager.class) |
| 2269 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2270 | |
| 2271 | final int targetSdk = getTargetSdk(callingPackage); |
| 2272 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2273 | // Callers targeting S have no business invoking this method. |
| 2274 | return; |
| 2275 | } |
| 2276 | |
| 2277 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2278 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2279 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2280 | .setCallingPackage(callingPackage) |
| 2281 | .setCallingFeatureId(null) |
| 2282 | .setCallingPid(Binder.getCallingPid()) |
| 2283 | .setCallingUid(Binder.getCallingUid()) |
| 2284 | .setMethod("updateServiceLocation") |
| 2285 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2286 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2287 | .build()); |
| 2288 | // Apps that lack location permission have no business calling this method; |
| 2289 | // however, because no permission was declared in the public API, denials must |
| 2290 | // all be "soft". |
| 2291 | switch (locationResult) { |
| 2292 | case DENIED_HARD: /* fall through */ |
| 2293 | case DENIED_SOFT: |
| 2294 | return; |
| 2295 | } |
| 2296 | |
| 2297 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2298 | final long identity = Binder.clearCallingIdentity(); |
| 2299 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2300 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2301 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2302 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2303 | } |
| 2304 | } finally { |
| 2305 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2306 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2307 | } |
| 2308 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2309 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2310 | @Override |
| 2311 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2312 | return isRadioOnWithFeature(callingPackage, null); |
| 2313 | } |
| 2314 | |
| 2315 | |
| 2316 | @Override |
| 2317 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2318 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2319 | callingFeatureId); |
| 2320 | } |
| 2321 | |
| 2322 | @Deprecated |
| 2323 | @Override |
| 2324 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2325 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2326 | } |
| 2327 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2328 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2329 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2330 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2331 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2332 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2333 | return false; |
| 2334 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2335 | |
| 2336 | final long identity = Binder.clearCallingIdentity(); |
| 2337 | try { |
| 2338 | return isRadioOnForSubscriber(subId); |
| 2339 | } finally { |
| 2340 | Binder.restoreCallingIdentity(identity); |
| 2341 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2342 | } |
| 2343 | |
| 2344 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2345 | final long identity = Binder.clearCallingIdentity(); |
| 2346 | try { |
| 2347 | final Phone phone = getPhone(subId); |
| 2348 | if (phone != null) { |
| 2349 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2350 | } else { |
| 2351 | return false; |
| 2352 | } |
| 2353 | } finally { |
| 2354 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2355 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2356 | } |
| 2357 | |
| 2358 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2359 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2360 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2361 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2362 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2363 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2364 | |
| 2365 | final long identity = Binder.clearCallingIdentity(); |
| 2366 | try { |
| 2367 | final Phone phone = getPhone(subId); |
| 2368 | if (phone != null) { |
| 2369 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2370 | } |
| 2371 | } finally { |
| 2372 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2373 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2374 | } |
| 2375 | |
| 2376 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2377 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2378 | } |
| 2379 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2380 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2381 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2382 | |
| 2383 | final long identity = Binder.clearCallingIdentity(); |
| 2384 | try { |
| 2385 | final Phone phone = getPhone(subId); |
| 2386 | if (phone == null) { |
| 2387 | return false; |
| 2388 | } |
| 2389 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2390 | toggleRadioOnOffForSubscriber(subId); |
| 2391 | } |
| 2392 | return true; |
| 2393 | } finally { |
| 2394 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2395 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2396 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2397 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2398 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2399 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2400 | /* |
| 2401 | * If any of the Radios are available, it will need to be |
| 2402 | * shutdown. So return true if any Radio is available. |
| 2403 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2404 | final long identity = Binder.clearCallingIdentity(); |
| 2405 | try { |
| 2406 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2407 | Phone phone = PhoneFactory.getPhone(i); |
| 2408 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2409 | } |
| 2410 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2411 | return false; |
| 2412 | } finally { |
| 2413 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2414 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2415 | } |
| 2416 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2417 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2418 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2419 | enforceModifyPermission(); |
| 2420 | |
| 2421 | final long identity = Binder.clearCallingIdentity(); |
| 2422 | try { |
| 2423 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2424 | logv("Shutting down Phone " + i); |
| 2425 | shutdownRadioUsingPhoneId(i); |
| 2426 | } |
| 2427 | } finally { |
| 2428 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2429 | } |
| 2430 | } |
| 2431 | |
| 2432 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2433 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2434 | if (phone != null && phone.isRadioAvailable()) { |
| 2435 | phone.shutdownRadio(); |
| 2436 | } |
| 2437 | } |
| 2438 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2439 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2440 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2441 | |
| 2442 | final long identity = Binder.clearCallingIdentity(); |
| 2443 | try { |
| 2444 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2445 | if (defaultPhone != null) { |
| 2446 | defaultPhone.setRadioPower(turnOn); |
| 2447 | return true; |
| 2448 | } else { |
| 2449 | loge("There's no default phone."); |
| 2450 | return false; |
| 2451 | } |
| 2452 | } finally { |
| 2453 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2454 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2455 | } |
| 2456 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2457 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2458 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2459 | |
| 2460 | final long identity = Binder.clearCallingIdentity(); |
| 2461 | try { |
| 2462 | final Phone phone = getPhone(subId); |
| 2463 | if (phone != null) { |
| 2464 | phone.setRadioPower(turnOn); |
| 2465 | return true; |
| 2466 | } else { |
| 2467 | return false; |
| 2468 | } |
| 2469 | } finally { |
| 2470 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2471 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2472 | } |
| 2473 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2474 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2475 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2476 | public boolean enableDataConnectivity() { |
| 2477 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2478 | |
| 2479 | final long identity = Binder.clearCallingIdentity(); |
| 2480 | try { |
| 2481 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2482 | final Phone phone = getPhone(subId); |
| 2483 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2484 | phone.getDataEnabledSettings().setDataEnabled( |
| 2485 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2486 | return true; |
| 2487 | } else { |
| 2488 | return false; |
| 2489 | } |
| 2490 | } finally { |
| 2491 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2492 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2493 | } |
| 2494 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2495 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2496 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2497 | public boolean disableDataConnectivity() { |
| 2498 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2499 | |
| 2500 | final long identity = Binder.clearCallingIdentity(); |
| 2501 | try { |
| 2502 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2503 | final Phone phone = getPhone(subId); |
| 2504 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2505 | phone.getDataEnabledSettings().setDataEnabled( |
| 2506 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2507 | return true; |
| 2508 | } else { |
| 2509 | return false; |
| 2510 | } |
| 2511 | } finally { |
| 2512 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2513 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2514 | } |
| 2515 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2516 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2517 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2518 | final long identity = Binder.clearCallingIdentity(); |
| 2519 | try { |
| 2520 | final Phone phone = getPhone(subId); |
| 2521 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2522 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2523 | } else { |
| 2524 | return false; |
| 2525 | } |
| 2526 | } finally { |
| 2527 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2528 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2529 | } |
| 2530 | |
| 2531 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2532 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2533 | } |
| 2534 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2535 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2536 | enforceCallPermission(); |
| 2537 | |
| 2538 | final long identity = Binder.clearCallingIdentity(); |
| 2539 | try { |
| 2540 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2541 | return; |
| 2542 | } |
| 2543 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2544 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2545 | } finally { |
| 2546 | Binder.restoreCallingIdentity(identity); |
| 2547 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2548 | }; |
| 2549 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2550 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2551 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2552 | |
| 2553 | final long identity = Binder.clearCallingIdentity(); |
| 2554 | try { |
| 2555 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2556 | return false; |
| 2557 | } |
| 2558 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2559 | } finally { |
| 2560 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2561 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2562 | } |
| 2563 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2564 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2565 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2566 | } |
| 2567 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2568 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2569 | final long identity = Binder.clearCallingIdentity(); |
| 2570 | try { |
| 2571 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2572 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2573 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2574 | } finally { |
| 2575 | Binder.restoreCallingIdentity(identity); |
| 2576 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2577 | } |
| 2578 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2579 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2580 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2581 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2582 | } |
| 2583 | |
| 2584 | @Override |
| 2585 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2586 | final long identity = Binder.clearCallingIdentity(); |
| 2587 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2588 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2589 | if (phone != null) { |
| 2590 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2591 | } else { |
| 2592 | return PhoneConstantConversions.convertDataState( |
| 2593 | PhoneConstants.DataState.DISCONNECTED); |
| 2594 | } |
| 2595 | } finally { |
| 2596 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2597 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2598 | } |
| 2599 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2600 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2601 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2602 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2603 | } |
| 2604 | |
| 2605 | @Override |
| 2606 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2607 | final long identity = Binder.clearCallingIdentity(); |
| 2608 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2609 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2610 | if (phone != null) { |
| 2611 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2612 | } else { |
| 2613 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2614 | } |
| 2615 | } finally { |
| 2616 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2617 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2618 | } |
| 2619 | |
| 2620 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2621 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2622 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2623 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2624 | |
| 2625 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2626 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2627 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2628 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2629 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2630 | .setCallingPid(Binder.getCallingPid()) |
| 2631 | .setCallingUid(Binder.getCallingUid()) |
| 2632 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2633 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2634 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2635 | .build()); |
| 2636 | switch (locationResult) { |
| 2637 | case DENIED_HARD: |
| 2638 | throw new SecurityException("Not allowed to access cell location"); |
| 2639 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2640 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2641 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2642 | } |
| 2643 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2644 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2645 | final long identity = Binder.clearCallingIdentity(); |
| 2646 | try { |
| 2647 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2648 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2649 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2650 | } finally { |
| 2651 | Binder.restoreCallingIdentity(identity); |
| 2652 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2653 | } |
| 2654 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2655 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2656 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2657 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2658 | // registered cell info, so return a NULL country instead. |
| 2659 | final long identity = Binder.clearCallingIdentity(); |
| 2660 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2661 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2662 | // Get default phone in this case. |
| 2663 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2664 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2665 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2666 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2667 | if (phone == null) return ""; |
| 2668 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2669 | if (sst == null) return ""; |
| 2670 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2671 | if (lt == null) return ""; |
| 2672 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry(); |
| 2673 | EmergencyNumberTracker ent = phone.getEmergencyNumberTracker(); |
| 2674 | return (ent == null) ? "" : ent.getEmergencyCountryIso(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2675 | } finally { |
| 2676 | Binder.restoreCallingIdentity(identity); |
| 2677 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2678 | } |
| 2679 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2680 | /** |
| 2681 | * This method was removed due to potential issues caused by performing partial |
| 2682 | * updates of service state, and lack of a credible use case. |
| 2683 | * |
| 2684 | * This has the ability to break the telephony implementation by disabling notification of |
| 2685 | * changes in device connectivity. DO NOT USE THIS! |
| 2686 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2687 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2688 | public void enableLocationUpdates() { |
| 2689 | mApp.enforceCallingOrSelfPermission( |
| 2690 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2691 | } |
| 2692 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2693 | /** |
| 2694 | * This method was removed due to potential issues caused by performing partial |
| 2695 | * updates of service state, and lack of a credible use case. |
| 2696 | * |
| 2697 | * This has the ability to break the telephony implementation by disabling notification of |
| 2698 | * changes in device connectivity. DO NOT USE THIS! |
| 2699 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2700 | @Override |
| 2701 | public void disableLocationUpdates() { |
| 2702 | mApp.enforceCallingOrSelfPermission( |
| 2703 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2704 | } |
| 2705 | |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2706 | /** |
| 2707 | * Returns the target SDK version number for a given package name. |
| 2708 | * |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2709 | * This call MUST be invoked before clearing the calling UID. |
| 2710 | * |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2711 | * @return target SDK if the package is found or INT_MAX. |
| 2712 | */ |
| 2713 | private int getTargetSdk(String packageName) { |
| 2714 | try { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2715 | final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser( |
Chen Xu | 0150f0e | 2019-07-30 15:12:06 -0700 | [diff] [blame] | 2716 | packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid())); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2717 | if (ai != null) return ai.targetSdkVersion; |
| 2718 | } catch (PackageManager.NameNotFoundException unexpected) { |
Nathan Harold | ec18474 | 2019-07-10 17:04:16 -0700 | [diff] [blame] | 2719 | loge("Failed to get package info for pkg=" |
| 2720 | + packageName + ", uid=" + Binder.getCallingUid()); |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2721 | } |
| 2722 | return Integer.MAX_VALUE; |
| 2723 | } |
| 2724 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2725 | @Override |
| 2726 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2727 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2728 | String callingFeatureId) { |
Nathan Harold | 31d7ff3 | 2018-10-15 20:20:30 -0700 | [diff] [blame] | 2729 | final int targetSdk = getTargetSdk(callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2730 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2731 | throw new SecurityException( |
| 2732 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2733 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2734 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2735 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2736 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2737 | return null; |
| 2738 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2739 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2740 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2741 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2742 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2743 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2744 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2745 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2746 | for (CellInfo ci : info) { |
| 2747 | if (ci instanceof CellInfoGsm) { |
| 2748 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2749 | } else if (ci instanceof CellInfoWcdma) { |
| 2750 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2751 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2752 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2753 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2754 | } |
| 2755 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2756 | private List<CellInfo> getCachedCellInfo() { |
| 2757 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2758 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2759 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2760 | if (info != null) cellInfos.addAll(info); |
| 2761 | } |
| 2762 | return cellInfos; |
| 2763 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2764 | |
| 2765 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2766 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2767 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2768 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2769 | |
| 2770 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2771 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2772 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2773 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2774 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2775 | .setCallingPid(Binder.getCallingPid()) |
| 2776 | .setCallingUid(Binder.getCallingUid()) |
| 2777 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2778 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2779 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2780 | .build()); |
| 2781 | switch (locationResult) { |
| 2782 | case DENIED_HARD: |
| 2783 | throw new SecurityException("Not allowed to access cell info"); |
| 2784 | case DENIED_SOFT: |
| 2785 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2786 | } |
| 2787 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2788 | final int targetSdk = getTargetSdk(callingPackage); |
| 2789 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2790 | return getCachedCellInfo(); |
| 2791 | } |
| 2792 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2793 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2794 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2795 | final long identity = Binder.clearCallingIdentity(); |
| 2796 | try { |
| 2797 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2798 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2799 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2800 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2801 | if (info != null) cellInfos.addAll(info); |
| 2802 | } |
| 2803 | return cellInfos; |
| 2804 | } finally { |
| 2805 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2806 | } |
| 2807 | } |
| 2808 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2809 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2810 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2811 | String callingFeatureId) { |
| 2812 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2813 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2814 | } |
| 2815 | |
| 2816 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2817 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2818 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2819 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2820 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2821 | } |
| 2822 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2823 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2824 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2825 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2826 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2827 | |
| 2828 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2829 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2830 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2831 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2832 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2833 | .setCallingPid(Binder.getCallingPid()) |
| 2834 | .setCallingUid(Binder.getCallingUid()) |
| 2835 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2836 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2837 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2838 | .build()); |
| 2839 | switch (locationResult) { |
| 2840 | case DENIED_HARD: |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2841 | if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) { |
| 2842 | // Safetynet logging for b/154934934 |
| 2843 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2844 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2845 | throw new SecurityException("Not allowed to access cell info"); |
| 2846 | case DENIED_SOFT: |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2847 | if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) { |
| 2848 | // Safetynet logging for b/154934934 |
| 2849 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2850 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2851 | try { |
| 2852 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2853 | } catch (RemoteException re) { |
| 2854 | // Drop without consequences |
| 2855 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2856 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2857 | } |
| 2858 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2859 | |
| 2860 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2861 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2862 | |
| 2863 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2864 | } |
| 2865 | |
| 2866 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2867 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2868 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2869 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2870 | |
| 2871 | final long identity = Binder.clearCallingIdentity(); |
| 2872 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2873 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2874 | } finally { |
| 2875 | Binder.restoreCallingIdentity(identity); |
| 2876 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2877 | } |
| 2878 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2879 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2880 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2881 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2882 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2883 | return null; |
| 2884 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2885 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2886 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2887 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2888 | return null; |
| 2889 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2890 | |
| 2891 | final long identity = Binder.clearCallingIdentity(); |
| 2892 | try { |
| 2893 | return phone.getImei(); |
| 2894 | } finally { |
| 2895 | Binder.restoreCallingIdentity(identity); |
| 2896 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2897 | } |
| 2898 | |
| 2899 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2900 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2901 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2902 | String tac = null; |
| 2903 | if (phone != null) { |
| 2904 | String imei = phone.getImei(); |
| 2905 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2906 | } |
| 2907 | return tac; |
| 2908 | } |
| 2909 | |
| 2910 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2911 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2912 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2913 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2914 | return null; |
| 2915 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2916 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2917 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2918 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2919 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2920 | return null; |
| 2921 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2922 | |
| 2923 | final long identity = Binder.clearCallingIdentity(); |
| 2924 | try { |
| 2925 | return phone.getMeid(); |
| 2926 | } finally { |
| 2927 | Binder.restoreCallingIdentity(identity); |
| 2928 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2929 | } |
| 2930 | |
| 2931 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2932 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2933 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2934 | String manufacturerCode = null; |
| 2935 | if (phone != null) { |
| 2936 | String meid = phone.getMeid(); |
| 2937 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2938 | } |
| 2939 | return manufacturerCode; |
| 2940 | } |
| 2941 | |
| 2942 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2943 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2944 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2945 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2946 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2947 | return null; |
| 2948 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2949 | int subId = phone.getSubId(); |
| 2950 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2951 | mApp, subId, callingPackage, callingFeatureId, |
| 2952 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2953 | return null; |
| 2954 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2955 | |
| 2956 | final long identity = Binder.clearCallingIdentity(); |
| 2957 | try { |
| 2958 | return phone.getDeviceSvn(); |
| 2959 | } finally { |
| 2960 | Binder.restoreCallingIdentity(identity); |
| 2961 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2962 | } |
| 2963 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2964 | @Override |
| 2965 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2966 | final long identity = Binder.clearCallingIdentity(); |
| 2967 | try { |
| 2968 | final Phone phone = getPhone(subId); |
| 2969 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2970 | } finally { |
| 2971 | Binder.restoreCallingIdentity(identity); |
| 2972 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2973 | } |
| 2974 | |
| 2975 | @Override |
| 2976 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2977 | final long identity = Binder.clearCallingIdentity(); |
| 2978 | try { |
| 2979 | final Phone phone = getPhone(subId); |
| 2980 | return phone == null ? null : phone.getCarrierName(); |
| 2981 | } finally { |
| 2982 | Binder.restoreCallingIdentity(identity); |
| 2983 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2984 | } |
| 2985 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2986 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2987 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2988 | final long identity = Binder.clearCallingIdentity(); |
| 2989 | try { |
| 2990 | final Phone phone = getPhone(subId); |
| 2991 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2992 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2993 | } finally { |
| 2994 | Binder.restoreCallingIdentity(identity); |
| 2995 | } |
| 2996 | } |
| 2997 | |
| 2998 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2999 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3000 | final long identity = Binder.clearCallingIdentity(); |
| 3001 | try { |
| 3002 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3003 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3004 | } finally { |
| 3005 | Binder.restoreCallingIdentity(identity); |
| 3006 | } |
| 3007 | } |
| 3008 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3009 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3010 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3011 | if (!isSubscriptionMccMnc) { |
| 3012 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3013 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3014 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3015 | if (phone == null) { |
| 3016 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3017 | } |
| 3018 | final long identity = Binder.clearCallingIdentity(); |
| 3019 | try { |
| 3020 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3021 | } finally { |
| 3022 | Binder.restoreCallingIdentity(identity); |
| 3023 | } |
| 3024 | } |
| 3025 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3026 | // |
| 3027 | // Internal helper methods. |
| 3028 | // |
| 3029 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3030 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3031 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3032 | * |
| 3033 | * @throws SecurityException if the caller does not have the required permission |
| 3034 | */ |
| 3035 | private void enforceModifyPermission() { |
| 3036 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3037 | } |
| 3038 | |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3039 | /** |
| 3040 | * Make sure the caller is system. |
| 3041 | * |
| 3042 | * @throws SecurityException if the caller is not system. |
| 3043 | */ |
| 3044 | private void enforceSystemCaller() { |
| 3045 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 3046 | throw new SecurityException("Caller must be system"); |
| 3047 | } |
| 3048 | } |
| 3049 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3050 | private void enforceActiveEmergencySessionPermission() { |
| 3051 | mApp.enforceCallingOrSelfPermission( |
| 3052 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3053 | } |
| 3054 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3055 | /** |
| 3056 | * Make sure the caller has the CALL_PHONE permission. |
| 3057 | * |
| 3058 | * @throws SecurityException if the caller does not have the required permission |
| 3059 | */ |
| 3060 | private void enforceCallPermission() { |
| 3061 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3062 | } |
| 3063 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3064 | private void enforceSettingsPermission() { |
| 3065 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3066 | } |
| 3067 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3068 | private String createTelUrl(String number) { |
| 3069 | if (TextUtils.isEmpty(number)) { |
| 3070 | return null; |
| 3071 | } |
| 3072 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3073 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3074 | } |
| 3075 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3076 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3077 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3078 | } |
| 3079 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3080 | private static void logv(String msg) { |
| 3081 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3082 | } |
| 3083 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3084 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3085 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3086 | } |
| 3087 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3088 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3089 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3090 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3091 | } |
| 3092 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3093 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3094 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3095 | final long identity = Binder.clearCallingIdentity(); |
| 3096 | try { |
| 3097 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3098 | if (phone == null) { |
| 3099 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3100 | } else { |
| 3101 | return phone.getPhoneType(); |
| 3102 | } |
| 3103 | } finally { |
| 3104 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3105 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3106 | } |
| 3107 | |
| 3108 | /** |
| 3109 | * Returns the CDMA ERI icon index to display |
| 3110 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3111 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3112 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3113 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3114 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3115 | } |
| 3116 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3117 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3118 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3119 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3120 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3121 | mApp, subId, callingPackage, callingFeatureId, |
| 3122 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3123 | return -1; |
| 3124 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3125 | |
| 3126 | final long identity = Binder.clearCallingIdentity(); |
| 3127 | try { |
| 3128 | final Phone phone = getPhone(subId); |
| 3129 | if (phone != null) { |
| 3130 | return phone.getCdmaEriIconIndex(); |
| 3131 | } else { |
| 3132 | return -1; |
| 3133 | } |
| 3134 | } finally { |
| 3135 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3136 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3137 | } |
| 3138 | |
| 3139 | /** |
| 3140 | * Returns the CDMA ERI icon mode, |
| 3141 | * 0 - ON |
| 3142 | * 1 - FLASHING |
| 3143 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3144 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3145 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3146 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3147 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3148 | } |
| 3149 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3150 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3151 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3152 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3153 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3154 | mApp, subId, callingPackage, callingFeatureId, |
| 3155 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3156 | return -1; |
| 3157 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3158 | |
| 3159 | final long identity = Binder.clearCallingIdentity(); |
| 3160 | try { |
| 3161 | final Phone phone = getPhone(subId); |
| 3162 | if (phone != null) { |
| 3163 | return phone.getCdmaEriIconMode(); |
| 3164 | } else { |
| 3165 | return -1; |
| 3166 | } |
| 3167 | } finally { |
| 3168 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3169 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3170 | } |
| 3171 | |
| 3172 | /** |
| 3173 | * Returns the CDMA ERI text, |
| 3174 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3175 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3176 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3177 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3178 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3179 | } |
| 3180 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3181 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3182 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3183 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3184 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3185 | mApp, subId, callingPackage, callingFeatureId, |
| 3186 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3187 | return null; |
| 3188 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3189 | |
| 3190 | final long identity = Binder.clearCallingIdentity(); |
| 3191 | try { |
| 3192 | final Phone phone = getPhone(subId); |
| 3193 | if (phone != null) { |
| 3194 | return phone.getCdmaEriText(); |
| 3195 | } else { |
| 3196 | return null; |
| 3197 | } |
| 3198 | } finally { |
| 3199 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3200 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3201 | } |
| 3202 | |
| 3203 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3204 | * Returns the CDMA MDN. |
| 3205 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3206 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3207 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3208 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3209 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3210 | |
| 3211 | final long identity = Binder.clearCallingIdentity(); |
| 3212 | try { |
| 3213 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3214 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3215 | return phone.getLine1Number(); |
| 3216 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3217 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3218 | return null; |
| 3219 | } |
| 3220 | } finally { |
| 3221 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3222 | } |
| 3223 | } |
| 3224 | |
| 3225 | /** |
| 3226 | * Returns the CDMA MIN. |
| 3227 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3228 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3229 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3230 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3231 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3232 | |
| 3233 | final long identity = Binder.clearCallingIdentity(); |
| 3234 | try { |
| 3235 | final Phone phone = getPhone(subId); |
| 3236 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3237 | return phone.getCdmaMin(); |
| 3238 | } else { |
| 3239 | return null; |
| 3240 | } |
| 3241 | } finally { |
| 3242 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3243 | } |
| 3244 | } |
| 3245 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3246 | @Override |
| 3247 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3248 | INumberVerificationCallback callback, String callingPackage) { |
| 3249 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3250 | != PERMISSION_GRANTED) { |
| 3251 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3252 | } |
| 3253 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3254 | |
| 3255 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3256 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 3257 | throw new SecurityException("Calling package must be configured in the device config"); |
| 3258 | } |
| 3259 | |
| 3260 | if (range == null) { |
| 3261 | throw new NullPointerException("Range must be non-null"); |
| 3262 | } |
| 3263 | |
| 3264 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3265 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3266 | |
| 3267 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3268 | } |
| 3269 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3270 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3271 | * Returns true if CDMA provisioning needs to run. |
| 3272 | */ |
| 3273 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3274 | final long identity = Binder.clearCallingIdentity(); |
| 3275 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3276 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3277 | } finally { |
| 3278 | Binder.restoreCallingIdentity(identity); |
| 3279 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3280 | } |
| 3281 | |
| 3282 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3283 | * Sets the voice mail number of a given subId. |
| 3284 | */ |
| 3285 | @Override |
| 3286 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3287 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3288 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3289 | |
| 3290 | final long identity = Binder.clearCallingIdentity(); |
| 3291 | try { |
| 3292 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3293 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3294 | return success; |
| 3295 | } finally { |
| 3296 | Binder.restoreCallingIdentity(identity); |
| 3297 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3298 | } |
| 3299 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3300 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3301 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3302 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3303 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3304 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3305 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3306 | throw new SecurityException("caller must be system dialer"); |
| 3307 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3308 | |
| 3309 | final long identity = Binder.clearCallingIdentity(); |
| 3310 | try { |
| 3311 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3312 | if (phoneAccountHandle == null) { |
| 3313 | return null; |
| 3314 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3315 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3316 | } finally { |
| 3317 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3318 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3319 | } |
| 3320 | |
| 3321 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3322 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3323 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3324 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3325 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3326 | mApp, subId, callingPackage, callingFeatureId, |
| 3327 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3328 | return null; |
| 3329 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3330 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3331 | final long identity = Binder.clearCallingIdentity(); |
| 3332 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3333 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3334 | } finally { |
| 3335 | Binder.restoreCallingIdentity(identity); |
| 3336 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3337 | } |
| 3338 | |
| 3339 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3340 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3341 | VisualVoicemailSmsFilterSettings settings) { |
| 3342 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3343 | |
| 3344 | final long identity = Binder.clearCallingIdentity(); |
| 3345 | try { |
| 3346 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3347 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3348 | } finally { |
| 3349 | Binder.restoreCallingIdentity(identity); |
| 3350 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3351 | } |
| 3352 | |
| 3353 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3354 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3355 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3356 | |
| 3357 | final long identity = Binder.clearCallingIdentity(); |
| 3358 | try { |
| 3359 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3360 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3361 | } finally { |
| 3362 | Binder.restoreCallingIdentity(identity); |
| 3363 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3364 | } |
| 3365 | |
| 3366 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3367 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3368 | String callingPackage, int subId) { |
| 3369 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3370 | |
| 3371 | final long identity = Binder.clearCallingIdentity(); |
| 3372 | try { |
| 3373 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3374 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3375 | } finally { |
| 3376 | Binder.restoreCallingIdentity(identity); |
| 3377 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3378 | } |
| 3379 | |
| 3380 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3381 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3382 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3383 | |
| 3384 | final long identity = Binder.clearCallingIdentity(); |
| 3385 | try { |
| 3386 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3387 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3388 | } finally { |
| 3389 | Binder.restoreCallingIdentity(identity); |
| 3390 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3391 | } |
| 3392 | |
| 3393 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3394 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3395 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3396 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3397 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3398 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3399 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3400 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3401 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3402 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3403 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3404 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3405 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3406 | * Sets the voice activation state of a given subId. |
| 3407 | */ |
| 3408 | @Override |
| 3409 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3410 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3411 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3412 | |
| 3413 | final long identity = Binder.clearCallingIdentity(); |
| 3414 | try { |
| 3415 | final Phone phone = getPhone(subId); |
| 3416 | if (phone != null) { |
| 3417 | phone.setVoiceActivationState(activationState); |
| 3418 | } else { |
| 3419 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3420 | } |
| 3421 | } finally { |
| 3422 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3423 | } |
| 3424 | } |
| 3425 | |
| 3426 | /** |
| 3427 | * Sets the data activation state of a given subId. |
| 3428 | */ |
| 3429 | @Override |
| 3430 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3431 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3432 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3433 | |
| 3434 | final long identity = Binder.clearCallingIdentity(); |
| 3435 | try { |
| 3436 | final Phone phone = getPhone(subId); |
| 3437 | if (phone != null) { |
| 3438 | phone.setDataActivationState(activationState); |
| 3439 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3440 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3441 | } |
| 3442 | } finally { |
| 3443 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3444 | } |
| 3445 | } |
| 3446 | |
| 3447 | /** |
| 3448 | * Returns the voice activation state of a given subId. |
| 3449 | */ |
| 3450 | @Override |
| 3451 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3452 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3453 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3454 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3455 | final long identity = Binder.clearCallingIdentity(); |
| 3456 | try { |
| 3457 | if (phone != null) { |
| 3458 | return phone.getVoiceActivationState(); |
| 3459 | } else { |
| 3460 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3461 | } |
| 3462 | } finally { |
| 3463 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3464 | } |
| 3465 | } |
| 3466 | |
| 3467 | /** |
| 3468 | * Returns the data activation state of a given subId. |
| 3469 | */ |
| 3470 | @Override |
| 3471 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3472 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3473 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3474 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3475 | final long identity = Binder.clearCallingIdentity(); |
| 3476 | try { |
| 3477 | if (phone != null) { |
| 3478 | return phone.getDataActivationState(); |
| 3479 | } else { |
| 3480 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3481 | } |
| 3482 | } finally { |
| 3483 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3484 | } |
| 3485 | } |
| 3486 | |
| 3487 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3488 | * Returns the unread count of voicemails for a subId |
| 3489 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3490 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3491 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3492 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3493 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3494 | mApp, subId, callingPackage, callingFeatureId, |
| 3495 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3496 | return 0; |
| 3497 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3498 | final long identity = Binder.clearCallingIdentity(); |
| 3499 | try { |
| 3500 | final Phone phone = getPhone(subId); |
| 3501 | if (phone != null) { |
| 3502 | return phone.getVoiceMessageCount(); |
| 3503 | } else { |
| 3504 | return 0; |
| 3505 | } |
| 3506 | } finally { |
| 3507 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3508 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3509 | } |
| 3510 | |
| 3511 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3512 | * returns true, if the device is in a state where both voice and data |
| 3513 | * are supported simultaneously. This can change based on location or network condition. |
| 3514 | */ |
| 3515 | @Override |
| 3516 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3517 | final long identity = Binder.clearCallingIdentity(); |
| 3518 | try { |
| 3519 | final Phone phone = getPhone(subId); |
| 3520 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3521 | } finally { |
| 3522 | Binder.restoreCallingIdentity(identity); |
| 3523 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3524 | } |
| 3525 | |
| 3526 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3527 | * Send the dialer code if called from the current default dialer or the caller has |
| 3528 | * carrier privilege. |
| 3529 | * @param inputCode The dialer code to send |
| 3530 | */ |
| 3531 | @Override |
| 3532 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3533 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3534 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3535 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3536 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3537 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3538 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3539 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3540 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3541 | |
| 3542 | final long identity = Binder.clearCallingIdentity(); |
| 3543 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3544 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3545 | } finally { |
| 3546 | Binder.restoreCallingIdentity(identity); |
| 3547 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3548 | } |
| 3549 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3550 | @Override |
| 3551 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3552 | TelephonyPermissions |
| 3553 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3554 | mApp, subId, "getNetworkSelectionMode"); |
| 3555 | final long identity = Binder.clearCallingIdentity(); |
| 3556 | try { |
| 3557 | if (!isActiveSubscription(subId)) { |
| 3558 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3559 | } |
| 3560 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3561 | } finally { |
| 3562 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3563 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3564 | } |
| 3565 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3566 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3567 | public boolean isInEmergencySmsMode() { |
| 3568 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3569 | final long identity = Binder.clearCallingIdentity(); |
| 3570 | try { |
| 3571 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3572 | if (phone.isInEmergencySmsMode()) { |
| 3573 | return true; |
| 3574 | } |
| 3575 | } |
| 3576 | } finally { |
| 3577 | Binder.restoreCallingIdentity(identity); |
| 3578 | } |
| 3579 | return false; |
| 3580 | } |
| 3581 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3582 | /** |
| 3583 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3584 | * @param subId The subscription to use to check the configuration. |
| 3585 | * @param c The callback that will be used to send the result. |
| 3586 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3587 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3588 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3589 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3590 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3591 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3592 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3593 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3594 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3595 | "IMS not available on device."); |
| 3596 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3597 | final long token = Binder.clearCallingIdentity(); |
| 3598 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3599 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3600 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3601 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3602 | } catch (ImsException e) { |
| 3603 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3604 | } finally { |
| 3605 | Binder.restoreCallingIdentity(token); |
| 3606 | } |
| 3607 | } |
| 3608 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3609 | /** |
| 3610 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3611 | * @param subId The subscription to use to check the configuration. |
| 3612 | * @param c The callback that will be used to send the result. |
| 3613 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3614 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3615 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3616 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3617 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3618 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3619 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3620 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3621 | final long token = Binder.clearCallingIdentity(); |
| 3622 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3623 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3624 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3625 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3626 | } catch (ImsException e) { |
| 3627 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3628 | + "is inactive, ignoring unregister."); |
| 3629 | // If the subscription is no longer active, just return, since the callback |
| 3630 | // will already have been removed internally. |
| 3631 | } finally { |
| 3632 | Binder.restoreCallingIdentity(token); |
| 3633 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3634 | } |
| 3635 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3636 | /** |
| 3637 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3638 | */ |
| 3639 | @Override |
| 3640 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3641 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3642 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3643 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3644 | "IMS not available on device."); |
| 3645 | } |
| 3646 | final long token = Binder.clearCallingIdentity(); |
| 3647 | try { |
| 3648 | Phone phone = getPhone(subId); |
| 3649 | if (phone == null) { |
| 3650 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3651 | + subId + "'"); |
| 3652 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3653 | } |
| 3654 | phone.getImsRegistrationState(regState -> { |
| 3655 | try { |
| 3656 | consumer.accept((regState == null) |
| 3657 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3658 | } catch (RemoteException e) { |
| 3659 | // Ignore if the remote process is no longer available to call back. |
| 3660 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3661 | } |
| 3662 | }); |
| 3663 | } finally { |
| 3664 | Binder.restoreCallingIdentity(token); |
| 3665 | } |
| 3666 | } |
| 3667 | |
| 3668 | /** |
| 3669 | * Get the transport type for the IMS service registration state. |
| 3670 | */ |
| 3671 | @Override |
| 3672 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3673 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3674 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3675 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3676 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3677 | "IMS not available on device."); |
| 3678 | } |
| 3679 | final long token = Binder.clearCallingIdentity(); |
| 3680 | try { |
| 3681 | Phone phone = getPhone(subId); |
| 3682 | if (phone == null) { |
| 3683 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3684 | + subId + "'"); |
| 3685 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3686 | } |
| 3687 | phone.getImsRegistrationTech(regTech -> { |
| 3688 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3689 | int regTechConverted = (regTech == null) |
| 3690 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3691 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3692 | regTechConverted); |
| 3693 | try { |
| 3694 | consumer.accept(regTechConverted); |
| 3695 | } catch (RemoteException e) { |
| 3696 | // Ignore if the remote process is no longer available to call back. |
| 3697 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3698 | } |
| 3699 | }); |
| 3700 | } finally { |
| 3701 | Binder.restoreCallingIdentity(token); |
| 3702 | } |
| 3703 | } |
| 3704 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3705 | /** |
| 3706 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3707 | * @param subId The subscription to use to check the configuration. |
| 3708 | * @param c The callback that will be used to send the result. |
| 3709 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3710 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3711 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3712 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3713 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3714 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3715 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3716 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3717 | "IMS not available on device."); |
| 3718 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3719 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3720 | final long token = Binder.clearCallingIdentity(); |
| 3721 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3722 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3723 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3724 | } catch (ImsException e) { |
| 3725 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3726 | } finally { |
| 3727 | Binder.restoreCallingIdentity(token); |
| 3728 | } |
| 3729 | } |
| 3730 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3731 | /** |
| 3732 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3733 | * @param subId The subscription to use to check the configuration. |
| 3734 | * @param c The callback that will be used to send the result. |
| 3735 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3736 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3737 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3738 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3739 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3740 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3741 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3742 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3743 | |
| 3744 | final long token = Binder.clearCallingIdentity(); |
| 3745 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3746 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3747 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3748 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3749 | } catch (ImsException e) { |
| 3750 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3751 | + "is inactive, ignoring unregister."); |
| 3752 | // If the subscription is no longer active, just return, since the callback |
| 3753 | // will already have been removed internally. |
| 3754 | } finally { |
| 3755 | Binder.restoreCallingIdentity(token); |
| 3756 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3757 | } |
| 3758 | |
| 3759 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3760 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3761 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3762 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3763 | final long token = Binder.clearCallingIdentity(); |
| 3764 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3765 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3766 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3767 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3768 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3769 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3770 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3771 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3772 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3773 | } finally { |
| 3774 | Binder.restoreCallingIdentity(token); |
| 3775 | } |
| 3776 | } |
| 3777 | |
| 3778 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3779 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3780 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3781 | final long token = Binder.clearCallingIdentity(); |
| 3782 | try { |
| 3783 | Phone phone = getPhone(subId); |
| 3784 | if (phone == null) return false; |
| 3785 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3786 | } catch (com.android.ims.ImsException e) { |
| 3787 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3788 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3789 | } finally { |
| 3790 | Binder.restoreCallingIdentity(token); |
| 3791 | } |
| 3792 | } |
| 3793 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3794 | /** |
| 3795 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3796 | * subscription. |
| 3797 | * @param subId The subscription to use to check the configuration. |
| 3798 | * @param callback The callback that will be used to send the result. |
| 3799 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3800 | * @param transportType The transport type of the MmTelFeature capability. |
| 3801 | */ |
| 3802 | @Override |
| 3803 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3804 | int transportType) { |
| 3805 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3806 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3807 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3808 | "IMS not available on device."); |
| 3809 | } |
| 3810 | final long token = Binder.clearCallingIdentity(); |
| 3811 | try { |
| 3812 | int slotId = getSlotIndex(subId); |
| 3813 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3814 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3815 | + subId + "'"); |
| 3816 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3817 | } |
| 3818 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3819 | transportType, aBoolean -> { |
| 3820 | try { |
| 3821 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3822 | } catch (RemoteException e) { |
| 3823 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3824 | + "running. Ignore"); |
| 3825 | } |
| 3826 | }); |
| 3827 | } finally { |
| 3828 | Binder.restoreCallingIdentity(token); |
| 3829 | } |
| 3830 | } |
| 3831 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3832 | /** |
| 3833 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3834 | * @param subId The subscription to use to check the configuration. |
| 3835 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3836 | @Override |
| 3837 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3838 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3839 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3840 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3841 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3842 | final long token = Binder.clearCallingIdentity(); |
| 3843 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3844 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3845 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3846 | } catch (ImsException e) { |
| 3847 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3848 | } finally { |
| 3849 | Binder.restoreCallingIdentity(token); |
| 3850 | } |
| 3851 | } |
| 3852 | |
| 3853 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3854 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3855 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3856 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3857 | final long identity = Binder.clearCallingIdentity(); |
| 3858 | try { |
| 3859 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3860 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3861 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3862 | } catch (ImsException e) { |
| 3863 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3864 | } finally { |
| 3865 | Binder.restoreCallingIdentity(identity); |
| 3866 | } |
| 3867 | } |
| 3868 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3869 | /** |
| 3870 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3871 | * @param subId The subscription to use to check the configuration. |
| 3872 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3873 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3874 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3875 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3876 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3877 | final long identity = Binder.clearCallingIdentity(); |
| 3878 | try { |
| 3879 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3880 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3881 | } catch (ImsException e) { |
| 3882 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3883 | } finally { |
| 3884 | Binder.restoreCallingIdentity(identity); |
| 3885 | } |
| 3886 | } |
| 3887 | |
| 3888 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3889 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3890 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3891 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3892 | final long identity = Binder.clearCallingIdentity(); |
| 3893 | try { |
| 3894 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3895 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3896 | } catch (ImsException e) { |
| 3897 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3898 | } finally { |
| 3899 | Binder.restoreCallingIdentity(identity); |
| 3900 | } |
| 3901 | } |
| 3902 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3903 | /** |
| 3904 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3905 | * @param subId The subscription to use to check the configuration. |
| 3906 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3907 | @Override |
| 3908 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3909 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3910 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3911 | final long identity = Binder.clearCallingIdentity(); |
| 3912 | try { |
| 3913 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3914 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3915 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3916 | } catch (ImsException e) { |
| 3917 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3918 | } finally { |
| 3919 | Binder.restoreCallingIdentity(identity); |
| 3920 | } |
| 3921 | } |
| 3922 | |
| 3923 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3924 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3925 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3926 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3927 | final long identity = Binder.clearCallingIdentity(); |
| 3928 | try { |
| 3929 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3930 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3931 | } catch (ImsException e) { |
| 3932 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3933 | } finally { |
| 3934 | Binder.restoreCallingIdentity(identity); |
| 3935 | } |
| 3936 | } |
| 3937 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3938 | /** |
| 3939 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3940 | * @param subId The subscription to use to check the configuration. |
| 3941 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3942 | @Override |
| 3943 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3944 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3945 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3946 | final long identity = Binder.clearCallingIdentity(); |
| 3947 | try { |
| 3948 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3949 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3950 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3951 | } catch (ImsException e) { |
| 3952 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3953 | } finally { |
| 3954 | Binder.restoreCallingIdentity(identity); |
| 3955 | } |
| 3956 | } |
| 3957 | |
| 3958 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3959 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3960 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3961 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3962 | final long identity = Binder.clearCallingIdentity(); |
| 3963 | try { |
| 3964 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3965 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3966 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3967 | } catch (ImsException e) { |
| 3968 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3969 | } finally { |
| 3970 | Binder.restoreCallingIdentity(identity); |
| 3971 | } |
| 3972 | } |
| 3973 | |
| 3974 | @Override |
| 3975 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3976 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3977 | "setVoWiFiNonPersistent"); |
| 3978 | final long identity = Binder.clearCallingIdentity(); |
| 3979 | try { |
| 3980 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3981 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3982 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3983 | } catch (ImsException e) { |
| 3984 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3985 | } finally { |
| 3986 | Binder.restoreCallingIdentity(identity); |
| 3987 | } |
| 3988 | } |
| 3989 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3990 | /** |
| 3991 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3992 | * @param subId The subscription to use to check the configuration. |
| 3993 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3994 | @Override |
| 3995 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3996 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3997 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3998 | final long identity = Binder.clearCallingIdentity(); |
| 3999 | try { |
| 4000 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4001 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4002 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4003 | } catch (ImsException e) { |
| 4004 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4005 | } finally { |
| 4006 | Binder.restoreCallingIdentity(identity); |
| 4007 | } |
| 4008 | } |
| 4009 | |
| 4010 | @Override |
| 4011 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4012 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4013 | "setVoWiFiModeSetting"); |
| 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 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4018 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
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 | |
| 4026 | @Override |
| 4027 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4028 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4029 | final long identity = Binder.clearCallingIdentity(); |
| 4030 | try { |
| 4031 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4032 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4033 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4034 | } catch (ImsException e) { |
| 4035 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4036 | } finally { |
| 4037 | Binder.restoreCallingIdentity(identity); |
| 4038 | } |
| 4039 | } |
| 4040 | |
| 4041 | @Override |
| 4042 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4043 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4044 | "setVoWiFiRoamingModeSetting"); |
| 4045 | final long identity = Binder.clearCallingIdentity(); |
| 4046 | try { |
| 4047 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4048 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4049 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4050 | } catch (ImsException e) { |
| 4051 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4052 | } finally { |
| 4053 | Binder.restoreCallingIdentity(identity); |
| 4054 | } |
| 4055 | } |
| 4056 | |
| 4057 | @Override |
| 4058 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4059 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4060 | "setRttCapabilityEnabled"); |
| 4061 | final long identity = Binder.clearCallingIdentity(); |
| 4062 | try { |
| 4063 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4064 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 4065 | } catch (ImsException e) { |
| 4066 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4067 | } finally { |
| 4068 | Binder.restoreCallingIdentity(identity); |
| 4069 | } |
| 4070 | } |
| 4071 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4072 | /** |
| 4073 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4074 | * @param subId The subscription to use to check the configuration. |
| 4075 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4076 | @Override |
| 4077 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4078 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4079 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4080 | final long identity = Binder.clearCallingIdentity(); |
| 4081 | try { |
| 4082 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4083 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4084 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4085 | } catch (ImsException e) { |
| 4086 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4087 | } finally { |
| 4088 | Binder.restoreCallingIdentity(identity); |
| 4089 | } |
| 4090 | } |
| 4091 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4092 | @Override |
| 4093 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4094 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 4095 | final long identity = Binder.clearCallingIdentity(); |
| 4096 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4097 | if (!isImsAvailableOnDevice()) { |
| 4098 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4099 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4100 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4101 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4102 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4103 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4104 | } catch (ImsException e) { |
| 4105 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4106 | } finally { |
| 4107 | Binder.restoreCallingIdentity(identity); |
| 4108 | } |
| 4109 | } |
| 4110 | |
| 4111 | @Override |
| 4112 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4113 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 4114 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4115 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4116 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4117 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4118 | try { |
| 4119 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4120 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4121 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4122 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4123 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4124 | + "is inactive, ignoring unregister."); |
| 4125 | // If the subscription is no longer active, just return, since the callback will already |
| 4126 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4127 | } finally { |
| 4128 | Binder.restoreCallingIdentity(identity); |
| 4129 | } |
| 4130 | } |
| 4131 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4132 | |
| 4133 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4134 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4135 | message); |
| 4136 | } |
| 4137 | |
| 4138 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4139 | boolean isMmtelCapability) { |
| 4140 | Phone phone = getPhone(subId); |
| 4141 | if (phone == null) { |
| 4142 | loge("phone instance null for subid " + subId); |
| 4143 | return false; |
| 4144 | } |
| 4145 | if (isMmtelCapability) { |
| 4146 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4147 | return false; |
| 4148 | } |
| 4149 | } else { |
| 4150 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4151 | return false; |
| 4152 | } |
| 4153 | } |
| 4154 | return true; |
| 4155 | } |
| 4156 | |
| 4157 | @Override |
| 4158 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4159 | boolean isProvisioned) { |
| 4160 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4161 | |
| 4162 | final long identity = Binder.clearCallingIdentity(); |
| 4163 | try { |
| 4164 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4165 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4166 | return; |
| 4167 | } |
| 4168 | |
| 4169 | // this capability requires provisioning, route to the correct API. |
| 4170 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4171 | switch (capability) { |
| 4172 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4173 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4174 | ims.setEabProvisioned(isProvisioned); |
| 4175 | break; |
| 4176 | default: { |
| 4177 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4178 | + "rcs capability '" + capability + "', which does not require " |
| 4179 | + "provisioning."); |
| 4180 | } |
| 4181 | } |
| 4182 | } finally { |
| 4183 | Binder.restoreCallingIdentity(identity); |
| 4184 | } |
| 4185 | |
| 4186 | } |
| 4187 | |
| 4188 | |
| 4189 | @Override |
| 4190 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4191 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4192 | final long identity = Binder.clearCallingIdentity(); |
| 4193 | try { |
| 4194 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4195 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4196 | return true; |
| 4197 | } |
| 4198 | |
| 4199 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4200 | switch (capability) { |
| 4201 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4202 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4203 | return ims.isEabProvisionedOnDevice(); |
| 4204 | |
| 4205 | default: { |
| 4206 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4207 | + "capability '" + capability + "', which does not require " |
| 4208 | + "provisioning."); |
| 4209 | } |
| 4210 | } |
| 4211 | |
| 4212 | } finally { |
| 4213 | Binder.restoreCallingIdentity(identity); |
| 4214 | } |
| 4215 | } |
| 4216 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4217 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4218 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4219 | boolean isProvisioned) { |
| 4220 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4221 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4222 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4223 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4224 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4225 | final long identity = Binder.clearCallingIdentity(); |
| 4226 | try { |
| 4227 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4228 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4229 | return; |
| 4230 | } |
| 4231 | |
| 4232 | // this capability requires provisioning, route to the correct API. |
| 4233 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4234 | switch (capability) { |
| 4235 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4236 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4237 | ims.setVolteProvisioned(isProvisioned); |
| 4238 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4239 | ims.setWfcProvisioned(isProvisioned); |
| 4240 | } |
| 4241 | break; |
| 4242 | } |
| 4243 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4244 | // There is currently no difference in VT provisioning type. |
| 4245 | ims.setVtProvisioned(isProvisioned); |
| 4246 | break; |
| 4247 | } |
| 4248 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4249 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4250 | // change the capability of the feature instead if needed. |
| 4251 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4252 | == isProvisioned) { |
| 4253 | // No change in provisioning. |
| 4254 | return; |
| 4255 | } |
| 4256 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4257 | try { |
| 4258 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4259 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4260 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4261 | + ", Exception" + e.getMessage()); |
| 4262 | } |
| 4263 | break; |
| 4264 | } |
| 4265 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4266 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4267 | + "MmTel capability '" + capability + "', which does not require " |
| 4268 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4269 | } |
| 4270 | } |
| 4271 | |
| 4272 | } finally { |
| 4273 | Binder.restoreCallingIdentity(identity); |
| 4274 | } |
| 4275 | } |
| 4276 | |
| 4277 | @Override |
| 4278 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4279 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4280 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4281 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4282 | } |
| 4283 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4284 | final long identity = Binder.clearCallingIdentity(); |
| 4285 | try { |
| 4286 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4287 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4288 | return true; |
| 4289 | } |
| 4290 | |
| 4291 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4292 | switch (capability) { |
| 4293 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4294 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4295 | return ims.isVolteProvisionedOnDevice(); |
| 4296 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4297 | return ims.isWfcProvisionedOnDevice(); |
| 4298 | } |
| 4299 | // This should never happen, since we are checking tech above to make sure it |
| 4300 | // is either LTE or IWLAN. |
| 4301 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4302 | + "capability."); |
| 4303 | } |
| 4304 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4305 | // There is currently no difference in VT provisioning type. |
| 4306 | return ims.isVtProvisionedOnDevice(); |
| 4307 | } |
| 4308 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4309 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4310 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4311 | } |
| 4312 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4313 | throw new IllegalArgumentException( |
| 4314 | "Tried to get provisioning for MmTel capability '" + capability |
| 4315 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4316 | } |
| 4317 | } |
| 4318 | |
| 4319 | } finally { |
| 4320 | Binder.restoreCallingIdentity(identity); |
| 4321 | } |
| 4322 | } |
| 4323 | |
| 4324 | @Override |
| 4325 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4326 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4327 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4328 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4329 | } |
| 4330 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4331 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4332 | return (provisionedBits & capability) > 0; |
| 4333 | } |
| 4334 | |
| 4335 | @Override |
| 4336 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4337 | boolean isProvisioned) { |
| 4338 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4339 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4340 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4341 | } |
| 4342 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4343 | "setProvisioningStatusForCapability"); |
| 4344 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4345 | // If the current provisioning status for capability already matches isProvisioned, |
| 4346 | // do nothing. |
| 4347 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4348 | return; |
| 4349 | } |
| 4350 | if (isProvisioned) { |
| 4351 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4352 | } else { |
| 4353 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4354 | } |
| 4355 | } |
| 4356 | |
| 4357 | /** |
| 4358 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4359 | * technology. The bitfield should mirror the bitfield defined by |
| 4360 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4361 | */ |
| 4362 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4363 | String key = getMmTelProvisioningKey(subId, tech); |
| 4364 | // Default is no capabilities are provisioned. |
| 4365 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4366 | } |
| 4367 | |
| 4368 | /** |
| 4369 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4370 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4371 | * technology specified. |
| 4372 | * |
| 4373 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4374 | */ |
| 4375 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4376 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4377 | String key = getMmTelProvisioningKey(subId, tech); |
| 4378 | editor.putInt(key, newField); |
| 4379 | editor.commit(); |
| 4380 | } |
| 4381 | |
| 4382 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4383 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4384 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4385 | } |
| 4386 | |
| 4387 | /** |
| 4388 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4389 | * carrier associated with the subscription id. |
| 4390 | */ |
| 4391 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4392 | int capability) { |
| 4393 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4394 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4395 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4396 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4397 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4398 | false); |
| 4399 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4400 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4401 | |
| 4402 | // First check to make sure that the capability requires provisioning. |
| 4403 | switch (capability) { |
| 4404 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4405 | // intentional fallthrough |
| 4406 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4407 | if (requireVoiceVtProvisioning) { |
| 4408 | // Voice and Video requires provisioning |
| 4409 | return true; |
| 4410 | } |
| 4411 | break; |
| 4412 | } |
| 4413 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4414 | if (requireUtProvisioning) { |
| 4415 | // UT requires provisioning |
| 4416 | return true; |
| 4417 | } |
| 4418 | break; |
| 4419 | } |
| 4420 | } |
| 4421 | return false; |
| 4422 | } |
| 4423 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4424 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4425 | int capability) { |
| 4426 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4427 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4428 | |
| 4429 | boolean requireRcsProvisioning = c.getBoolean( |
| 4430 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4431 | |
| 4432 | // First check to make sure that the capability requires provisioning. |
| 4433 | switch (capability) { |
| 4434 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4435 | // intentional fallthrough |
| 4436 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4437 | if (requireRcsProvisioning) { |
| 4438 | // OPTION or PRESENCE requires provisioning |
| 4439 | return true; |
| 4440 | } |
| 4441 | break; |
| 4442 | } |
| 4443 | } |
| 4444 | return false; |
| 4445 | } |
| 4446 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4447 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4448 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4449 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4450 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4451 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4452 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4453 | final long identity = Binder.clearCallingIdentity(); |
| 4454 | try { |
| 4455 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4456 | int slotId = getSlotIndex(subId); |
| 4457 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4458 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4459 | + subId + "' for key:" + key); |
| 4460 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4461 | } |
| 4462 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4463 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4464 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4465 | + subId + "' for key:" + key); |
| 4466 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4467 | } finally { |
| 4468 | Binder.restoreCallingIdentity(identity); |
| 4469 | } |
| 4470 | } |
| 4471 | |
| 4472 | @Override |
| 4473 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4474 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4475 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4476 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4477 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4478 | final long identity = Binder.clearCallingIdentity(); |
| 4479 | try { |
| 4480 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4481 | int slotId = getSlotIndex(subId); |
| 4482 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4483 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4484 | + subId + "' for key:" + key); |
| 4485 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4486 | } |
| 4487 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4488 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4489 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4490 | + subId + "' for key:" + key); |
| 4491 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4492 | } finally { |
| 4493 | Binder.restoreCallingIdentity(identity); |
| 4494 | } |
| 4495 | } |
| 4496 | |
| 4497 | @Override |
| 4498 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4499 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4500 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4501 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4502 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4503 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4504 | final long identity = Binder.clearCallingIdentity(); |
| 4505 | try { |
| 4506 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4507 | int slotId = getSlotIndex(subId); |
| 4508 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4509 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4510 | + subId + "' for key:" + key); |
| 4511 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4512 | } |
| 4513 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4514 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4515 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4516 | + "' for key:" + key); |
| 4517 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4518 | } finally { |
| 4519 | Binder.restoreCallingIdentity(identity); |
| 4520 | } |
| 4521 | } |
| 4522 | |
| 4523 | @Override |
| 4524 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4525 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4526 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4527 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4528 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4529 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4530 | final long identity = Binder.clearCallingIdentity(); |
| 4531 | try { |
| 4532 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4533 | int slotId = getSlotIndex(subId); |
| 4534 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4535 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4536 | + subId + "' for key:" + key); |
| 4537 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4538 | } |
| 4539 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4540 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4541 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4542 | + "' for key:" + key); |
| 4543 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4544 | } finally { |
| 4545 | Binder.restoreCallingIdentity(identity); |
| 4546 | } |
| 4547 | } |
| 4548 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4549 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4550 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4551 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4552 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4553 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4554 | } |
| 4555 | return slotId; |
| 4556 | } |
| 4557 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4558 | private int getSlotIndex(int subId) { |
| 4559 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4560 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4561 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4562 | } |
| 4563 | return slotId; |
| 4564 | } |
| 4565 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4566 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4567 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4568 | */ |
| 4569 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4570 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4571 | String callingFeatureId) { |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4572 | final int targetSdk = getTargetSdk(callingPackage); |
| 4573 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4574 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4575 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4576 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4577 | mApp, subId, callingPackage, callingFeatureId, |
| 4578 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4579 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4580 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4581 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4582 | final long identity = Binder.clearCallingIdentity(); |
| 4583 | try { |
| 4584 | final Phone phone = getPhone(subId); |
| 4585 | if (phone != null) { |
| 4586 | return phone.getServiceState().getDataNetworkType(); |
| 4587 | } else { |
| 4588 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4589 | } |
| 4590 | } finally { |
| 4591 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4592 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4593 | } |
| 4594 | |
| 4595 | /** |
| 4596 | * Returns the data network type |
| 4597 | */ |
| 4598 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4599 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4600 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4601 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4602 | } |
| 4603 | |
| 4604 | /** |
| 4605 | * Returns the data network type for a subId |
| 4606 | */ |
| 4607 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4608 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4609 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4610 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4611 | mApp, subId, callingPackage, callingFeatureId, |
| 4612 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4613 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4614 | } |
| 4615 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4616 | final long identity = Binder.clearCallingIdentity(); |
| 4617 | try { |
| 4618 | final Phone phone = getPhone(subId); |
| 4619 | if (phone != null) { |
| 4620 | return phone.getServiceState().getDataNetworkType(); |
| 4621 | } else { |
| 4622 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4623 | } |
| 4624 | } finally { |
| 4625 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4626 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4627 | } |
| 4628 | |
| 4629 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4630 | * Returns the Voice network type for a subId |
| 4631 | */ |
| 4632 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4633 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4634 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4635 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4636 | mApp, subId, callingPackage, callingFeatureId, |
| 4637 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4638 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4639 | } |
| 4640 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4641 | final long identity = Binder.clearCallingIdentity(); |
| 4642 | try { |
| 4643 | final Phone phone = getPhone(subId); |
| 4644 | if (phone != null) { |
| 4645 | return phone.getServiceState().getVoiceNetworkType(); |
| 4646 | } else { |
| 4647 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4648 | } |
| 4649 | } finally { |
| 4650 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4651 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4652 | } |
| 4653 | |
| 4654 | /** |
| 4655 | * @return true if a ICC card is present |
| 4656 | */ |
| 4657 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4658 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4659 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4660 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4661 | } |
| 4662 | |
| 4663 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4664 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4665 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4666 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4667 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4668 | final long identity = Binder.clearCallingIdentity(); |
| 4669 | try { |
| 4670 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4671 | if (phone != null) { |
| 4672 | return phone.getIccCard().hasIccCard(); |
| 4673 | } else { |
| 4674 | return false; |
| 4675 | } |
| 4676 | } finally { |
| 4677 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4678 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4679 | } |
| 4680 | |
| 4681 | /** |
| 4682 | * Return if the current radio is LTE on CDMA. This |
| 4683 | * is a tri-state return value as for a period of time |
| 4684 | * the mode may be unknown. |
| 4685 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4686 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4687 | * @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] | 4688 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4689 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4690 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4691 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4692 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4693 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4694 | } |
| 4695 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4696 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4697 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4698 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4699 | try { |
| 4700 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4701 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4702 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4703 | } |
| 4704 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4705 | final long identity = Binder.clearCallingIdentity(); |
| 4706 | try { |
| 4707 | final Phone phone = getPhone(subId); |
| 4708 | if (phone == null) { |
| 4709 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4710 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 4711 | return TelephonyProperties.lte_on_cdma_device() |
| 4712 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4713 | } |
| 4714 | } finally { |
| 4715 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4716 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4717 | } |
| 4718 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4719 | /** |
| 4720 | * {@hide} |
| 4721 | * Returns Default subId, 0 in the case of single standby. |
| 4722 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4723 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4724 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4725 | } |
| 4726 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4727 | private int getSlotForDefaultSubscription() { |
| 4728 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4729 | } |
| 4730 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4731 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4732 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4733 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4734 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4735 | private boolean isActiveSubscription(int subId) { |
| 4736 | return mSubscriptionController.isActiveSubId(subId); |
| 4737 | } |
| 4738 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4739 | /** |
| 4740 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4741 | */ |
| 4742 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4743 | final long identity = Binder.clearCallingIdentity(); |
| 4744 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4745 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4746 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4747 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4748 | } finally { |
| 4749 | Binder.restoreCallingIdentity(identity); |
| 4750 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4751 | } |
| 4752 | |
| 4753 | /** |
| 4754 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4755 | */ |
| 4756 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4757 | final long identity = Binder.clearCallingIdentity(); |
| 4758 | try { |
| 4759 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4760 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4761 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4762 | } finally { |
| 4763 | Binder.restoreCallingIdentity(identity); |
| 4764 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4765 | } |
| 4766 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4767 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4768 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4769 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4770 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4771 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4772 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4773 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4774 | if (phoneId == -1) { |
| 4775 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4776 | + " does not correspond to an active phone"); |
| 4777 | } |
| 4778 | return PhoneFactory.getPhone(phoneId); |
| 4779 | } |
| 4780 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4781 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4782 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4783 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4784 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4785 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4786 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4787 | if (DBG) { |
| 4788 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4789 | } |
| 4790 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4791 | p2); |
| 4792 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4793 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4794 | |
| 4795 | @Override |
| 4796 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4797 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4798 | enforceModifyPermission(); |
| 4799 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4800 | if (DBG) { |
| 4801 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4802 | } |
| 4803 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4804 | callingPackage, aid, p2); |
| 4805 | } |
| 4806 | |
| 4807 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4808 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4809 | final long identity = Binder.clearCallingIdentity(); |
| 4810 | try { |
| 4811 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4812 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4813 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4814 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4815 | if (bestComponent == null |
| 4816 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4817 | loge("The calling package is not allowed to access ISD-R."); |
| 4818 | throw new SecurityException( |
| 4819 | "The calling package is not allowed to access ISD-R."); |
| 4820 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4821 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4822 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4823 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4824 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4825 | null /* workSource */); |
| 4826 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4827 | return response; |
| 4828 | } finally { |
| 4829 | Binder.restoreCallingIdentity(identity); |
| 4830 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4831 | } |
| 4832 | |
| 4833 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4834 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4835 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4836 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4837 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4838 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4839 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4840 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4841 | @Override |
| 4842 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4843 | enforceModifyPermission(); |
| 4844 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4845 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4846 | channel); |
| 4847 | } |
| 4848 | |
| 4849 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4850 | final long identity = Binder.clearCallingIdentity(); |
| 4851 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4852 | if (channel < 0) { |
| 4853 | return false; |
| 4854 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4855 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4856 | null /* workSource */); |
| 4857 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4858 | return success; |
| 4859 | } finally { |
| 4860 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4861 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4862 | } |
| 4863 | |
| 4864 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4865 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4866 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4867 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4868 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4869 | if (DBG) { |
| 4870 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4871 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4872 | + p3 + " data=" + data); |
| 4873 | } |
| 4874 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4875 | command, p1, p2, p3, data); |
| 4876 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4877 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4878 | @Override |
| 4879 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4880 | int command, int p1, int p2, int p3, String data) { |
| 4881 | enforceModifyPermission(); |
| 4882 | if (DBG) { |
| 4883 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4884 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4885 | + p3 + " data=" + data); |
| 4886 | } |
| 4887 | return iccTransmitApduLogicalChannelWithPermission( |
| 4888 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4889 | data); |
| 4890 | } |
| 4891 | |
| 4892 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4893 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4894 | final long identity = Binder.clearCallingIdentity(); |
| 4895 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4896 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4897 | return ""; |
| 4898 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4899 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4900 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4901 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4902 | null /* workSource */); |
| 4903 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4904 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4905 | // Append the returned status code to the end of the response payload. |
| 4906 | String s = Integer.toHexString( |
| 4907 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4908 | if (response.payload != null) { |
| 4909 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4910 | } |
| 4911 | return s; |
| 4912 | } finally { |
| 4913 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4914 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4915 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4916 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4917 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4918 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4919 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4920 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4921 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4922 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4923 | if (DBG) { |
| 4924 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4925 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4926 | } |
| 4927 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4928 | cla, command, p1, p2, p3, data); |
| 4929 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4930 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4931 | @Override |
| 4932 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4933 | int command, int p1, int p2, int p3, String data) { |
| 4934 | enforceModifyPermission(); |
| 4935 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4936 | if (DBG) { |
| 4937 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4938 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4939 | + " data=" + data); |
| 4940 | } |
| 4941 | |
| 4942 | return iccTransmitApduBasicChannelWithPermission( |
| 4943 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4944 | p2, p3, data); |
| 4945 | } |
| 4946 | |
| 4947 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4948 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4949 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4950 | final long identity = Binder.clearCallingIdentity(); |
| 4951 | try { |
| 4952 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4953 | && TextUtils.equals(ISDR_AID, data)) { |
| 4954 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4955 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4956 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4957 | if (bestComponent == null |
| 4958 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4959 | loge("The calling package is not allowed to select ISD-R."); |
| 4960 | throw new SecurityException( |
| 4961 | "The calling package is not allowed to select ISD-R."); |
| 4962 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4963 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4964 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4965 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4966 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4967 | null /* workSource */); |
| 4968 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4969 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4970 | // Append the returned status code to the end of the response payload. |
| 4971 | String s = Integer.toHexString( |
| 4972 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4973 | if (response.payload != null) { |
| 4974 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4975 | } |
| 4976 | return s; |
| 4977 | } finally { |
| 4978 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4979 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4980 | } |
| 4981 | |
| 4982 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4983 | 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] | 4984 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4985 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4986 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4987 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4988 | final long identity = Binder.clearCallingIdentity(); |
| 4989 | try { |
| 4990 | if (DBG) { |
| 4991 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4992 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4993 | } |
| 4994 | |
| 4995 | IccIoResult response = |
| 4996 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4997 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4998 | subId); |
| 4999 | |
| 5000 | if (DBG) { |
| 5001 | log("Exchange SIM_IO [R]" + response); |
| 5002 | } |
| 5003 | |
| 5004 | byte[] result = null; |
| 5005 | int length = 2; |
| 5006 | if (response.payload != null) { |
| 5007 | length = 2 + response.payload.length; |
| 5008 | result = new byte[length]; |
| 5009 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5010 | } else { |
| 5011 | result = new byte[length]; |
| 5012 | } |
| 5013 | |
| 5014 | result[length - 1] = (byte) response.sw2; |
| 5015 | result[length - 2] = (byte) response.sw1; |
| 5016 | return result; |
| 5017 | } finally { |
| 5018 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5019 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5020 | } |
| 5021 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5022 | /** |
| 5023 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5024 | * on a particular subscription |
| 5025 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5026 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5027 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5028 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5029 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5030 | return null; |
| 5031 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5032 | |
| 5033 | final long identity = Binder.clearCallingIdentity(); |
| 5034 | try { |
| 5035 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5036 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5037 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5038 | return null; |
| 5039 | } |
| 5040 | Object response = sendRequest( |
| 5041 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5042 | if (response instanceof String[]) { |
| 5043 | return (String[]) response; |
| 5044 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5045 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5046 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5047 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5048 | } finally { |
| 5049 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5050 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5051 | } |
| 5052 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5053 | /** |
| 5054 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5055 | * subscription. |
| 5056 | * |
| 5057 | * @param subId the id of the subscription. |
| 5058 | * @param appType the uicc app type, must be USIM or SIM. |
| 5059 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5060 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5061 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5062 | * @return number of fplmns that is successfully written to the SIM. |
| 5063 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5064 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5065 | String callingFeatureId) { |
| 5066 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 5067 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5068 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 5069 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 5070 | } |
| 5071 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5072 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5073 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5074 | } |
| 5075 | if (fplmns == null) { |
| 5076 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5077 | } |
| 5078 | for (String fplmn : fplmns) { |
| 5079 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5080 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5081 | } |
| 5082 | } |
| 5083 | final long identity = Binder.clearCallingIdentity(); |
| 5084 | try { |
| 5085 | Object response = sendRequest( |
| 5086 | CMD_SET_FORBIDDEN_PLMNS, |
| 5087 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5088 | subId); |
| 5089 | return (int) response; |
| 5090 | } finally { |
| 5091 | Binder.restoreCallingIdentity(identity); |
| 5092 | } |
| 5093 | } |
| 5094 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5095 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5096 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5097 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5098 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5099 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5100 | final long identity = Binder.clearCallingIdentity(); |
| 5101 | try { |
| 5102 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5103 | if (response.payload == null) { |
| 5104 | return ""; |
| 5105 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5106 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5107 | // Append the returned status code to the end of the response payload. |
| 5108 | String s = Integer.toHexString( |
| 5109 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5110 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5111 | return s; |
| 5112 | } finally { |
| 5113 | Binder.restoreCallingIdentity(identity); |
| 5114 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5115 | } |
| 5116 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5117 | /** |
| 5118 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5119 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5120 | * |
| 5121 | * @param itemID the ID of the item to read |
| 5122 | * @return the NV item as a String, or null on error. |
| 5123 | */ |
| 5124 | @Override |
| 5125 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5126 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5127 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5128 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5129 | |
| 5130 | final long identity = Binder.clearCallingIdentity(); |
| 5131 | try { |
| 5132 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5133 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5134 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5135 | return value; |
| 5136 | } finally { |
| 5137 | Binder.restoreCallingIdentity(identity); |
| 5138 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5139 | } |
| 5140 | |
| 5141 | /** |
| 5142 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5143 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5144 | * |
| 5145 | * @param itemID the ID of the item to read |
| 5146 | * @param itemValue the value to write, as a String |
| 5147 | * @return true on success; false on any failure |
| 5148 | */ |
| 5149 | @Override |
| 5150 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5151 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5152 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5153 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5154 | |
| 5155 | final long identity = Binder.clearCallingIdentity(); |
| 5156 | try { |
| 5157 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5158 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5159 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5160 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5161 | return success; |
| 5162 | } finally { |
| 5163 | Binder.restoreCallingIdentity(identity); |
| 5164 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5165 | } |
| 5166 | |
| 5167 | /** |
| 5168 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5169 | * Used for device configuration by some CDMA operators. |
| 5170 | * |
| 5171 | * @param preferredRoamingList byte array containing the new PRL |
| 5172 | * @return true on success; false on any failure |
| 5173 | */ |
| 5174 | @Override |
| 5175 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5176 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5177 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5178 | |
| 5179 | final long identity = Binder.clearCallingIdentity(); |
| 5180 | try { |
| 5181 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5182 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5183 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5184 | return success; |
| 5185 | } finally { |
| 5186 | Binder.restoreCallingIdentity(identity); |
| 5187 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5188 | } |
| 5189 | |
| 5190 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5191 | * 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] | 5192 | * Used for device configuration by some CDMA operators. |
| 5193 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5194 | * @param slotIndex - device slot. |
| 5195 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5196 | * @return true on success; false on any failure |
| 5197 | */ |
| 5198 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5199 | public boolean resetModemConfig(int slotIndex) { |
| 5200 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5201 | if (phone != null) { |
| 5202 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5203 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5204 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5205 | final long identity = Binder.clearCallingIdentity(); |
| 5206 | try { |
| 5207 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5208 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5209 | return success; |
| 5210 | } finally { |
| 5211 | Binder.restoreCallingIdentity(identity); |
| 5212 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5213 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5214 | return false; |
| 5215 | } |
| 5216 | |
| 5217 | /** |
| 5218 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5219 | * |
| 5220 | * @param slotIndex - device slot. |
| 5221 | * |
| 5222 | * @return true on success; false on any failure |
| 5223 | */ |
| 5224 | @Override |
| 5225 | public boolean rebootModem(int slotIndex) { |
| 5226 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5227 | if (phone != null) { |
| 5228 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5229 | mApp, phone.getSubId(), "rebootModem"); |
| 5230 | |
| 5231 | final long identity = Binder.clearCallingIdentity(); |
| 5232 | try { |
| 5233 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5234 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5235 | return success; |
| 5236 | } finally { |
| 5237 | Binder.restoreCallingIdentity(identity); |
| 5238 | } |
| 5239 | } |
| 5240 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5241 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5242 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5243 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5244 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5245 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5246 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5247 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5248 | return new String[0]; |
| 5249 | } |
| 5250 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5251 | final long identity = Binder.clearCallingIdentity(); |
| 5252 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5253 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5254 | } finally { |
| 5255 | Binder.restoreCallingIdentity(identity); |
| 5256 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5257 | } |
| 5258 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5259 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5260 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5261 | * {@link #disableIms(int)}. |
| 5262 | * @param slotIndex device slot. |
| 5263 | */ |
| 5264 | public void resetIms(int slotIndex) { |
| 5265 | enforceModifyPermission(); |
| 5266 | |
| 5267 | final long identity = Binder.clearCallingIdentity(); |
| 5268 | try { |
| 5269 | if (mImsResolver == null) { |
| 5270 | // may happen if the does not support IMS. |
| 5271 | return; |
| 5272 | } |
| 5273 | mImsResolver.disableIms(slotIndex); |
| 5274 | mImsResolver.enableIms(slotIndex); |
| 5275 | } finally { |
| 5276 | Binder.restoreCallingIdentity(identity); |
| 5277 | } |
| 5278 | } |
| 5279 | |
| 5280 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5281 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5282 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5283 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5284 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5285 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5286 | |
| 5287 | final long identity = Binder.clearCallingIdentity(); |
| 5288 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5289 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5290 | // may happen if the device does not support IMS. |
| 5291 | return; |
| 5292 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5293 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5294 | } finally { |
| 5295 | Binder.restoreCallingIdentity(identity); |
| 5296 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5297 | } |
| 5298 | |
| 5299 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5300 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5301 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5302 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5303 | public void disableIms(int slotId) { |
| 5304 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5305 | |
| 5306 | final long identity = Binder.clearCallingIdentity(); |
| 5307 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5308 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5309 | // may happen if the device does not support IMS. |
| 5310 | return; |
| 5311 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5312 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5313 | } finally { |
| 5314 | Binder.restoreCallingIdentity(identity); |
| 5315 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5316 | } |
| 5317 | |
| 5318 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5319 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5320 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5321 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5322 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5323 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5324 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5325 | |
| 5326 | final long identity = Binder.clearCallingIdentity(); |
| 5327 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5328 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5329 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5330 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5331 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5332 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5333 | } finally { |
| 5334 | Binder.restoreCallingIdentity(identity); |
| 5335 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5336 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5337 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5338 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5339 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5340 | @Override |
| 5341 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5342 | enforceModifyPermission(); |
| 5343 | |
| 5344 | final long identity = Binder.clearCallingIdentity(); |
| 5345 | try { |
| 5346 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5347 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5348 | } finally { |
| 5349 | Binder.restoreCallingIdentity(identity); |
| 5350 | } |
| 5351 | } |
| 5352 | |
| 5353 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5354 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5355 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5356 | */ |
| 5357 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5358 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5359 | |
| 5360 | final long identity = Binder.clearCallingIdentity(); |
| 5361 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5362 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5363 | // may happen if the device does not support IMS. |
| 5364 | return null; |
| 5365 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5366 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5367 | } finally { |
| 5368 | Binder.restoreCallingIdentity(identity); |
| 5369 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5370 | } |
| 5371 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5372 | /** |
| 5373 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5374 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5375 | */ |
| 5376 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5377 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5378 | |
| 5379 | final long identity = Binder.clearCallingIdentity(); |
| 5380 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5381 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5382 | // may happen if the device does not support IMS. |
| 5383 | return null; |
| 5384 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5385 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5386 | } finally { |
| 5387 | Binder.restoreCallingIdentity(identity); |
| 5388 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5389 | } |
| 5390 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5391 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5392 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5393 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5394 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5395 | * @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] | 5396 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5397 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5398 | * @param packageName The name of the package that the current configuration will be replaced |
| 5399 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5400 | * @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] | 5401 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5402 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5403 | int[] featureTypes, String packageName) { |
| 5404 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5405 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5406 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5407 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5408 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5409 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5410 | final long identity = Binder.clearCallingIdentity(); |
| 5411 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5412 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5413 | // may happen if the device does not support IMS. |
| 5414 | return false; |
| 5415 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5416 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5417 | for (int featureType : featureTypes) { |
| 5418 | featureConfig.put(featureType, packageName); |
| 5419 | } |
| 5420 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5421 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5422 | } finally { |
| 5423 | Binder.restoreCallingIdentity(identity); |
| 5424 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5425 | } |
| 5426 | |
| 5427 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5428 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5429 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5430 | * |
| 5431 | * This should only be used for testing. |
| 5432 | * |
| 5433 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5434 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5435 | */ |
| 5436 | @Override |
| 5437 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5438 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5439 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5440 | "clearCarrierImsServiceOverride"); |
| 5441 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5442 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5443 | "clearCarrierImsServiceOverride"); |
| 5444 | |
| 5445 | final long identity = Binder.clearCallingIdentity(); |
| 5446 | try { |
| 5447 | if (mImsResolver == null) { |
| 5448 | // may happen if the device does not support IMS. |
| 5449 | return false; |
| 5450 | } |
| 5451 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5452 | } finally { |
| 5453 | Binder.restoreCallingIdentity(identity); |
| 5454 | } |
| 5455 | } |
| 5456 | |
| 5457 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5458 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5459 | * |
| 5460 | * @param slotId The slot that the ImsService is associated with. |
| 5461 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5462 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5463 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5464 | * @return the package name of the ImsService configuration. |
| 5465 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5466 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5467 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5468 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5469 | TelephonyPermissions |
| 5470 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5471 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5472 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5473 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5474 | final long identity = Binder.clearCallingIdentity(); |
| 5475 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5476 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5477 | // may happen if the device does not support IMS. |
| 5478 | return ""; |
| 5479 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5480 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5481 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5482 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5483 | } finally { |
| 5484 | Binder.restoreCallingIdentity(identity); |
| 5485 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5486 | } |
| 5487 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5488 | /** |
| 5489 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5490 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5491 | * @param callback A callback with an integer containing the |
| 5492 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5493 | */ |
| 5494 | @Override |
| 5495 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5496 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5497 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5498 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5499 | "IMS not available on device."); |
| 5500 | } |
| 5501 | final long token = Binder.clearCallingIdentity(); |
| 5502 | try { |
| 5503 | int slotId = getSlotIndex(subId); |
| 5504 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5505 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5506 | + subId + "'"); |
| 5507 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5508 | } |
| 5509 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5510 | try { |
| 5511 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5512 | } catch (RemoteException e) { |
| 5513 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5514 | + "Ignore"); |
| 5515 | } |
| 5516 | }); |
| 5517 | } finally { |
| 5518 | Binder.restoreCallingIdentity(token); |
| 5519 | } |
| 5520 | } |
| 5521 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5522 | public void setImsRegistrationState(boolean registered) { |
| 5523 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5524 | |
| 5525 | final long identity = Binder.clearCallingIdentity(); |
| 5526 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5527 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5528 | } finally { |
| 5529 | Binder.restoreCallingIdentity(identity); |
| 5530 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5531 | } |
| 5532 | |
| 5533 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5534 | * Set the network selection mode to automatic. |
| 5535 | * |
| 5536 | */ |
| 5537 | @Override |
| 5538 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5539 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5540 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5541 | |
| 5542 | final long identity = Binder.clearCallingIdentity(); |
| 5543 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5544 | if (!isActiveSubscription(subId)) { |
| 5545 | return; |
| 5546 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5547 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 5548 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 5549 | } finally { |
| 5550 | Binder.restoreCallingIdentity(identity); |
| 5551 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5552 | } |
| 5553 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5554 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5555 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5556 | * |
| 5557 | * @param subId the id of the subscription. |
| 5558 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5559 | * the operator to attach to. |
| 5560 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5561 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5562 | * normal network selection next time. |
| 5563 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5564 | */ |
| 5565 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5566 | public boolean setNetworkSelectionModeManual( |
| 5567 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5568 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5569 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5570 | |
| 5571 | if (!isActiveSubscription(subId)) { |
| 5572 | return false; |
| 5573 | } |
| 5574 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5575 | final long identity = Binder.clearCallingIdentity(); |
| 5576 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5577 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5578 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5579 | if (DBG) { |
| 5580 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5581 | + " operator: " + operatorInfo); |
| 5582 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5583 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5584 | } finally { |
| 5585 | Binder.restoreCallingIdentity(identity); |
| 5586 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5587 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5588 | /** |
| 5589 | * Get the manual network selection |
| 5590 | * |
| 5591 | * @param subId the id of the subscription. |
| 5592 | * |
| 5593 | * @return the previously saved user selected PLMN |
| 5594 | */ |
| 5595 | @Override |
| 5596 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5597 | TelephonyPermissions |
| 5598 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5599 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5600 | |
| 5601 | final long identity = Binder.clearCallingIdentity(); |
| 5602 | try { |
| 5603 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5604 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5605 | } |
| 5606 | |
| 5607 | final Phone phone = getPhone(subId); |
| 5608 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5609 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5610 | } |
| 5611 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5612 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5613 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5614 | } finally { |
| 5615 | Binder.restoreCallingIdentity(identity); |
| 5616 | } |
| 5617 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5618 | |
| 5619 | /** |
| 5620 | * Scans for available networks. |
| 5621 | */ |
| 5622 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5623 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5624 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5625 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5626 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5627 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5628 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5629 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5630 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5631 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5632 | .setCallingPid(Binder.getCallingPid()) |
| 5633 | .setCallingUid(Binder.getCallingUid()) |
| 5634 | .setMethod("getCellNetworkScanResults") |
| 5635 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 5636 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5637 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5638 | .build()); |
| 5639 | switch (locationResult) { |
| 5640 | case DENIED_HARD: |
| 5641 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5642 | case DENIED_SOFT: |
| 5643 | return null; |
| 5644 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5645 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5646 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5647 | try { |
| 5648 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5649 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5650 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5651 | } finally { |
| 5652 | Binder.restoreCallingIdentity(identity); |
| 5653 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5654 | } |
| 5655 | |
| 5656 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5657 | * Get the call forwarding info, given the call forwarding reason. |
| 5658 | */ |
| 5659 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5660 | public void getCallForwarding(int subId, int callForwardingReason, |
| 5661 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5662 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5663 | long identity = Binder.clearCallingIdentity(); |
| 5664 | try { |
| 5665 | if (DBG) { |
| 5666 | log("getCallForwarding: subId " + subId |
| 5667 | + " callForwardingReason" + callForwardingReason); |
| 5668 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5669 | |
| 5670 | Phone phone = getPhone(subId); |
| 5671 | if (phone == null) { |
| 5672 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5673 | callback.onError( |
| 5674 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5675 | } catch (RemoteException e) { |
| 5676 | // ignore |
| 5677 | } |
| 5678 | return; |
| 5679 | } |
| 5680 | |
| 5681 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 5682 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 5683 | @Override |
| 5684 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 5685 | try { |
| 5686 | callback.onCallForwardingInfoAvailable(info); |
| 5687 | } catch (RemoteException e) { |
| 5688 | // ignore |
| 5689 | } |
| 5690 | } |
| 5691 | |
| 5692 | @Override |
| 5693 | public void onError(int error) { |
| 5694 | try { |
| 5695 | callback.onError(error); |
| 5696 | } catch (RemoteException e) { |
| 5697 | // ignore |
| 5698 | } |
| 5699 | } |
| 5700 | }); |
| 5701 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5702 | } finally { |
| 5703 | Binder.restoreCallingIdentity(identity); |
| 5704 | } |
| 5705 | } |
| 5706 | |
| 5707 | /** |
| 5708 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5709 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5710 | */ |
| 5711 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5712 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 5713 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5714 | enforceModifyPermission(); |
| 5715 | long identity = Binder.clearCallingIdentity(); |
| 5716 | try { |
| 5717 | if (DBG) { |
| 5718 | log("setCallForwarding: subId " + subId |
| 5719 | + " callForwardingInfo" + callForwardingInfo); |
| 5720 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5721 | |
| 5722 | Phone phone = getPhone(subId); |
| 5723 | if (phone == null) { |
| 5724 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5725 | callback.accept( |
| 5726 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5727 | } catch (RemoteException e) { |
| 5728 | // ignore |
| 5729 | } |
| 5730 | return; |
| 5731 | } |
| 5732 | |
| 5733 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 5734 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5735 | |
| 5736 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5737 | } finally { |
| 5738 | Binder.restoreCallingIdentity(identity); |
| 5739 | } |
| 5740 | } |
| 5741 | |
| 5742 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5743 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5744 | */ |
| 5745 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5746 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5747 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5748 | long identity = Binder.clearCallingIdentity(); |
| 5749 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5750 | |
| 5751 | Phone phone = getPhone(subId); |
| 5752 | if (phone == null) { |
| 5753 | try { |
| 5754 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5755 | } catch (RemoteException e) { |
| 5756 | // ignore |
| 5757 | } |
| 5758 | return; |
| 5759 | } |
| 5760 | |
| 5761 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 5762 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5763 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5764 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5765 | } finally { |
| 5766 | Binder.restoreCallingIdentity(identity); |
| 5767 | } |
| 5768 | } |
| 5769 | |
| 5770 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5771 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5772 | */ |
| 5773 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5774 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5775 | enforceModifyPermission(); |
| 5776 | long identity = Binder.clearCallingIdentity(); |
| 5777 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5778 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 5779 | |
| 5780 | Phone phone = getPhone(subId); |
| 5781 | if (phone == null) { |
| 5782 | try { |
| 5783 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5784 | } catch (RemoteException e) { |
| 5785 | // ignore |
| 5786 | } |
| 5787 | return; |
| 5788 | } |
| 5789 | |
| 5790 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 5791 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5792 | |
| 5793 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5794 | } finally { |
| 5795 | Binder.restoreCallingIdentity(identity); |
| 5796 | } |
| 5797 | } |
| 5798 | |
| 5799 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5800 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5801 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5802 | * @param subId id of the subscription |
| 5803 | * @param request contains the radio access networks with bands/channels to scan |
| 5804 | * @param messenger callback messenger for scan results or errors |
| 5805 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5806 | * @return the id of the requested scan which can be used to stop the scan. |
| 5807 | */ |
| 5808 | @Override |
| 5809 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5810 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5811 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5812 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5813 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5814 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5815 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5816 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5817 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5818 | .setCallingPid(Binder.getCallingPid()) |
| 5819 | .setCallingUid(Binder.getCallingUid()) |
| 5820 | .setMethod("requestNetworkScan") |
| 5821 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
James.cf Lin | 1d4d739 | 2020-07-03 18:22:53 +0800 | [diff] [blame] | 5822 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5823 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5824 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5825 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5826 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 5827 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5828 | if (e != null) { |
| 5829 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5830 | throw e; |
| 5831 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5832 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5833 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5834 | } |
| 5835 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5836 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5837 | int callingUid = Binder.getCallingUid(); |
| 5838 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5839 | final long identity = Binder.clearCallingIdentity(); |
| 5840 | try { |
| 5841 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5842 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5843 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5844 | } finally { |
| 5845 | Binder.restoreCallingIdentity(identity); |
| 5846 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5847 | } |
| 5848 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5849 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5850 | NetworkScanRequest request, int subId, String callingPackage) { |
| 5851 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5852 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5853 | boolean hasNetworkScanPermission = |
| 5854 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5855 | == PERMISSION_GRANTED; |
| 5856 | |
| 5857 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5858 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5859 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5860 | } |
| 5861 | |
| 5862 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5863 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5864 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5865 | return new SecurityException("Specific channels must not be" |
| 5866 | + " scanned without location access."); |
| 5867 | } |
| 5868 | } |
| 5869 | } |
| 5870 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5871 | return null; |
| 5872 | } |
| 5873 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5874 | /** |
| 5875 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5876 | * |
| 5877 | * @param subId id of the subscription |
| 5878 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5879 | */ |
| 5880 | @Override |
| 5881 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5882 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5883 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5884 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5885 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5886 | final long identity = Binder.clearCallingIdentity(); |
| 5887 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5888 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5889 | } finally { |
| 5890 | Binder.restoreCallingIdentity(identity); |
| 5891 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5892 | } |
| 5893 | |
| 5894 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5895 | * Get the calculated preferred network type. |
| 5896 | * Used for debugging incorrect network type. |
| 5897 | * |
| 5898 | * @return the preferred network type, defined in RILConstants.java. |
| 5899 | */ |
| 5900 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5901 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5902 | final Phone defaultPhone = getDefaultPhone(); |
| 5903 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5904 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5905 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5906 | } |
| 5907 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5908 | final long identity = Binder.clearCallingIdentity(); |
| 5909 | try { |
| 5910 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5911 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5912 | } finally { |
| 5913 | Binder.restoreCallingIdentity(identity); |
| 5914 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5915 | } |
| 5916 | |
| 5917 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5918 | * Get the preferred network type. |
| 5919 | * Used for device configuration by some CDMA operators. |
| 5920 | * |
| 5921 | * @return the preferred network type, defined in RILConstants.java. |
| 5922 | */ |
| 5923 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5924 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5925 | TelephonyPermissions |
| 5926 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5927 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5928 | |
| 5929 | final long identity = Binder.clearCallingIdentity(); |
| 5930 | try { |
| 5931 | if (DBG) log("getPreferredNetworkType"); |
| 5932 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5933 | int networkType = (result != null ? result[0] : -1); |
| 5934 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5935 | return networkType; |
| 5936 | } finally { |
| 5937 | Binder.restoreCallingIdentity(identity); |
| 5938 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5939 | } |
| 5940 | |
| 5941 | /** |
| 5942 | * Set the preferred network type. |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5943 | * |
| 5944 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5945 | * @return true on success; false on any failure. |
| 5946 | */ |
| 5947 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5948 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5949 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5950 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5951 | |
| 5952 | final long identity = Binder.clearCallingIdentity(); |
| 5953 | try { |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5954 | Boolean success = (Boolean) sendRequest( |
| 5955 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
calvinpan | 03641a7 | 2020-08-18 16:53:59 +0800 | [diff] [blame] | 5956 | |
| 5957 | if (success) { |
| 5958 | Settings.Global.putInt(mApp.getContentResolver(), |
| 5959 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 5960 | } |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5961 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 5962 | return success; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5963 | } finally { |
| 5964 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5965 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5966 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5967 | |
| 5968 | /** |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5969 | * Get the allowed network types that store in the telephony provider. |
| 5970 | * |
| 5971 | * @param subId the id of the subscription. |
| 5972 | * @return allowedNetworkTypes the allowed network types. |
| 5973 | */ |
| 5974 | @Override |
| 5975 | public long getAllowedNetworkTypes(int subId) { |
| 5976 | TelephonyPermissions |
| 5977 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5978 | mApp, subId, "getAllowedNetworkTypes"); |
| 5979 | |
| 5980 | final long identity = Binder.clearCallingIdentity(); |
| 5981 | try { |
| 5982 | return SubscriptionManager.getLongSubscriptionProperty( |
| 5983 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5984 | } finally { |
| 5985 | Binder.restoreCallingIdentity(identity); |
| 5986 | } |
| 5987 | } |
| 5988 | |
| 5989 | /** |
| 5990 | * Set the allowed network types. |
| 5991 | * |
| 5992 | * @param subId the id of the subscription. |
| 5993 | * @param allowedNetworkTypes the allowed network types. |
| 5994 | * @return true on success; false on any failure. |
| 5995 | */ |
| 5996 | @Override |
| 5997 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 5998 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5999 | mApp, subId, "setAllowedNetworkTypes"); |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 6000 | |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 6001 | SubscriptionManager.setSubscriptionProperty(subId, |
| 6002 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 6003 | String.valueOf(allowedNetworkTypes)); |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 6004 | |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 6005 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 6006 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 6007 | RILConstants.PREFERRED_NETWORK_MODE); |
| 6008 | return setPreferredNetworkType(subId, preferredNetworkMode); |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 6009 | } |
| 6010 | |
| 6011 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6012 | * Get the allowed network types for certain reason. |
| 6013 | * |
| 6014 | * @param subId the id of the subscription. |
| 6015 | * @param reason the reason the allowed network type change is taking place |
| 6016 | * @return the allowed network types. |
| 6017 | */ |
| 6018 | @Override |
| 6019 | public long getAllowedNetworkTypesForReason(int subId, |
| 6020 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
| 6021 | TelephonyPermissions |
| 6022 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6023 | mApp, subId, "getAllowedNetworkTypesForReason"); |
| 6024 | final long identity = Binder.clearCallingIdentity(); |
| 6025 | try { |
| 6026 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6027 | } finally { |
| 6028 | Binder.restoreCallingIdentity(identity); |
| 6029 | } |
| 6030 | } |
| 6031 | |
| 6032 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6033 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6034 | * @param subId subscription id of the sim card |
| 6035 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6036 | * This can be passed following states |
| 6037 | * <ol> |
| 6038 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6039 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6040 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6041 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6042 | * </ol> |
| 6043 | * @return operation result. |
| 6044 | */ |
| 6045 | @Override |
| 6046 | public int setNrDualConnectivityState(int subId, |
| 6047 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6048 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6049 | mApp, subId, "enableNRDualConnectivity"); |
| 6050 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6051 | final long identity = Binder.clearCallingIdentity(); |
| 6052 | try { |
| 6053 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6054 | nrDualConnectivityState, subId, |
| 6055 | workSource); |
| 6056 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6057 | return result; |
| 6058 | } finally { |
| 6059 | Binder.restoreCallingIdentity(identity); |
| 6060 | } |
| 6061 | } |
| 6062 | |
| 6063 | /** |
| 6064 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6065 | * @return true if dual connectivity is enabled else false |
| 6066 | */ |
| 6067 | @Override |
| 6068 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6069 | TelephonyPermissions |
| 6070 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6071 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6072 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6073 | final long identity = Binder.clearCallingIdentity(); |
| 6074 | try { |
| 6075 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6076 | null, subId, workSource); |
| 6077 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6078 | return isEnabled; |
| 6079 | } finally { |
| 6080 | Binder.restoreCallingIdentity(identity); |
| 6081 | } |
| 6082 | } |
| 6083 | |
| 6084 | /** |
Sooraj Sasindran | 4deb887 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 6085 | * get carrier bandwidth per primary and secondary carrier |
| 6086 | * @param subId subscription id of the sim card |
| 6087 | * @return CarrierBandwidth with bandwidth of both primary and secondary carrier.. |
| 6088 | */ |
| 6089 | @Override |
| 6090 | public CarrierBandwidth getCarrierBandwidth(int subId) { |
| 6091 | TelephonyPermissions |
| 6092 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6093 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6094 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6095 | final long identity = Binder.clearCallingIdentity(); |
| 6096 | try { |
| 6097 | CarrierBandwidth carrierBandwidth = |
| 6098 | getPhoneFromSubId(subId).getCarrierBandwidth(); |
| 6099 | if (DBG) log("getCarrierBandwidth: " + carrierBandwidth); |
| 6100 | return carrierBandwidth; |
| 6101 | } finally { |
| 6102 | Binder.restoreCallingIdentity(identity); |
| 6103 | } |
| 6104 | } |
| 6105 | |
| 6106 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6107 | * Get the effective allowed network types on the device. |
| 6108 | * This API will return an intersection of allowed network types for all reasons, |
| 6109 | * including the configuration done through setAllowedNetworkTypes |
| 6110 | * |
| 6111 | * @param subId the id of the subscription. |
| 6112 | * @return the allowed network types |
| 6113 | */ |
| 6114 | @Override |
| 6115 | public long getEffectiveAllowedNetworkTypes(int subId) { |
| 6116 | TelephonyPermissions |
| 6117 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6118 | mApp, subId, "getEffectiveAllowedNetworkTypes"); |
| 6119 | final long identity = Binder.clearCallingIdentity(); |
| 6120 | try { |
| 6121 | return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes(); |
| 6122 | } finally { |
| 6123 | Binder.restoreCallingIdentity(identity); |
| 6124 | } |
| 6125 | } |
| 6126 | |
| 6127 | /** |
| 6128 | * Set the allowed network types of the device and |
| 6129 | * provide the reason triggering the allowed network change. |
| 6130 | * |
| 6131 | * @param subId the id of the subscription. |
| 6132 | * @param reason the reason the allowed network type change is taking place |
| 6133 | * @param allowedNetworkTypes the allowed network types. |
| 6134 | * @return true on success; false on any failure. |
| 6135 | */ |
| 6136 | @Override |
| 6137 | public boolean setAllowedNetworkTypesForReason(int subId, |
| 6138 | @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) { |
| 6139 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6140 | mApp, subId, "setAllowedNetworkTypesForReason"); |
| 6141 | final long identity = Binder.clearCallingIdentity(); |
| 6142 | try { |
| 6143 | getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes); |
| 6144 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 6145 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 6146 | RILConstants.PREFERRED_NETWORK_MODE); |
| 6147 | return setPreferredNetworkType(subId, preferredNetworkMode); |
| 6148 | } finally { |
| 6149 | Binder.restoreCallingIdentity(identity); |
| 6150 | } |
| 6151 | } |
| 6152 | |
| 6153 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6154 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6155 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6156 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6157 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6158 | * @hide |
| 6159 | */ |
| 6160 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6161 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6162 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6163 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6164 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6165 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6166 | if (phone != null) { |
| 6167 | return phone.hasMatchedTetherApnSetting(); |
| 6168 | } else { |
| 6169 | return false; |
| 6170 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6171 | } finally { |
| 6172 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6173 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6174 | } |
| 6175 | |
| 6176 | /** |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6177 | * Enable or disable always reporting signal strength changes from radio. |
| 6178 | * |
| 6179 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 6180 | */ |
| 6181 | @Override |
| 6182 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 6183 | enforceModifyPermission(); |
| 6184 | enforceSystemCaller(); |
| 6185 | |
| 6186 | final long identity = Binder.clearCallingIdentity(); |
| 6187 | final Phone phone = getPhone(subId); |
| 6188 | try { |
| 6189 | if (phone != null) { |
| 6190 | if (DBG) { |
| 6191 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6192 | + " isEnable=" + isEnable); |
| 6193 | } |
| 6194 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6195 | } else { |
| 6196 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6197 | + subId); |
| 6198 | } |
| 6199 | } finally { |
| 6200 | Binder.restoreCallingIdentity(identity); |
| 6201 | } |
| 6202 | } |
| 6203 | |
| 6204 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6205 | * Get the user enabled state of Mobile Data. |
| 6206 | * |
| 6207 | * TODO: remove and use isUserDataEnabled. |
| 6208 | * This can't be removed now because some vendor codes |
| 6209 | * calls through ITelephony directly while they should |
| 6210 | * use TelephonyManager. |
| 6211 | * |
| 6212 | * @return true on enabled |
| 6213 | */ |
| 6214 | @Override |
| 6215 | public boolean getDataEnabled(int subId) { |
| 6216 | return isUserDataEnabled(subId); |
| 6217 | } |
| 6218 | |
| 6219 | /** |
| 6220 | * Get whether mobile data is enabled per user setting. |
| 6221 | * |
| 6222 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6223 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6224 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6225 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6226 | * |
| 6227 | * @return {@code true} if data is enabled else {@code false} |
| 6228 | */ |
| 6229 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6230 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6231 | try { |
| 6232 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6233 | null); |
| 6234 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6235 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6236 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6237 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6238 | |
| 6239 | final long identity = Binder.clearCallingIdentity(); |
| 6240 | try { |
| 6241 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6242 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6243 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6244 | if (phone != null) { |
| 6245 | boolean retVal = phone.isUserDataEnabled(); |
| 6246 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6247 | return retVal; |
| 6248 | } else { |
| 6249 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6250 | return false; |
| 6251 | } |
| 6252 | } finally { |
| 6253 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6254 | } |
| 6255 | } |
| 6256 | |
| 6257 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6258 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6259 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6260 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6261 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6262 | * @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] | 6263 | */ |
| 6264 | @Override |
| 6265 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6266 | try { |
| 6267 | try { |
| 6268 | mApp.enforceCallingOrSelfPermission( |
| 6269 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6270 | null); |
| 6271 | } catch (Exception e) { |
| 6272 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6273 | "isDataEnabled"); |
| 6274 | } |
| 6275 | } catch (Exception e) { |
| 6276 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6277 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6278 | |
| 6279 | final long identity = Binder.clearCallingIdentity(); |
| 6280 | try { |
| 6281 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6282 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6283 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6284 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6285 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6286 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6287 | return retVal; |
| 6288 | } else { |
| 6289 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6290 | return false; |
| 6291 | } |
| 6292 | } finally { |
| 6293 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6294 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6295 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6296 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6297 | /** |
| 6298 | * Check if data is enabled for a specific reason |
| 6299 | * @param subId Subscription index |
| 6300 | * @param reason the reason the data enable change is taking place |
| 6301 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6302 | */ |
| 6303 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6304 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6305 | @TelephonyManager.DataEnabledReason int reason) { |
| 6306 | try { |
| 6307 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6308 | null); |
| 6309 | } catch (Exception e) { |
| 6310 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6311 | "isDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6312 | } |
| 6313 | |
| 6314 | |
| 6315 | final long identity = Binder.clearCallingIdentity(); |
| 6316 | try { |
| 6317 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6318 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6319 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6320 | + " reason=" + reason); |
| 6321 | } |
| 6322 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6323 | if (phone != null) { |
| 6324 | boolean retVal; |
| 6325 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6326 | retVal = phone.isUserDataEnabled(); |
| 6327 | } else { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6328 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6329 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6330 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6331 | return retVal; |
| 6332 | } else { |
| 6333 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6334 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6335 | + subId + " retVal=false"); |
| 6336 | } |
| 6337 | return false; |
| 6338 | } |
| 6339 | } finally { |
| 6340 | Binder.restoreCallingIdentity(identity); |
| 6341 | } |
| 6342 | } |
| 6343 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6344 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6345 | Phone phone) { |
Hall Liu | 54a2a0c | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 6346 | if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) { |
| 6347 | // Skip the check if it's one of these special uids |
| 6348 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6349 | } |
| 6350 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6351 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6352 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6353 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6354 | || subController == null) return privilegeFromSim; |
| 6355 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6356 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6357 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6358 | |
| 6359 | final long identity = Binder.clearCallingIdentity(); |
| 6360 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6361 | int subId = phone.getSubId(); |
| 6362 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6363 | // A test override is in place for the privileges for this subId, so don't try to |
| 6364 | // read the subscription privileges. |
| 6365 | return privilegeFromSim; |
| 6366 | } |
| 6367 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6368 | SubscriptionManager subManager = (SubscriptionManager) |
| 6369 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6370 | for (String pkg : packages) { |
| 6371 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6372 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6373 | } |
| 6374 | } |
| 6375 | return privilegeFromSim; |
| 6376 | } finally { |
| 6377 | Binder.restoreCallingIdentity(identity); |
| 6378 | } |
| 6379 | } |
| 6380 | |
| 6381 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6382 | String pkgName) { |
| 6383 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6384 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6385 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6386 | || subController == null) return privilegeFromSim; |
| 6387 | |
| 6388 | final long identity = Binder.clearCallingIdentity(); |
| 6389 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6390 | int subId = phone.getSubId(); |
| 6391 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6392 | // A test override is in place for the privileges for this subId, so don't try to |
| 6393 | // read the subscription privileges. |
| 6394 | return privilegeFromSim; |
| 6395 | } |
| 6396 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6397 | SubscriptionManager subManager = (SubscriptionManager) |
| 6398 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6399 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6400 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6401 | } finally { |
| 6402 | Binder.restoreCallingIdentity(identity); |
| 6403 | } |
| 6404 | } |
| 6405 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6406 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6407 | public int getCarrierPrivilegeStatus(int subId) { |
| 6408 | final Phone phone = getPhone(subId); |
| 6409 | if (phone == null) { |
| 6410 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6411 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6412 | } |
| 6413 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6414 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6415 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6416 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6417 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6418 | |
| 6419 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6420 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6421 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6422 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6423 | |
| 6424 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6425 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6426 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6427 | final Phone phone = getPhone(subId); |
| 6428 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6429 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6430 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6431 | } |
| 6432 | UiccProfile profile = |
| 6433 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6434 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6435 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6436 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6437 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6438 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6439 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6440 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6441 | } |
| 6442 | |
| 6443 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6444 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 6445 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6446 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6447 | } |
| 6448 | |
| 6449 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 6450 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6451 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6452 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6453 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6454 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6455 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6456 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6457 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6458 | } |
| 6459 | |
| 6460 | @Override |
| 6461 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6462 | if (TextUtils.isEmpty(pkgName)) |
| 6463 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6464 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6465 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6466 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 6467 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6468 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6469 | continue; |
| 6470 | } |
| 6471 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6472 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6473 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6474 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6475 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6476 | break; |
| 6477 | } |
| 6478 | } |
| 6479 | |
| 6480 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6481 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6482 | |
| 6483 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6484 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 6485 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6486 | loge("phoneId " + phoneId + " is not valid."); |
| 6487 | return null; |
| 6488 | } |
| 6489 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6490 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6491 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6492 | return null ; |
| 6493 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6494 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6495 | } |
| 6496 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6497 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6498 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6499 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6500 | List<String> privilegedPackages = new ArrayList<>(); |
| 6501 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6502 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 6503 | // has UICC in that slot. |
| 6504 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6505 | if (card.hasCarrierPrivilegeRules()) { |
| 6506 | if (packages == null) { |
| 6507 | // Only check packages in user 0 for now |
| 6508 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6509 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6510 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6511 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6512 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6513 | } |
| 6514 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6515 | PackageInfo pkgInfo = packages.get(p); |
| 6516 | if (pkgInfo != null && pkgInfo.packageName != null |
| 6517 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6518 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6519 | privilegedPackages.add(pkgInfo.packageName); |
| 6520 | } |
| 6521 | } |
| 6522 | } |
| 6523 | } |
| 6524 | return privilegedPackages; |
| 6525 | } |
| 6526 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6527 | @Override |
| 6528 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6529 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6530 | |
| 6531 | final long identity = Binder.clearCallingIdentity(); |
| 6532 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6533 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6534 | try { |
| 6535 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6536 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6537 | } |
| 6538 | } finally { |
| 6539 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6540 | } |
| 6541 | return privilegedPackages; |
| 6542 | } |
| 6543 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6544 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6545 | final Phone phone = getPhone(subId); |
| 6546 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6547 | if (card == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6548 | return null; |
| 6549 | } |
| 6550 | String iccId = card.getIccId(); |
| 6551 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6552 | return null; |
| 6553 | } |
| 6554 | return iccId; |
| 6555 | } |
| 6556 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6557 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame^] | 6558 | public void setCallComposerStatus(int subId, int status) { |
| 6559 | enforceModifyPermission(); |
| 6560 | |
| 6561 | final long identity = Binder.clearCallingIdentity(); |
| 6562 | try { |
| 6563 | Phone phone = getPhone(subId); |
| 6564 | if (phone != null) { |
| 6565 | Phone defaultPhone = phone.getImsPhone(); |
| 6566 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6567 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6568 | imsPhone.setCallComposerStatus(status); |
| 6569 | } |
| 6570 | } |
| 6571 | } finally { |
| 6572 | Binder.restoreCallingIdentity(identity); |
| 6573 | } |
| 6574 | } |
| 6575 | |
| 6576 | @Override |
| 6577 | public int getCallComposerStatus(int subId) { |
| 6578 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 6579 | |
| 6580 | final long identity = Binder.clearCallingIdentity(); |
| 6581 | try { |
| 6582 | Phone phone = getPhone(subId); |
| 6583 | if (phone != null) { |
| 6584 | Phone defaultPhone = phone.getImsPhone(); |
| 6585 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6586 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6587 | return imsPhone.getCallComposerStatus(); |
| 6588 | } |
| 6589 | } |
| 6590 | } finally { |
| 6591 | Binder.restoreCallingIdentity(identity); |
| 6592 | } |
| 6593 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 6594 | } |
| 6595 | |
| 6596 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6597 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6598 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6599 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6600 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6601 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6602 | final long identity = Binder.clearCallingIdentity(); |
| 6603 | try { |
| 6604 | final String iccId = getIccId(subId); |
| 6605 | final Phone phone = getPhone(subId); |
| 6606 | if (phone == null) { |
| 6607 | return false; |
| 6608 | } |
| 6609 | final String subscriberId = phone.getSubscriberId(); |
| 6610 | |
| 6611 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6612 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6613 | + subscriberId + " to " + number); |
| 6614 | } |
| 6615 | |
| 6616 | if (TextUtils.isEmpty(iccId)) { |
| 6617 | return false; |
| 6618 | } |
| 6619 | |
| 6620 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6621 | |
| 6622 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6623 | if (alphaTag == null) { |
| 6624 | editor.remove(alphaTagPrefKey); |
| 6625 | } else { |
| 6626 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6627 | } |
| 6628 | |
| 6629 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6630 | // track all merged IMSIs based on line number |
| 6631 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6632 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6633 | if (number == null) { |
| 6634 | editor.remove(numberPrefKey); |
| 6635 | editor.remove(subscriberPrefKey); |
| 6636 | } else { |
| 6637 | editor.putString(numberPrefKey, number); |
| 6638 | editor.putString(subscriberPrefKey, subscriberId); |
| 6639 | } |
| 6640 | |
| 6641 | editor.commit(); |
| 6642 | return true; |
| 6643 | } finally { |
| 6644 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6645 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6646 | } |
| 6647 | |
| 6648 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6649 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6650 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6651 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6652 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6653 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6654 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6655 | return null; |
| 6656 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6657 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6658 | final long identity = Binder.clearCallingIdentity(); |
| 6659 | try { |
| 6660 | String iccId = getIccId(subId); |
| 6661 | if (iccId != null) { |
| 6662 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6663 | if (DBG_MERGE) { |
| 6664 | log("getLine1NumberForDisplay returning " |
| 6665 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6666 | } |
| 6667 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6668 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6669 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6670 | return null; |
| 6671 | } finally { |
| 6672 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6673 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6674 | } |
| 6675 | |
| 6676 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6677 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6678 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6679 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6680 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6681 | return null; |
| 6682 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6683 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6684 | final long identity = Binder.clearCallingIdentity(); |
| 6685 | try { |
| 6686 | String iccId = getIccId(subId); |
| 6687 | if (iccId != null) { |
| 6688 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6689 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6690 | } |
| 6691 | return null; |
| 6692 | } finally { |
| 6693 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6694 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6695 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6696 | |
| 6697 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6698 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6699 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6700 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6701 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6702 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6703 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6704 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6705 | return null; |
| 6706 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6707 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6708 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6709 | // the process, where TelephonyManager was instantiated. |
| 6710 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6711 | final long identity = Binder.clearCallingIdentity(); |
| 6712 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6713 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6714 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6715 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6716 | |
| 6717 | // Figure out what subscribers are currently active |
| 6718 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6719 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6720 | // Only consider subs which match the current subId |
| 6721 | // This logic can be simplified. See b/131189269 for progress. |
| 6722 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6723 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6724 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6725 | |
| 6726 | // First pass, find a number override for an active subscriber |
| 6727 | String mergeNumber = null; |
| 6728 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6729 | for (String key : prefs.keySet()) { |
| 6730 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6731 | final String subscriberId = (String) prefs.get(key); |
| 6732 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6733 | final String iccId = key.substring( |
| 6734 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6735 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6736 | mergeNumber = (String) prefs.get(numberKey); |
| 6737 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6738 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6739 | + " for active subscriber " + subscriberId); |
| 6740 | } |
| 6741 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6742 | break; |
| 6743 | } |
| 6744 | } |
| 6745 | } |
| 6746 | } |
| 6747 | |
| 6748 | // Shortcut when no active merged subscribers |
| 6749 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6750 | return null; |
| 6751 | } |
| 6752 | |
| 6753 | // Second pass, find all subscribers under that line override |
| 6754 | final ArraySet<String> result = new ArraySet<>(); |
| 6755 | for (String key : prefs.keySet()) { |
| 6756 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6757 | final String number = (String) prefs.get(key); |
| 6758 | if (mergeNumber.equals(number)) { |
| 6759 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6760 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6761 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6762 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6763 | result.add(subscriberId); |
| 6764 | } |
| 6765 | } |
| 6766 | } |
| 6767 | } |
| 6768 | |
| 6769 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6770 | Arrays.sort(resultArray); |
| 6771 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6772 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6773 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6774 | } |
| 6775 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6776 | } finally { |
| 6777 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6778 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6779 | } |
| 6780 | |
| 6781 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6782 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6783 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6784 | |
| 6785 | final long identity = Binder.clearCallingIdentity(); |
| 6786 | try { |
| 6787 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6788 | TelephonyManager.class); |
| 6789 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6790 | if (subscriberId == null) { |
| 6791 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6792 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6793 | + subId); |
| 6794 | } |
| 6795 | return null; |
| 6796 | } |
| 6797 | |
| 6798 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6799 | .getSubscriptionInfo(subId); |
| 6800 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6801 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6802 | if (groupUuid == null) { |
| 6803 | return new String[]{subscriberId}; |
| 6804 | } |
| 6805 | |
| 6806 | // Get all subscriberIds from the group. |
| 6807 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6808 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6809 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6810 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6811 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6812 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6813 | if (subscriberId != null) { |
| 6814 | mergedSubscriberIds.add(subscriberId); |
| 6815 | } |
| 6816 | } |
| 6817 | |
| 6818 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6819 | } finally { |
| 6820 | Binder.restoreCallingIdentity(identity); |
| 6821 | |
| 6822 | } |
| 6823 | } |
| 6824 | |
| 6825 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6826 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6827 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6828 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6829 | |
| 6830 | final long identity = Binder.clearCallingIdentity(); |
| 6831 | try { |
| 6832 | final Phone phone = getPhone(subId); |
| 6833 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6834 | } finally { |
| 6835 | Binder.restoreCallingIdentity(identity); |
| 6836 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6837 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6838 | |
| 6839 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6840 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6841 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6842 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6843 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6844 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6845 | |
| 6846 | final long identity = Binder.clearCallingIdentity(); |
| 6847 | try { |
| 6848 | final Phone phone = getPhone(subId); |
| 6849 | if (phone == null) { |
| 6850 | return false; |
| 6851 | } |
| 6852 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6853 | cdmaNonRoamingList); |
| 6854 | } finally { |
| 6855 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6856 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6857 | } |
| 6858 | |
| 6859 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6860 | @Deprecated |
| 6861 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6862 | enforceModifyPermission(); |
| 6863 | |
| 6864 | int returnValue = 0; |
| 6865 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6866 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6867 | if(result.exception == null) { |
| 6868 | if (result.result != null) { |
| 6869 | byte[] responseData = (byte[])(result.result); |
| 6870 | if(responseData.length > oemResp.length) { |
| 6871 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6872 | responseData.length + "bytes. Buffer Size is " + |
| 6873 | oemResp.length + "bytes."); |
| 6874 | } |
| 6875 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6876 | returnValue = responseData.length; |
| 6877 | } |
| 6878 | } else { |
| 6879 | CommandException ex = (CommandException) result.exception; |
| 6880 | returnValue = ex.getCommandError().ordinal(); |
| 6881 | if(returnValue > 0) returnValue *= -1; |
| 6882 | } |
| 6883 | } catch (RuntimeException e) { |
| 6884 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6885 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6886 | if(returnValue > 0) returnValue *= -1; |
| 6887 | } |
| 6888 | |
| 6889 | return returnValue; |
| 6890 | } |
| 6891 | |
| 6892 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6893 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6894 | try { |
| 6895 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6896 | } catch (RuntimeException e) { |
| 6897 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6898 | } |
| 6899 | } |
| 6900 | |
| 6901 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6902 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6903 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 6904 | try { |
| 6905 | TelephonyPermissions |
| 6906 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6907 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6908 | } catch (SecurityException e) { |
| 6909 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 6910 | throw e; |
| 6911 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6912 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6913 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6914 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6915 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6916 | final long identity = Binder.clearCallingIdentity(); |
| 6917 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6918 | TelephonyPermissions |
| 6919 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6920 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6921 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6922 | } finally { |
| 6923 | Binder.restoreCallingIdentity(identity); |
| 6924 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6925 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6926 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6927 | |
| 6928 | @Override |
| 6929 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6930 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6931 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6932 | |
| 6933 | final long identity = Binder.clearCallingIdentity(); |
| 6934 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6935 | ImsManager.getInstance(defaultPhone.getContext(), |
| 6936 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6937 | } finally { |
| 6938 | Binder.restoreCallingIdentity(identity); |
| 6939 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6940 | } |
| 6941 | |
| 6942 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6943 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6944 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6945 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 6946 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6947 | return false; |
| 6948 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6949 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6950 | final long identity = Binder.clearCallingIdentity(); |
| 6951 | try { |
| 6952 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 6953 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 6954 | // In the long run, we may instead need to check if there exists a connection service |
| 6955 | // which can support video calling. |
| 6956 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6957 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6958 | return imsManager.isVtEnabledByPlatform() |
| 6959 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 6960 | && imsManager.isVtEnabledByUser(); |
| 6961 | } finally { |
| 6962 | Binder.restoreCallingIdentity(identity); |
| 6963 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6964 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 6965 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6966 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6967 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 6968 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6969 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6970 | mApp, subId, callingPackage, callingFeatureId, |
| 6971 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6972 | return false; |
| 6973 | } |
| 6974 | |
| 6975 | final long identity = Binder.clearCallingIdentity(); |
| 6976 | try { |
| 6977 | CarrierConfigManager configManager = |
| 6978 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6979 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6980 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 6981 | } finally { |
| 6982 | Binder.restoreCallingIdentity(identity); |
| 6983 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6984 | } |
| 6985 | |
| 6986 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6987 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6988 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6989 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6990 | return false; |
| 6991 | } |
| 6992 | |
| 6993 | final long identity = Binder.clearCallingIdentity(); |
| 6994 | try { |
| 6995 | CarrierConfigManager configManager = |
| 6996 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6997 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6998 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 6999 | } finally { |
| 7000 | Binder.restoreCallingIdentity(identity); |
| 7001 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7002 | } |
| 7003 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7004 | @Override |
| 7005 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7006 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7007 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7008 | } |
| 7009 | |
| 7010 | @Override |
| 7011 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7012 | final long identity = Binder.clearCallingIdentity(); |
| 7013 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7014 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7015 | } finally { |
| 7016 | Binder.restoreCallingIdentity(identity); |
| 7017 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7018 | } |
| 7019 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7020 | /** |
| 7021 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7022 | * support for the feature and device firmware support. |
| 7023 | * |
| 7024 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7025 | */ |
| 7026 | @Override |
| 7027 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7028 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7029 | final Phone phone = getPhone(subscriptionId); |
| 7030 | if (phone == null) { |
| 7031 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7032 | return false; |
| 7033 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7034 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7035 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7036 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7037 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7038 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7039 | return isCarrierSupported && isDeviceSupported; |
| 7040 | } finally { |
| 7041 | Binder.restoreCallingIdentity(identity); |
| 7042 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7043 | } |
| 7044 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7045 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7046 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7047 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7048 | * 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] | 7049 | */ |
| 7050 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7051 | final long identity = Binder.clearCallingIdentity(); |
| 7052 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7053 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7054 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7055 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7056 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7057 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7058 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7059 | } finally { |
| 7060 | Binder.restoreCallingIdentity(identity); |
| 7061 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7062 | } |
| 7063 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7064 | @Deprecated |
| 7065 | @Override |
| 7066 | public String getDeviceId(String callingPackage) { |
| 7067 | return getDeviceIdWithFeature(callingPackage, null); |
| 7068 | } |
| 7069 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7070 | /** |
| 7071 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7072 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7073 | * |
| 7074 | * <p>Requires Permission: |
| 7075 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7076 | */ |
| 7077 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7078 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7079 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7080 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7081 | return null; |
| 7082 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7083 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7084 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7085 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7086 | return null; |
| 7087 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7088 | |
| 7089 | final long identity = Binder.clearCallingIdentity(); |
| 7090 | try { |
| 7091 | return phone.getDeviceId(); |
| 7092 | } finally { |
| 7093 | Binder.restoreCallingIdentity(identity); |
| 7094 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7095 | } |
| 7096 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7097 | /** |
| 7098 | * {@hide} |
| 7099 | * Returns the IMS Registration Status on a particular subid |
| 7100 | * |
| 7101 | * @param subId |
| 7102 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7103 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7104 | Phone phone = getPhone(subId); |
| 7105 | if (phone != null) { |
| 7106 | return phone.isImsRegistered(); |
| 7107 | } else { |
| 7108 | return false; |
| 7109 | } |
| 7110 | } |
| 7111 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7112 | @Override |
| 7113 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7114 | final long identity = Binder.clearCallingIdentity(); |
| 7115 | try { |
| 7116 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 7117 | } finally { |
| 7118 | Binder.restoreCallingIdentity(identity); |
| 7119 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7120 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 7121 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7122 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7123 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7124 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7125 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7126 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7127 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7128 | } |
| 7129 | final long identity = Binder.clearCallingIdentity(); |
| 7130 | try { |
| 7131 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7132 | } finally { |
| 7133 | Binder.restoreCallingIdentity(identity); |
| 7134 | } |
| 7135 | } |
| 7136 | |
| 7137 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7138 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
duki.hong | fd96bde | 2020-07-22 17:32:19 +0900 | [diff] [blame] | 7139 | enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, " |
| 7140 | + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7141 | final long identity = Binder.clearCallingIdentity(); |
| 7142 | try { |
| 7143 | Phone phone = getPhone(subscriptionId); |
| 7144 | if (phone == null) { |
| 7145 | return null; |
| 7146 | } |
| 7147 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7148 | } finally { |
| 7149 | Binder.restoreCallingIdentity(identity); |
| 7150 | } |
| 7151 | } |
| 7152 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7153 | /** |
| 7154 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7155 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7156 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7157 | final long identity = Binder.clearCallingIdentity(); |
| 7158 | try { |
| 7159 | Phone phone = getPhone(subId); |
| 7160 | if (phone != null) { |
| 7161 | return phone.isWifiCallingEnabled(); |
| 7162 | } else { |
| 7163 | return false; |
| 7164 | } |
| 7165 | } finally { |
| 7166 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7167 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7168 | } |
| 7169 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7170 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7171 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7172 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7173 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7174 | final long identity = Binder.clearCallingIdentity(); |
| 7175 | try { |
| 7176 | Phone phone = getPhone(subId); |
| 7177 | if (phone != null) { |
| 7178 | return phone.isVideoEnabled(); |
| 7179 | } else { |
| 7180 | return false; |
| 7181 | } |
| 7182 | } finally { |
| 7183 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7184 | } |
| 7185 | } |
| 7186 | |
| 7187 | /** |
| 7188 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7189 | * defined in {@link ImsRegistrationImplBase}. |
| 7190 | */ |
| 7191 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7192 | final long identity = Binder.clearCallingIdentity(); |
| 7193 | try { |
| 7194 | Phone phone = getPhone(subId); |
| 7195 | if (phone != null) { |
| 7196 | return phone.getImsRegistrationTech(); |
| 7197 | } else { |
| 7198 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7199 | } |
| 7200 | } finally { |
| 7201 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7202 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7203 | } |
| 7204 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7205 | @Override |
| 7206 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7207 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7208 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7209 | return; |
| 7210 | } |
| 7211 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7212 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7213 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7214 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7215 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7216 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7217 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7218 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7219 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7220 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7221 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 7222 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7223 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7224 | // There has been issues when Sms raw table somehow stores orphan |
| 7225 | // fragments. They lead to garbled message when new fragments come |
| 7226 | // in and combined with those stale ones. In case this happens again, |
| 7227 | // user can reset all network settings which will clean up this table. |
| 7228 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7229 | // Clean up IMS settings as well here. |
| 7230 | int slotId = getSlotIndex(subId); |
| 7231 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7232 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7233 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7234 | |
| 7235 | // Erase modem config if erase modem on network setting is enabled. |
| 7236 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7237 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7238 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 7239 | sendEraseModemConfig(getDefaultPhone()); |
| 7240 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7241 | } finally { |
| 7242 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7243 | } |
| 7244 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7245 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7246 | private void cleanUpSmsRawTable(Context context) { |
| 7247 | ContentResolver resolver = context.getContentResolver(); |
| 7248 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7249 | resolver.delete(uri, null, null); |
| 7250 | } |
| 7251 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7252 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7253 | public String getSimLocaleForSubscriber(int subId) { |
| 7254 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7255 | final Phone phone = getPhone(subId); |
| 7256 | if (phone == null) { |
| 7257 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7258 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7259 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7260 | final long identity = Binder.clearCallingIdentity(); |
| 7261 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7262 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7263 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7264 | if (info == null) { |
| 7265 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7266 | return null; |
| 7267 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7268 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7269 | // preferences (EF-PL and EF-LI)... |
| 7270 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7271 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7272 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7273 | if (localeFromDefaultSim != null) { |
| 7274 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7275 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7276 | + localeFromDefaultSim); |
| 7277 | return localeFromDefaultSim.toLanguageTag(); |
| 7278 | } else { |
| 7279 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7280 | } |
| 7281 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7282 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7283 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7284 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7285 | // the SIM and carrier preferences does not include a country we add the country |
| 7286 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7287 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7288 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7289 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7290 | return mccLocale.toLanguageTag(); |
| 7291 | } |
| 7292 | |
| 7293 | if (DBG) log("No locale found - returning null"); |
| 7294 | return null; |
| 7295 | } finally { |
| 7296 | Binder.restoreCallingIdentity(identity); |
| 7297 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7298 | } |
| 7299 | |
| 7300 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7301 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7302 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7303 | } |
| 7304 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7305 | /** |
| 7306 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7307 | */ |
| 7308 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7309 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7310 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7311 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7312 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7313 | private final ModemActivityInfo mLastModemActivityInfo = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7314 | new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7315 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7316 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7317 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7318 | * representing the state of the modem. |
| 7319 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7320 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7321 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7322 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7323 | */ |
| 7324 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7325 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7326 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7327 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7328 | |
| 7329 | final long identity = Binder.clearCallingIdentity(); |
| 7330 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7331 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7332 | } finally { |
| 7333 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7334 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7335 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7336 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7337 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7338 | // less than total activity duration. |
| 7339 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7340 | if (info == null) { |
| 7341 | return false; |
| 7342 | } |
| 7343 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7344 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7345 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7346 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7347 | return (info.isValid() |
| 7348 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7349 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7350 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7351 | && (totalTxTimeMs <= activityDurationMs)); |
| 7352 | } |
| 7353 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7354 | /** |
| 7355 | * {@hide} |
| 7356 | * Returns the service state information on specified subscription. |
| 7357 | */ |
| 7358 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7359 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7360 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7361 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7362 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7363 | return null; |
| 7364 | } |
| 7365 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7366 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7367 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7368 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7369 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7370 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7371 | .setCallingPid(Binder.getCallingPid()) |
| 7372 | .setCallingUid(Binder.getCallingUid()) |
| 7373 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7374 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7375 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7376 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7377 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7378 | .build()); |
| 7379 | |
| 7380 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7381 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7382 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7383 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7384 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7385 | .setCallingPid(Binder.getCallingPid()) |
| 7386 | .setCallingUid(Binder.getCallingUid()) |
| 7387 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7388 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7389 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7390 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7391 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7392 | .build()); |
| 7393 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7394 | boolean hasFinePermission = |
| 7395 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7396 | boolean hasCoarsePermission = |
| 7397 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7398 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7399 | final Phone phone = getPhone(subId); |
| 7400 | if (phone == null) { |
| 7401 | return null; |
| 7402 | } |
| 7403 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 7404 | final long identity = Binder.clearCallingIdentity(); |
| 7405 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7406 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 7407 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7408 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7409 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7410 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7411 | Rlog.d(LOG_TAG, |
| 7412 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7413 | return null; |
| 7414 | } |
| 7415 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7416 | ServiceState ss = phone.getServiceState(); |
| 7417 | |
| 7418 | // Scrub out the location info in ServiceState depending on what level of access |
| 7419 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7420 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7421 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7422 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7423 | } finally { |
| 7424 | Binder.restoreCallingIdentity(identity); |
| 7425 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7426 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7427 | |
| 7428 | /** |
| 7429 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7430 | * |
| 7431 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7432 | * voicemail ringtone. |
| 7433 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7434 | * PhoneAccount. |
| 7435 | */ |
| 7436 | @Override |
| 7437 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7438 | final long identity = Binder.clearCallingIdentity(); |
| 7439 | try { |
| 7440 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7441 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7442 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7443 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7444 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7445 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7446 | } finally { |
| 7447 | Binder.restoreCallingIdentity(identity); |
| 7448 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7449 | } |
| 7450 | |
| 7451 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7452 | * Sets the per-account voicemail ringtone. |
| 7453 | * |
| 7454 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7455 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7456 | * |
| 7457 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7458 | * voicemail ringtone. |
| 7459 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7460 | * PhoneAccount. |
| 7461 | */ |
| 7462 | @Override |
| 7463 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7464 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7465 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7466 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7467 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7468 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7469 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7470 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7471 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7472 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7473 | |
| 7474 | final long identity = Binder.clearCallingIdentity(); |
| 7475 | try { |
| 7476 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7477 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7478 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7479 | } |
| 7480 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7481 | } finally { |
| 7482 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7483 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7484 | } |
| 7485 | |
| 7486 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7487 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7488 | * |
| 7489 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7490 | * voicemail vibration setting. |
| 7491 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7492 | */ |
| 7493 | @Override |
| 7494 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7495 | final long identity = Binder.clearCallingIdentity(); |
| 7496 | try { |
| 7497 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7498 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7499 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7500 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7501 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7502 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7503 | } finally { |
| 7504 | Binder.restoreCallingIdentity(identity); |
| 7505 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7506 | } |
| 7507 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7508 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7509 | * Sets the per-account voicemail vibration. |
| 7510 | * |
| 7511 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7512 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7513 | * |
| 7514 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7515 | * voicemail vibration setting. |
| 7516 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7517 | * specific PhoneAccount. |
| 7518 | */ |
| 7519 | @Override |
| 7520 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7521 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7522 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7523 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7524 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7525 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7526 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7527 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7528 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7529 | } |
| 7530 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7531 | final long identity = Binder.clearCallingIdentity(); |
| 7532 | try { |
| 7533 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7534 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7535 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7536 | } |
| 7537 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7538 | } finally { |
| 7539 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7540 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7541 | } |
| 7542 | |
| 7543 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7544 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 7545 | * |
| 7546 | * @throws SecurityException if the caller does not have the required permission |
| 7547 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7548 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7549 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7550 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7551 | } |
| 7552 | |
| 7553 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7554 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 7555 | * permission. |
| 7556 | * |
| 7557 | * @throws SecurityException if the caller does not have the required permission |
| 7558 | */ |
| 7559 | private void enforceSendSmsPermission() { |
| 7560 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 7561 | } |
| 7562 | |
| 7563 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7564 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7565 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7566 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7567 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7568 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7569 | final long identity = Binder.clearCallingIdentity(); |
| 7570 | try { |
| 7571 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7572 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7573 | if (componentName == null) { |
| 7574 | throw new SecurityException( |
| 7575 | "Caller not current active visual voicemail package[null]"); |
| 7576 | } |
| 7577 | String vvmPackage = componentName.getPackageName(); |
| 7578 | if (!callingPackage.equals(vvmPackage)) { |
| 7579 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 7580 | + vvmPackage + "]"); |
| 7581 | } |
| 7582 | } finally { |
| 7583 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7584 | } |
| 7585 | } |
| 7586 | |
| 7587 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7588 | * Return the application ID for the app type. |
| 7589 | * |
| 7590 | * @param subId the subscription ID that this request applies to. |
| 7591 | * @param appType the uicc app type. |
| 7592 | * @return Application ID for specificied app type, or null if no uicc. |
| 7593 | */ |
| 7594 | @Override |
| 7595 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7596 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7597 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7598 | |
| 7599 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7600 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7601 | if (phone == null) { |
| 7602 | return null; |
| 7603 | } |
| 7604 | String aid = null; |
| 7605 | try { |
| 7606 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 7607 | .getApplicationByType(appType).getAid(); |
| 7608 | } catch (Exception e) { |
| 7609 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 7610 | } |
| 7611 | return aid; |
| 7612 | } finally { |
| 7613 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7614 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7615 | } |
| 7616 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7617 | /** |
| 7618 | * Return the Electronic Serial Number. |
| 7619 | * |
| 7620 | * @param subId the subscription ID that this request applies to. |
| 7621 | * @return ESN or null if error. |
| 7622 | */ |
| 7623 | @Override |
| 7624 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7625 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7626 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7627 | |
| 7628 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7629 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7630 | if (phone == null) { |
| 7631 | return null; |
| 7632 | } |
| 7633 | String esn = null; |
| 7634 | try { |
| 7635 | esn = phone.getEsn(); |
| 7636 | } catch (Exception e) { |
| 7637 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 7638 | } |
| 7639 | return esn; |
| 7640 | } finally { |
| 7641 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7642 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7643 | } |
| 7644 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7645 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7646 | * Return the Preferred Roaming List Version. |
| 7647 | * |
| 7648 | * @param subId the subscription ID that this request applies to. |
| 7649 | * @return PRLVersion or null if error. |
| 7650 | */ |
| 7651 | @Override |
| 7652 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7653 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7654 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7655 | |
| 7656 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7657 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7658 | if (phone == null) { |
| 7659 | return null; |
| 7660 | } |
| 7661 | String cdmaPrlVersion = null; |
| 7662 | try { |
| 7663 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7664 | } catch (Exception e) { |
| 7665 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7666 | } |
| 7667 | return cdmaPrlVersion; |
| 7668 | } finally { |
| 7669 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7670 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7671 | } |
| 7672 | |
| 7673 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7674 | * Get snapshot of Telephony histograms |
| 7675 | * @return List of Telephony histograms |
| 7676 | * @hide |
| 7677 | */ |
| 7678 | @Override |
| 7679 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7680 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7681 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7682 | |
| 7683 | final long identity = Binder.clearCallingIdentity(); |
| 7684 | try { |
| 7685 | return RIL.getTelephonyRILTimingHistograms(); |
| 7686 | } finally { |
| 7687 | Binder.restoreCallingIdentity(identity); |
| 7688 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7689 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7690 | |
| 7691 | /** |
| 7692 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7693 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7694 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7695 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7696 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7697 | * @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] | 7698 | */ |
| 7699 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7700 | @TelephonyManager.SetCarrierRestrictionResult |
| 7701 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7702 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7703 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7704 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7705 | if (carrierRestrictionRules == null) { |
| 7706 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7707 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7708 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7709 | final long identity = Binder.clearCallingIdentity(); |
| 7710 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7711 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7712 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7713 | } finally { |
| 7714 | Binder.restoreCallingIdentity(identity); |
| 7715 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7716 | } |
| 7717 | |
| 7718 | /** |
| 7719 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7720 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7721 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7722 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7723 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7724 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7725 | */ |
| 7726 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7727 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7728 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7729 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7730 | |
| 7731 | final long identity = Binder.clearCallingIdentity(); |
| 7732 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7733 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7734 | if (response instanceof CarrierRestrictionRules) { |
| 7735 | return (CarrierRestrictionRules) response; |
| 7736 | } |
| 7737 | // Response is an Exception of some kind, |
| 7738 | // which is signalled to the user as a NULL retval |
| 7739 | return null; |
| 7740 | } catch (Exception e) { |
| 7741 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7742 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7743 | } finally { |
| 7744 | Binder.restoreCallingIdentity(identity); |
| 7745 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7746 | } |
| 7747 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7748 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7749 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7750 | * @param subId the subscription ID that this action applies to. |
| 7751 | * @param enabled control enable or disable radio. |
| 7752 | * {@hide} |
| 7753 | */ |
| 7754 | @Override |
| 7755 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7756 | enforceModifyPermission(); |
| 7757 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7758 | |
| 7759 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7760 | if (phone == null) { |
| 7761 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7762 | return; |
| 7763 | } |
| 7764 | try { |
| 7765 | phone.carrierActionSetRadioEnabled(enabled); |
| 7766 | } catch (Exception e) { |
| 7767 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7768 | } finally { |
| 7769 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7770 | } |
| 7771 | } |
| 7772 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7773 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7774 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7775 | * network status based on which carrier apps could apply actions accordingly, |
| 7776 | * enable/disable default url handler for example. |
| 7777 | * |
| 7778 | * @param subId the subscription ID that this action applies to. |
| 7779 | * @param report control start/stop reporting the default network status. |
| 7780 | * {@hide} |
| 7781 | */ |
| 7782 | @Override |
| 7783 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7784 | enforceModifyPermission(); |
| 7785 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7786 | |
| 7787 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7788 | if (phone == null) { |
| 7789 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7790 | return; |
| 7791 | } |
| 7792 | try { |
| 7793 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7794 | } catch (Exception e) { |
| 7795 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7796 | } finally { |
| 7797 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7798 | } |
| 7799 | } |
| 7800 | |
| 7801 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7802 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7803 | * @param subId the subscription ID that this action applies to. |
| 7804 | * {@hide} |
| 7805 | */ |
| 7806 | @Override |
| 7807 | public void carrierActionResetAll(int subId) { |
| 7808 | enforceModifyPermission(); |
| 7809 | final Phone phone = getPhone(subId); |
| 7810 | if (phone == null) { |
| 7811 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7812 | return; |
| 7813 | } |
| 7814 | try { |
| 7815 | phone.carrierActionResetAll(); |
| 7816 | } catch (Exception e) { |
| 7817 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7818 | } |
| 7819 | } |
| 7820 | |
| 7821 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7822 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7823 | * bug report is being generated. |
| 7824 | */ |
| 7825 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7826 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7827 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7828 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7829 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7830 | + Binder.getCallingPid() |
| 7831 | + ", uid=" + Binder.getCallingUid() |
| 7832 | + "without permission " |
| 7833 | + android.Manifest.permission.DUMP); |
| 7834 | return; |
| 7835 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7836 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7837 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7838 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7839 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 7840 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 7841 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 7842 | @NonNull String[] args) { |
| 7843 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 7844 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 7845 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7846 | } |
| 7847 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7848 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7849 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 7850 | * @param subId Subscription index |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7851 | * @param reason the reason the data enable change is taking place |
| 7852 | * @param enabled True if enabling the data, otherwise disabling. |
| 7853 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7854 | */ |
| 7855 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7856 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7857 | boolean enabled) { |
| 7858 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 7859 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7860 | try { |
| 7861 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7862 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7863 | } catch (SecurityException se) { |
| 7864 | enforceModifyPermission(); |
| 7865 | } |
| 7866 | } else { |
| 7867 | enforceModifyPermission(); |
| 7868 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7869 | |
| 7870 | final long identity = Binder.clearCallingIdentity(); |
| 7871 | try { |
| 7872 | Phone phone = getPhone(subId); |
| 7873 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7874 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7875 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7876 | } else { |
| 7877 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 7878 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7879 | } |
| 7880 | } finally { |
| 7881 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7882 | } |
| 7883 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7884 | |
| 7885 | /** |
| 7886 | * Get Client request stats |
| 7887 | * @return List of Client Request Stats |
| 7888 | * @hide |
| 7889 | */ |
| 7890 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7891 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7892 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7893 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7894 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7895 | return null; |
| 7896 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7897 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7898 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7899 | final long identity = Binder.clearCallingIdentity(); |
| 7900 | try { |
| 7901 | if (phone != null) { |
| 7902 | return phone.getClientRequestStats(); |
| 7903 | } |
| 7904 | |
| 7905 | return null; |
| 7906 | } finally { |
| 7907 | Binder.restoreCallingIdentity(identity); |
| 7908 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7909 | } |
| 7910 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7911 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7912 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7913 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7914 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7915 | |
| 7916 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7917 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7918 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7919 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7920 | * @param state State of SIM (power down, power up, pass through) |
| 7921 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7922 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7923 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7924 | * |
| 7925 | **/ |
| 7926 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7927 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7928 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7929 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7930 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7931 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7932 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7933 | final long identity = Binder.clearCallingIdentity(); |
| 7934 | try { |
| 7935 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 7936 | phone.setSimPowerState(state, null, workSource); |
| 7937 | } |
| 7938 | } finally { |
| 7939 | Binder.restoreCallingIdentity(identity); |
| 7940 | } |
| 7941 | } |
| 7942 | |
| 7943 | /** |
| 7944 | * Set SIM card power state. |
| 7945 | * |
| 7946 | * @param slotIndex SIM slot id. |
| 7947 | * @param state State of SIM (power down, power up, pass through) |
| 7948 | * @param callback callback to trigger after success or failure |
| 7949 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7950 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7951 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 7952 | * |
| 7953 | **/ |
| 7954 | @Override |
| 7955 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 7956 | IIntegerConsumer callback) { |
| 7957 | enforceModifyPermission(); |
| 7958 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7959 | |
| 7960 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7961 | |
| 7962 | final long identity = Binder.clearCallingIdentity(); |
| 7963 | try { |
| 7964 | if (phone != null) { |
| 7965 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 7966 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7967 | } |
| 7968 | } finally { |
| 7969 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7970 | } |
| 7971 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7972 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7973 | private boolean isUssdApiAllowed(int subId) { |
| 7974 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7975 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7976 | if (configManager == null) { |
| 7977 | return false; |
| 7978 | } |
| 7979 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 7980 | if (pb == null) { |
| 7981 | return false; |
| 7982 | } |
| 7983 | return pb.getBoolean( |
| 7984 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 7985 | } |
| 7986 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7987 | /** |
| 7988 | * Check if phone is in emergency callback mode |
| 7989 | * @return true if phone is in emergency callback mode |
| 7990 | * @param subId sub id |
| 7991 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 7992 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7993 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7994 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7995 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7996 | |
| 7997 | final long identity = Binder.clearCallingIdentity(); |
| 7998 | try { |
| 7999 | if (phone != null) { |
| 8000 | return phone.isInEcm(); |
| 8001 | } else { |
| 8002 | return false; |
| 8003 | } |
| 8004 | } finally { |
| 8005 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8006 | } |
| 8007 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8008 | |
| 8009 | /** |
| 8010 | * Get the current signal strength information for the given subscription. |
| 8011 | * Because this information is not updated when the device is in a low power state |
| 8012 | * it should not be relied-upon to be current. |
| 8013 | * @param subId Subscription index |
| 8014 | * @return the most recent cached signal strength info from the modem |
| 8015 | */ |
| 8016 | @Override |
| 8017 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8018 | final long identity = Binder.clearCallingIdentity(); |
| 8019 | try { |
| 8020 | Phone p = getPhone(subId); |
| 8021 | if (p == null) { |
| 8022 | return null; |
| 8023 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8024 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8025 | return p.getSignalStrength(); |
| 8026 | } finally { |
| 8027 | Binder.restoreCallingIdentity(identity); |
| 8028 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8029 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8030 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8031 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8032 | * Get the current modem radio state for the given slot. |
| 8033 | * @param slotIndex slot index. |
| 8034 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8035 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8036 | * @return the current radio power state from the modem |
| 8037 | */ |
| 8038 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8039 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8040 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8041 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8042 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8043 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8044 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8045 | } |
| 8046 | |
| 8047 | final long identity = Binder.clearCallingIdentity(); |
| 8048 | try { |
| 8049 | return phone.getRadioPowerState(); |
| 8050 | } finally { |
| 8051 | Binder.restoreCallingIdentity(identity); |
| 8052 | } |
| 8053 | } |
| 8054 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8055 | } |
| 8056 | |
| 8057 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8058 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8059 | * |
| 8060 | * <p>Requires one of the following permissions: |
| 8061 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 8062 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8063 | * privileges. |
| 8064 | * |
| 8065 | * @param subId subscription id |
| 8066 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8067 | * {@code false}. |
| 8068 | */ |
| 8069 | @Override |
| 8070 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8071 | try { |
| 8072 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8073 | null); |
| 8074 | } catch (Exception e) { |
| 8075 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 8076 | mApp, subId, "isDataRoamingEnabled"); |
| 8077 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8078 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8079 | boolean isEnabled = false; |
| 8080 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8081 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8082 | Phone phone = getPhone(subId); |
| 8083 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8084 | } finally { |
| 8085 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8086 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8087 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8088 | } |
| 8089 | |
| 8090 | |
| 8091 | /** |
| 8092 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8093 | * |
| 8094 | * <p> Requires permission: |
| 8095 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8096 | * privileges. |
| 8097 | * |
| 8098 | * @param subId subscription id |
| 8099 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8100 | */ |
| 8101 | @Override |
| 8102 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8103 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8104 | mApp, subId, "setDataRoamingEnabled"); |
| 8105 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8106 | final long identity = Binder.clearCallingIdentity(); |
| 8107 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8108 | Phone phone = getPhone(subId); |
| 8109 | if (phone != null) { |
| 8110 | phone.setDataRoamingEnabled(isEnabled); |
| 8111 | } |
| 8112 | } finally { |
| 8113 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8114 | } |
| 8115 | } |
| 8116 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8117 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8118 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8119 | TelephonyPermissions |
| 8120 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8121 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8122 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8123 | boolean isAllowed = true; |
| 8124 | final long identity = Binder.clearCallingIdentity(); |
| 8125 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8126 | Phone phone = getPhone(subId); |
| 8127 | if (phone != null) { |
| 8128 | isAllowed = phone.isCspPlmnEnabled(); |
| 8129 | } |
| 8130 | } finally { |
| 8131 | Binder.restoreCallingIdentity(identity); |
| 8132 | } |
| 8133 | return isAllowed; |
| 8134 | } |
| 8135 | |
| 8136 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8137 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8138 | // Verify that tha callingPackage belongs to the calling UID |
| 8139 | mApp.getSystemService(AppOpsManager.class) |
| 8140 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8141 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8142 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8143 | try { |
| 8144 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8145 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8146 | } catch (SecurityException e) { |
| 8147 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8148 | // has carrier privileges on an active UICC |
| 8149 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8150 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8151 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8152 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8153 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8154 | |
| 8155 | final long identity = Binder.clearCallingIdentity(); |
| 8156 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8157 | UiccController uiccController = UiccController.getInstance(); |
| 8158 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8159 | if (hasReadPermission) { |
| 8160 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8161 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8162 | |
| 8163 | // Remove private info if the caller doesn't have access |
| 8164 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8165 | for (UiccCardInfo cardInfo : cardInfos) { |
| 8166 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8167 | // is available |
| 8168 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 8169 | if (card == null || card.getUiccProfile() == null) { |
| 8170 | // assume no access if the card or profile is unavailable |
| 8171 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8172 | continue; |
| 8173 | } |
| 8174 | UiccProfile profile = card.getUiccProfile(); |
| 8175 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8176 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8177 | filteredInfos.add(cardInfo); |
| 8178 | } else { |
| 8179 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8180 | } |
| 8181 | } |
| 8182 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8183 | } finally { |
| 8184 | Binder.restoreCallingIdentity(identity); |
| 8185 | } |
| 8186 | } |
| 8187 | |
| 8188 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8189 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8190 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8191 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8192 | final long identity = Binder.clearCallingIdentity(); |
| 8193 | try { |
| 8194 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8195 | if (slots == null) { |
| 8196 | Rlog.i(LOG_TAG, "slots is null."); |
| 8197 | return null; |
| 8198 | } |
| 8199 | |
| 8200 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8201 | for (int i = 0; i < slots.length; i++) { |
| 8202 | UiccSlot slot = slots[i]; |
| 8203 | if (slot == null) { |
| 8204 | continue; |
| 8205 | } |
| 8206 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8207 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8208 | UiccCard card = slot.getUiccCard(); |
| 8209 | if (card != null) { |
| 8210 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8211 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8212 | cardId = slot.getEid(); |
| 8213 | if (TextUtils.isEmpty(cardId)) { |
| 8214 | cardId = slot.getIccId(); |
| 8215 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8216 | } |
| 8217 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8218 | if (cardId != null) { |
| 8219 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8220 | // if cardId is an EID, it's all digits so this is fine |
| 8221 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8222 | } |
| 8223 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8224 | int cardState = 0; |
| 8225 | switch (slot.getCardState()) { |
| 8226 | case CARDSTATE_ABSENT: |
| 8227 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8228 | break; |
| 8229 | case CARDSTATE_PRESENT: |
| 8230 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8231 | break; |
| 8232 | case CARDSTATE_ERROR: |
| 8233 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8234 | break; |
| 8235 | case CARDSTATE_RESTRICTED: |
| 8236 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8237 | break; |
| 8238 | default: |
| 8239 | break; |
| 8240 | |
| 8241 | } |
| 8242 | |
| 8243 | infos[i] = new UiccSlotInfo( |
| 8244 | slot.isActive(), |
| 8245 | slot.isEuicc(), |
| 8246 | cardId, |
| 8247 | cardState, |
| 8248 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8249 | slot.isExtendedApduSupported(), |
| 8250 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8251 | } |
| 8252 | return infos; |
| 8253 | } finally { |
| 8254 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8255 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8256 | } |
| 8257 | |
| 8258 | @Override |
| 8259 | public boolean switchSlots(int[] physicalSlots) { |
| 8260 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8261 | |
| 8262 | final long identity = Binder.clearCallingIdentity(); |
| 8263 | try { |
| 8264 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8265 | } finally { |
| 8266 | Binder.restoreCallingIdentity(identity); |
| 8267 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8268 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8269 | |
| 8270 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8271 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8272 | final long identity = Binder.clearCallingIdentity(); |
| 8273 | try { |
| 8274 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8275 | } finally { |
| 8276 | Binder.restoreCallingIdentity(identity); |
| 8277 | } |
| 8278 | } |
| 8279 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8280 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8281 | * A test API to reload the UICC profile. |
| 8282 | * |
| 8283 | * <p>Requires that the calling app has permission |
| 8284 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8285 | * @hide |
| 8286 | */ |
| 8287 | @Override |
| 8288 | public void refreshUiccProfile(int subId) { |
| 8289 | enforceModifyPermission(); |
| 8290 | |
| 8291 | final long identity = Binder.clearCallingIdentity(); |
| 8292 | try { |
| 8293 | Phone phone = getPhone(subId); |
| 8294 | if (phone == null) { |
| 8295 | return; |
| 8296 | } |
| 8297 | UiccCard uiccCard = phone.getUiccCard(); |
| 8298 | if (uiccCard == null) { |
| 8299 | return; |
| 8300 | } |
| 8301 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8302 | if (uiccProfile == null) { |
| 8303 | return; |
| 8304 | } |
| 8305 | uiccProfile.refresh(); |
| 8306 | } finally { |
| 8307 | Binder.restoreCallingIdentity(identity); |
| 8308 | } |
| 8309 | } |
| 8310 | |
| 8311 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8312 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8313 | */ |
| 8314 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8315 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8316 | } |
| 8317 | |
| 8318 | /** |
| 8319 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8320 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8321 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8322 | */ |
| 8323 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8324 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8325 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8326 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8327 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8328 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8329 | return isDataRoamingEnabled; |
| 8330 | } |
| 8331 | |
| 8332 | /** |
| 8333 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8334 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8335 | */ |
| 8336 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8337 | List<Integer> list = TelephonyProperties.default_network(); |
| 8338 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8339 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8340 | return list.get(phoneId); |
| 8341 | } |
| 8342 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8343 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8344 | |
| 8345 | @Override |
| 8346 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8347 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8348 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8349 | |
| 8350 | final long identity = Binder.clearCallingIdentity(); |
| 8351 | try { |
| 8352 | final Phone phone = getPhone(subId); |
| 8353 | if (phone == null) { |
| 8354 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8355 | return; |
| 8356 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8357 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8358 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8359 | if (carrierPrivilegeRules == null) { |
| 8360 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8361 | } else { |
| 8362 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8363 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8364 | } finally { |
| 8365 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8366 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8367 | } |
| 8368 | |
| 8369 | @Override |
| 8370 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8371 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8372 | |
| 8373 | final long identity = Binder.clearCallingIdentity(); |
| 8374 | try { |
| 8375 | final Phone phone = getPhone(subId); |
| 8376 | if (phone == null) { |
| 8377 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 8378 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 8379 | } |
| 8380 | return phone.getCarrierIdListVersion(); |
| 8381 | } finally { |
| 8382 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8383 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8384 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8385 | |
| 8386 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8387 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 8388 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8389 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8390 | mApp, subId, callingPackage, callingFeatureId, |
| 8391 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8392 | return -1; |
| 8393 | } |
| 8394 | |
| 8395 | final long identity = Binder.clearCallingIdentity(); |
| 8396 | try { |
| 8397 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 8398 | } finally { |
| 8399 | Binder.restoreCallingIdentity(identity); |
| 8400 | } |
| 8401 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8402 | |
| 8403 | @Override |
| 8404 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 8405 | TelephonyPermissions |
| 8406 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8407 | mApp, subId, "getCdmaRoamingMode"); |
| 8408 | |
| 8409 | final long identity = Binder.clearCallingIdentity(); |
| 8410 | try { |
| 8411 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 8412 | } finally { |
| 8413 | Binder.restoreCallingIdentity(identity); |
| 8414 | } |
| 8415 | } |
| 8416 | |
| 8417 | @Override |
| 8418 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 8419 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8420 | mApp, subId, "setCdmaRoamingMode"); |
| 8421 | |
| 8422 | final long identity = Binder.clearCallingIdentity(); |
| 8423 | try { |
| 8424 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 8425 | } finally { |
| 8426 | Binder.restoreCallingIdentity(identity); |
| 8427 | } |
| 8428 | } |
| 8429 | |
| 8430 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8431 | public int getCdmaSubscriptionMode(int subId) { |
| 8432 | TelephonyPermissions |
| 8433 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8434 | mApp, subId, "getCdmaSubscriptionMode"); |
| 8435 | |
| 8436 | final long identity = Binder.clearCallingIdentity(); |
| 8437 | try { |
| 8438 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 8439 | } finally { |
| 8440 | Binder.restoreCallingIdentity(identity); |
| 8441 | } |
| 8442 | } |
| 8443 | |
| 8444 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8445 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 8446 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8447 | mApp, subId, "setCdmaSubscriptionMode"); |
| 8448 | |
| 8449 | final long identity = Binder.clearCallingIdentity(); |
| 8450 | try { |
| 8451 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 8452 | } finally { |
| 8453 | Binder.restoreCallingIdentity(identity); |
| 8454 | } |
| 8455 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8456 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8457 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8458 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8459 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8460 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8461 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 8462 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8463 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8464 | } |
| 8465 | final long identity = Binder.clearCallingIdentity(); |
| 8466 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8467 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 8468 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8469 | if (phone.getEmergencyNumberTracker() != null |
| 8470 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 8471 | emergencyNumberListInternal.put( |
| 8472 | phone.getSubId(), |
| 8473 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 8474 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8475 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8476 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8477 | } finally { |
| 8478 | Binder.restoreCallingIdentity(identity); |
| 8479 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8480 | } |
| 8481 | |
| 8482 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8483 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8484 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8485 | if (!exactMatch) { |
| 8486 | TelephonyPermissions |
| 8487 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8488 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8489 | } |
| 8490 | final long identity = Binder.clearCallingIdentity(); |
| 8491 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8492 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8493 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8494 | && phone.getEmergencyNumberTracker() |
| 8495 | .isEmergencyNumber(number, exactMatch)) { |
| 8496 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8497 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8498 | } |
| 8499 | return false; |
| 8500 | } finally { |
| 8501 | Binder.restoreCallingIdentity(identity); |
| 8502 | } |
| 8503 | } |
| 8504 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8505 | /** |
| 8506 | * Update emergency number list for test mode. |
| 8507 | */ |
| 8508 | @Override |
| 8509 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 8510 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8511 | "updateEmergencyNumberListTestMode"); |
| 8512 | |
| 8513 | final long identity = Binder.clearCallingIdentity(); |
| 8514 | try { |
| 8515 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8516 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8517 | if (tracker != null) { |
| 8518 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 8519 | } |
| 8520 | } |
| 8521 | } finally { |
| 8522 | Binder.restoreCallingIdentity(identity); |
| 8523 | } |
| 8524 | } |
| 8525 | |
| 8526 | /** |
| 8527 | * Get the full emergency number list for test mode. |
| 8528 | */ |
| 8529 | @Override |
| 8530 | public List<String> getEmergencyNumberListTestMode() { |
| 8531 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8532 | "getEmergencyNumberListTestMode"); |
| 8533 | |
| 8534 | final long identity = Binder.clearCallingIdentity(); |
| 8535 | try { |
| 8536 | Set<String> emergencyNumbers = new HashSet<>(); |
| 8537 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8538 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8539 | if (tracker != null) { |
| 8540 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 8541 | emergencyNumbers.add(num.getNumber()); |
| 8542 | } |
| 8543 | } |
| 8544 | } |
| 8545 | return new ArrayList<>(emergencyNumbers); |
| 8546 | } finally { |
| 8547 | Binder.restoreCallingIdentity(identity); |
| 8548 | } |
| 8549 | } |
| 8550 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8551 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8552 | public int getEmergencyNumberDbVersion(int subId) { |
| 8553 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 8554 | |
| 8555 | final long identity = Binder.clearCallingIdentity(); |
| 8556 | try { |
| 8557 | final Phone phone = getPhone(subId); |
| 8558 | if (phone == null) { |
| 8559 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 8560 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 8561 | } |
| 8562 | return phone.getEmergencyNumberDbVersion(); |
| 8563 | } finally { |
| 8564 | Binder.restoreCallingIdentity(identity); |
| 8565 | } |
| 8566 | } |
| 8567 | |
| 8568 | @Override |
| 8569 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 8570 | enforceModifyPermission(); |
| 8571 | |
| 8572 | final long identity = Binder.clearCallingIdentity(); |
| 8573 | try { |
| 8574 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8575 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8576 | if (tracker != null) { |
| 8577 | tracker.updateOtaEmergencyNumberDatabase(); |
| 8578 | } |
| 8579 | } |
| 8580 | } finally { |
| 8581 | Binder.restoreCallingIdentity(identity); |
| 8582 | } |
| 8583 | } |
| 8584 | |
| 8585 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8586 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8587 | enforceActiveEmergencySessionPermission(); |
| 8588 | |
| 8589 | final long identity = Binder.clearCallingIdentity(); |
| 8590 | try { |
| 8591 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8592 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8593 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8594 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 8595 | } |
| 8596 | } |
| 8597 | } finally { |
| 8598 | Binder.restoreCallingIdentity(identity); |
| 8599 | } |
| 8600 | } |
| 8601 | |
| 8602 | @Override |
| 8603 | public void resetOtaEmergencyNumberDbFilePath() { |
| 8604 | enforceActiveEmergencySessionPermission(); |
| 8605 | |
| 8606 | final long identity = Binder.clearCallingIdentity(); |
| 8607 | try { |
| 8608 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8609 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8610 | if (tracker != null) { |
| 8611 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8612 | } |
| 8613 | } |
| 8614 | } finally { |
| 8615 | Binder.restoreCallingIdentity(identity); |
| 8616 | } |
| 8617 | } |
| 8618 | |
| 8619 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8620 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 8621 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 8622 | Phone phone = getPhone(subId); |
| 8623 | if (phone == null) { |
| 8624 | return null; |
| 8625 | } |
| 8626 | final long identity = Binder.clearCallingIdentity(); |
| 8627 | try { |
| 8628 | UiccProfile profile = UiccController.getInstance() |
| 8629 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 8630 | if (profile != null) { |
| 8631 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 8632 | } |
| 8633 | } finally { |
| 8634 | Binder.restoreCallingIdentity(identity); |
| 8635 | } |
| 8636 | return null; |
| 8637 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 8638 | |
| 8639 | /** |
| 8640 | * Enable or disable a modem stack. |
| 8641 | */ |
| 8642 | @Override |
| 8643 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 8644 | enforceModifyPermission(); |
| 8645 | |
| 8646 | final long identity = Binder.clearCallingIdentity(); |
| 8647 | try { |
| 8648 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8649 | if (phone == null) { |
| 8650 | return false; |
| 8651 | } else { |
| 8652 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 8653 | } |
| 8654 | } finally { |
| 8655 | Binder.restoreCallingIdentity(identity); |
| 8656 | } |
| 8657 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8658 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8659 | /** |
| 8660 | * Whether a modem stack is enabled or not. |
| 8661 | */ |
| 8662 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8663 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 8664 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8665 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8666 | if (phone == null) return false; |
| 8667 | |
| 8668 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8669 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 8670 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8671 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8672 | } |
| 8673 | |
| 8674 | final long identity = Binder.clearCallingIdentity(); |
| 8675 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8676 | try { |
| 8677 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 8678 | } catch (NoSuchElementException ex) { |
| 8679 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 8680 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8681 | } finally { |
| 8682 | Binder.restoreCallingIdentity(identity); |
| 8683 | } |
| 8684 | } |
| 8685 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8686 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8687 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8688 | enforceModifyPermission(); |
| 8689 | |
| 8690 | final long identity = Binder.clearCallingIdentity(); |
| 8691 | try { |
| 8692 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8693 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8694 | .commit(); |
| 8695 | } finally { |
| 8696 | Binder.restoreCallingIdentity(identity); |
| 8697 | } |
| 8698 | } |
| 8699 | |
| 8700 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8701 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8702 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8703 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8704 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8705 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8706 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8707 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8708 | |
| 8709 | final long identity = Binder.clearCallingIdentity(); |
| 8710 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8711 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8712 | } finally { |
| 8713 | Binder.restoreCallingIdentity(identity); |
| 8714 | } |
| 8715 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8716 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8717 | @TelephonyManager.IsMultiSimSupportedResult |
| 8718 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8719 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8720 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8721 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8722 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8723 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8724 | } |
| 8725 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8726 | // supported by the modem, indicate that it is restricted. |
| 8727 | PhoneCapability staticCapability = |
| 8728 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8729 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8730 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8731 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8732 | } |
Sarah Chin | 7caee49 | 2020-02-18 20:49:02 +0000 | [diff] [blame] | 8733 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8734 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8735 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8736 | } |
| 8737 | // Check if support of multiple SIMs is restricted by carrier |
| 8738 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8739 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8740 | } |
| 8741 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8742 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8743 | } |
| 8744 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8745 | /** |
| 8746 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8747 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8748 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8749 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8750 | * @param numOfSims number of active sims we want to switch to |
| 8751 | */ |
| 8752 | @Override |
| 8753 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8754 | if (numOfSims == 1) { |
| 8755 | enforceModifyPermission(); |
| 8756 | } else { |
| 8757 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8758 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8759 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8760 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8761 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8762 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8763 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8764 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8765 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8766 | return; |
| 8767 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8768 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8769 | } finally { |
| 8770 | Binder.restoreCallingIdentity(identity); |
| 8771 | } |
| 8772 | } |
| 8773 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8774 | @Override |
| 8775 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8776 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8777 | Phone phone = getPhone(subId); |
| 8778 | if (phone == null) { |
| 8779 | return false; |
| 8780 | } |
| 8781 | final long identity = Binder.clearCallingIdentity(); |
| 8782 | try { |
| 8783 | UiccCard uiccCard = phone.getUiccCard(); |
| 8784 | if (uiccCard == null) { |
| 8785 | return false; |
| 8786 | } |
| 8787 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8788 | if (uiccProfile == null) { |
| 8789 | return false; |
| 8790 | } |
| 8791 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8792 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8793 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8794 | } |
| 8795 | return false; |
| 8796 | } finally { |
| 8797 | Binder.restoreCallingIdentity(identity); |
| 8798 | } |
| 8799 | } |
| 8800 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8801 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8802 | * Get whether making changes to modem configurations will trigger reboot. |
| 8803 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8804 | */ |
| 8805 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8806 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8807 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8808 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8809 | mApp, subId, callingPackage, callingFeatureId, |
| 8810 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8811 | return false; |
| 8812 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8813 | final long identity = Binder.clearCallingIdentity(); |
| 8814 | try { |
| 8815 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8816 | } finally { |
| 8817 | Binder.restoreCallingIdentity(identity); |
| 8818 | } |
| 8819 | } |
| 8820 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8821 | private void updateModemStateMetrics() { |
| 8822 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8823 | // TODO: check the state for each modem if the api is ready. |
| 8824 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8825 | } |
| 8826 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8827 | @Override |
| 8828 | public int[] getSlotsMapping() { |
| 8829 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8830 | |
| 8831 | final long identity = Binder.clearCallingIdentity(); |
| 8832 | try { |
| 8833 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8834 | // All logical slots should have a mapping to a physical slot. |
| 8835 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8836 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8837 | for (int i = 0; i < slotInfos.length; i++) { |
| 8838 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8839 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8840 | } |
| 8841 | } |
| 8842 | return logicalSlotsMapping; |
| 8843 | } finally { |
| 8844 | Binder.restoreCallingIdentity(identity); |
| 8845 | } |
| 8846 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8847 | |
| 8848 | /** |
| 8849 | * Get the IRadio HAL Version |
| 8850 | */ |
| 8851 | @Override |
| 8852 | public int getRadioHalVersion() { |
| 8853 | Phone phone = getDefaultPhone(); |
| 8854 | if (phone == null) return -1; |
| 8855 | HalVersion hv = phone.getHalVersion(); |
| 8856 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8857 | return hv.major * 100 + hv.minor; |
| 8858 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8859 | |
| 8860 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8861 | * Get the current calling package name. |
| 8862 | * @return the current calling package name |
| 8863 | */ |
| 8864 | @Override |
| 8865 | public String getCurrentPackageName() { |
| 8866 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8867 | } |
| 8868 | |
| 8869 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8870 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8871 | * corresponding network requests on a subId. |
| 8872 | * |
| 8873 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8874 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8875 | * 2) APN is un-metered for this subscription, or |
| 8876 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 8877 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8878 | * |
| 8879 | * @return whether data is allowed for a apn type. |
| 8880 | * |
| 8881 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8882 | */ |
| 8883 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8884 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8885 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8886 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8887 | |
| 8888 | // Now that all security checks passes, perform the operation as ourselves. |
| 8889 | final long identity = Binder.clearCallingIdentity(); |
| 8890 | try { |
| 8891 | Phone phone = getPhone(subId); |
| 8892 | if (phone == null) return false; |
| 8893 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8894 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8895 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8896 | } finally { |
| 8897 | Binder.restoreCallingIdentity(identity); |
| 8898 | } |
| 8899 | } |
| 8900 | |
| 8901 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8902 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8903 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8904 | |
| 8905 | // Now that all security checks passes, perform the operation as ourselves. |
| 8906 | final long identity = Binder.clearCallingIdentity(); |
| 8907 | try { |
| 8908 | Phone phone = getPhone(subId); |
| 8909 | if (phone == null) return true; // By default return true. |
| 8910 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8911 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8912 | } finally { |
| 8913 | Binder.restoreCallingIdentity(identity); |
| 8914 | } |
| 8915 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8916 | |
| 8917 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 8918 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 8919 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 8920 | enforceModifyPermission(); |
| 8921 | long token = Binder.clearCallingIdentity(); |
| 8922 | try { |
| 8923 | Phone phone = getPhone(subscriptionId); |
| 8924 | if (phone == null) { |
| 8925 | try { |
| 8926 | if (resultCallback != null) { |
| 8927 | resultCallback.accept(false); |
| 8928 | } |
| 8929 | } catch (RemoteException e) { |
| 8930 | // ignore |
| 8931 | } |
| 8932 | return; |
| 8933 | } |
| 8934 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 8935 | Pair.create(specifiers, (x) -> { |
| 8936 | try { |
| 8937 | if (resultCallback != null) { |
| 8938 | resultCallback.accept(x); |
| 8939 | } |
| 8940 | } catch (RemoteException e) { |
| 8941 | // ignore |
| 8942 | } |
| 8943 | }); |
| 8944 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 8945 | } finally { |
| 8946 | Binder.restoreCallingIdentity(token); |
| 8947 | } |
| 8948 | } |
| 8949 | |
| 8950 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 8951 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 8952 | TelephonyPermissions |
| 8953 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8954 | mApp, subId, "getSystemSelectionChannels"); |
| 8955 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8956 | final long identity = Binder.clearCallingIdentity(); |
| 8957 | try { |
| 8958 | List<RadioAccessSpecifier> specifiers = |
| 8959 | (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, |
| 8960 | null, subId, workSource); |
| 8961 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 8962 | return specifiers; |
| 8963 | } finally { |
| 8964 | Binder.restoreCallingIdentity(identity); |
| 8965 | } |
| 8966 | } |
| 8967 | |
| 8968 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8969 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 8970 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8971 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 8972 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 8973 | if (iccRecords == null) { |
| 8974 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 8975 | return false; |
| 8976 | } |
| 8977 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 8978 | } |
| 8979 | |
| 8980 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8981 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 8982 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8983 | if (callingPackage == null) { |
| 8984 | callingPackage = getCurrentPackageName(); |
| 8985 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8986 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 8987 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 8988 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 8989 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8990 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 8991 | } |
| 8992 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 8993 | Intent intent = new Intent(); |
| 8994 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 8995 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 8996 | // Bring up choose default SMS subscription dialog right now |
| 8997 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 8998 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 8999 | mApp.startActivity(intent); |
| 9000 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9001 | |
| 9002 | @Override |
| 9003 | public String getMmsUAProfUrl(int subId) { |
| 9004 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9005 | final long identity = Binder.clearCallingIdentity(); |
| 9006 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9007 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9008 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9009 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9010 | return carrierUAProfUrl; |
| 9011 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9012 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9013 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9014 | } finally { |
| 9015 | Binder.restoreCallingIdentity(identity); |
| 9016 | } |
| 9017 | } |
| 9018 | |
| 9019 | @Override |
| 9020 | public String getMmsUserAgent(int subId) { |
| 9021 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9022 | final long identity = Binder.clearCallingIdentity(); |
| 9023 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9024 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9025 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9026 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9027 | return carrierUserAgent; |
| 9028 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9029 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9030 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9031 | } finally { |
| 9032 | Binder.restoreCallingIdentity(identity); |
| 9033 | } |
| 9034 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9035 | |
| 9036 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9037 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9038 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9039 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9040 | final long identity = Binder.clearCallingIdentity(); |
| 9041 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9042 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9043 | if (phone == null) return false; |
| 9044 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9045 | switch (policy) { |
| 9046 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9047 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9048 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9049 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9050 | default: |
| 9051 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9052 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9053 | } finally { |
| 9054 | Binder.restoreCallingIdentity(identity); |
| 9055 | } |
| 9056 | } |
| 9057 | |
| 9058 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9059 | public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy, |
| 9060 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9061 | enforceModifyPermission(); |
| 9062 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9063 | final long identity = Binder.clearCallingIdentity(); |
| 9064 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9065 | Phone phone = getPhone(subscriptionId); |
| 9066 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9067 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9068 | switch (policy) { |
| 9069 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9070 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9071 | break; |
| 9072 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9073 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9074 | break; |
| 9075 | default: |
| 9076 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9077 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9078 | } finally { |
| 9079 | Binder.restoreCallingIdentity(identity); |
| 9080 | } |
| 9081 | } |
| 9082 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9083 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9084 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9085 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9086 | * otherwise. |
| 9087 | */ |
| 9088 | @Override |
| 9089 | public void setCepEnabled(boolean isCepEnabled) { |
| 9090 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9091 | |
| 9092 | final long identity = Binder.clearCallingIdentity(); |
| 9093 | try { |
| 9094 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9095 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9096 | Phone defaultPhone = phone.getImsPhone(); |
| 9097 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9098 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9099 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9100 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9101 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9102 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9103 | + imsPhone.getMsisdn()); |
| 9104 | } |
| 9105 | } |
| 9106 | } finally { |
| 9107 | Binder.restoreCallingIdentity(identity); |
| 9108 | } |
| 9109 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9110 | |
| 9111 | /** |
| 9112 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9113 | * |
| 9114 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9115 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9116 | * before being read. |
| 9117 | */ |
| 9118 | @Override |
| 9119 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9120 | isCompressed) { |
| 9121 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9122 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
| 9123 | try { |
| 9124 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 9125 | if (configBinder == null) { |
| 9126 | Rlog.e(LOG_TAG, "null result for getImsConfig"); |
| 9127 | } else { |
| 9128 | configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed); |
| 9129 | } |
| 9130 | } catch (RemoteException e) { |
| 9131 | Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage()); |
| 9132 | } |
| 9133 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9134 | |
| 9135 | @Override |
| 9136 | public boolean isIccLockEnabled(int subId) { |
| 9137 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9138 | |
| 9139 | // Now that all security checks passes, perform the operation as ourselves. |
| 9140 | final long identity = Binder.clearCallingIdentity(); |
| 9141 | try { |
| 9142 | Phone phone = getPhone(subId); |
| 9143 | if (phone != null && phone.getIccCard() != null) { |
| 9144 | return phone.getIccCard().getIccLockEnabled(); |
| 9145 | } else { |
| 9146 | return false; |
| 9147 | } |
| 9148 | } finally { |
| 9149 | Binder.restoreCallingIdentity(identity); |
| 9150 | } |
| 9151 | } |
| 9152 | |
| 9153 | /** |
| 9154 | * Set the ICC pin lock enabled or disabled. |
| 9155 | * |
| 9156 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9157 | * three cases: |
| 9158 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9159 | * successfully. |
| 9160 | * - Positive number and zero for remaining password attempts. |
| 9161 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9162 | * |
| 9163 | */ |
| 9164 | @Override |
| 9165 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9166 | enforceModifyPermission(); |
| 9167 | |
| 9168 | Phone phone = getPhone(subId); |
| 9169 | if (phone == null) { |
| 9170 | return 0; |
| 9171 | } |
| 9172 | // Now that all security checks passes, perform the operation as ourselves. |
| 9173 | final long identity = Binder.clearCallingIdentity(); |
| 9174 | try { |
| 9175 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9176 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9177 | return attemptsRemaining; |
| 9178 | |
| 9179 | } catch (Exception e) { |
| 9180 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9181 | } finally { |
| 9182 | Binder.restoreCallingIdentity(identity); |
| 9183 | } |
| 9184 | return 0; |
| 9185 | } |
| 9186 | |
| 9187 | /** |
| 9188 | * Change the ICC password used in ICC pin lock. |
| 9189 | * |
| 9190 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9191 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9192 | * - Positive number and zero for remaining password attempts. |
| 9193 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9194 | * |
| 9195 | */ |
| 9196 | @Override |
| 9197 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9198 | enforceModifyPermission(); |
| 9199 | |
| 9200 | Phone phone = getPhone(subId); |
| 9201 | if (phone == null) { |
| 9202 | return 0; |
| 9203 | } |
| 9204 | // Now that all security checks passes, perform the operation as ourselves. |
| 9205 | final long identity = Binder.clearCallingIdentity(); |
| 9206 | try { |
| 9207 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9208 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9209 | return attemptsRemaining; |
| 9210 | |
| 9211 | } catch (Exception e) { |
| 9212 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9213 | } finally { |
| 9214 | Binder.restoreCallingIdentity(identity); |
| 9215 | } |
| 9216 | return 0; |
| 9217 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9218 | |
| 9219 | /** |
| 9220 | * Request for receiving user activity notification |
| 9221 | */ |
| 9222 | @Override |
| 9223 | public void requestUserActivityNotification() { |
| 9224 | if (!mNotifyUserActivity.get() |
| 9225 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9226 | mNotifyUserActivity.set(true); |
| 9227 | } |
| 9228 | } |
| 9229 | |
| 9230 | /** |
| 9231 | * Called when userActivity is signalled in the power manager. |
| 9232 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9233 | */ |
| 9234 | @Override |
| 9235 | public void userActivity() { |
| 9236 | // *************************************** |
| 9237 | // * Inherited from PhoneWindowManager * |
| 9238 | // *************************************** |
| 9239 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9240 | // WITH ITS LOCKS HELD. |
| 9241 | // |
| 9242 | // This code must be VERY careful about the locks |
| 9243 | // it acquires. |
| 9244 | // In fact, the current code acquires way too many, |
| 9245 | // and probably has lurking deadlocks. |
| 9246 | |
| 9247 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9248 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9249 | } |
| 9250 | |
| 9251 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9252 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9253 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9254 | } |
| 9255 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9256 | |
| 9257 | @Override |
| 9258 | public boolean canConnectTo5GInDsdsMode() { |
| 9259 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9260 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9261 | |
| 9262 | @Override |
| 9263 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 9264 | String callingFeatureId) { |
| 9265 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 9266 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 9267 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9268 | } |
| 9269 | |
| 9270 | Phone phone = getPhone(subId); |
| 9271 | if (phone == null) { |
| 9272 | throw new RuntimeException("phone is not available"); |
| 9273 | } |
| 9274 | // Now that all security checks passes, perform the operation as ourselves. |
| 9275 | final long identity = Binder.clearCallingIdentity(); |
| 9276 | try { |
| 9277 | return phone.getEquivalentHomePlmns(); |
| 9278 | } finally { |
| 9279 | Binder.restoreCallingIdentity(identity); |
| 9280 | } |
| 9281 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9282 | |
| 9283 | @Override |
| 9284 | public boolean isRadioInterfaceCapabilitySupported( |
| 9285 | @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 9286 | RadioInterfaceCapabilities radioInterfaceCapabilities = |
| 9287 | mPhoneConfigurationManager.getRadioInterfaceCapabilities(); |
| 9288 | if (radioInterfaceCapabilities == null) { |
| 9289 | throw new RuntimeException("radio interface capabilities are not available"); |
| 9290 | } else { |
| 9291 | return radioInterfaceCapabilities.isSupported(capability); |
| 9292 | } |
| 9293 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9294 | |
| 9295 | /** |
| 9296 | * Attempts to set the radio power state for thermal reason. This does not guarantee that the |
| 9297 | * requested radio power state will actually be set. See {@link |
| 9298 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 9299 | * |
| 9300 | * @param subId the subscription ID of the phone requesting to set the radio power state. |
| 9301 | * @param enable {@code true} if trying to turn radio on. |
| 9302 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 9303 | * false}. |
| 9304 | */ |
| 9305 | private boolean setRadioPowerForThermal(int subId, boolean enable) { |
| 9306 | Phone phone = getPhone(subId); |
| 9307 | if (phone != null) { |
| 9308 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 9309 | return true; |
| 9310 | } |
| 9311 | return false; |
| 9312 | } |
| 9313 | |
| 9314 | private int handleDataThrottlingRequest(int subId, |
| 9315 | DataThrottlingRequest dataThrottlingRequest) { |
| 9316 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 9317 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9318 | if (!setRadioPowerForThermal(subId, true)) { |
| 9319 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9320 | } |
| 9321 | |
| 9322 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 9323 | |
| 9324 | int thermalMitigationResult = |
| 9325 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
| 9326 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 9327 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 9328 | } |
| 9329 | return thermalMitigationResult; |
| 9330 | } |
| 9331 | |
| 9332 | /** |
| 9333 | * Thermal mitigation request to control functionalities at modem. |
| 9334 | * |
| 9335 | * @param subId the id of the subscription. |
| 9336 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
| 9337 | * |
| 9338 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 9339 | */ |
| 9340 | @Override |
| 9341 | @ThermalMitigationResult |
| 9342 | public int sendThermalMitigationRequest( |
| 9343 | int subId, |
| 9344 | ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException { |
| 9345 | enforceModifyPermission(); |
| 9346 | |
| 9347 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9348 | final long identity = Binder.clearCallingIdentity(); |
| 9349 | |
| 9350 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 9351 | try { |
| 9352 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 9353 | switch (thermalMitigationAction) { |
| 9354 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 9355 | thermalMitigationResult = |
| 9356 | handleDataThrottlingRequest(subId, |
| 9357 | thermalMitigationRequest.getDataThrottlingRequest()); |
| 9358 | break; |
| 9359 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 9360 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9361 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 9362 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 9363 | } |
| 9364 | |
| 9365 | // Ensure that radio is on. If not able to power on due to phone being |
| 9366 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9367 | if (!setRadioPowerForThermal(subId, true)) { |
| 9368 | thermalMitigationResult = |
| 9369 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9370 | break; |
| 9371 | } |
| 9372 | |
| 9373 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 9374 | false); |
| 9375 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9376 | break; |
| 9377 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 9378 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9379 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 9380 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 9381 | } |
| 9382 | |
| 9383 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 9384 | if (registry != null) { |
| 9385 | TelephonyConnectionService service = |
| 9386 | registry.getTelephonyConnectionService(); |
| 9387 | Phone phone = getPhone(subId); |
| 9388 | if (phone == null) { |
| 9389 | thermalMitigationResult = |
| 9390 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9391 | break; |
| 9392 | } |
| 9393 | |
| 9394 | if (PhoneConstantConversions.convertCallState(phone.getState()) |
| 9395 | != TelephonyManager.CALL_STATE_IDLE |
| 9396 | || phone.isInEmergencySmsMode() || phone.isInEcm() |
| 9397 | || (service != null && service.isEmergencyCallPending())) { |
| 9398 | String errorMessage = "Phone state is not valid. call state = " |
| 9399 | + PhoneConstantConversions.convertCallState(phone.getState()) |
| 9400 | + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode() |
| 9401 | + " isInEmergencyCallbackMode = " + phone.isInEcm(); |
| 9402 | errorMessage += service == null |
| 9403 | ? " TelephonyConnectionService is null" |
| 9404 | : " isEmergencyCallPending = " |
| 9405 | + service.isEmergencyCallPending(); |
| 9406 | Log.e(LOG_TAG, errorMessage); |
| 9407 | thermalMitigationResult = |
| 9408 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 9409 | break; |
| 9410 | } |
| 9411 | } else { |
| 9412 | thermalMitigationResult = |
| 9413 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9414 | break; |
| 9415 | } |
| 9416 | |
| 9417 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 9418 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9419 | if (!setRadioPowerForThermal(subId, false)) { |
| 9420 | thermalMitigationResult = |
| 9421 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9422 | break; |
| 9423 | } |
| 9424 | thermalMitigationResult = |
| 9425 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9426 | break; |
| 9427 | default: |
| 9428 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 9429 | + "not exist. Requested action: " + thermalMitigationAction); |
| 9430 | } |
| 9431 | } catch (IllegalArgumentException e) { |
| 9432 | throw e; |
| 9433 | } catch (Exception e) { |
| 9434 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 9435 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 9436 | } finally { |
| 9437 | Binder.restoreCallingIdentity(identity); |
| 9438 | } |
| 9439 | |
| 9440 | if (DBG) { |
| 9441 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 9442 | + thermalMitigationResult); |
| 9443 | } |
| 9444 | |
| 9445 | return thermalMitigationResult; |
| 9446 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 9447 | } |