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; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 29 | import android.app.role.RoleManager; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 30 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 31 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 32 | import android.content.Context; |
| 33 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 34 | import android.content.SharedPreferences; |
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; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 80 | import android.telephony.IBootstrapAuthenticationCallback; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 81 | import android.telephony.ICellInfoCallback; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 82 | import android.telephony.IccOpenLogicalChannelResponse; |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 83 | import android.telephony.LocationAccessPolicy; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 84 | import android.telephony.ModemActivityInfo; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 85 | import android.telephony.NeighboringCellInfo; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 86 | import android.telephony.NetworkScanRequest; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 87 | import android.telephony.PhoneCapability; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 88 | import android.telephony.PhoneNumberRange; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 89 | import android.telephony.RadioAccessFamily; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 90 | import android.telephony.RadioAccessSpecifier; |
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; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 93 | import android.telephony.SignalStrengthUpdateRequest; |
| 94 | import android.telephony.SignalThresholdInfo; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 95 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 96 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 97 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 98 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 99 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 100 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 101 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 102 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 103 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 104 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 105 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 106 | import android.telephony.data.ApnSetting; |
| 107 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 108 | import android.telephony.gba.GbaAuthRequest; |
| 109 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 110 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 111 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 112 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 113 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 114 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 115 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 116 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 117 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 118 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 119 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 120 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 121 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 122 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 123 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 124 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 125 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 126 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 127 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 128 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 129 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 130 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 131 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 132 | import com.android.ims.internal.IImsServiceFeatureCallback; |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 133 | import com.android.ims.rcs.uce.eab.EabUtil; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 134 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 136 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 138 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 139 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 141 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 142 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 143 | import com.android.internal.telephony.GbaManager; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 144 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 145 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 146 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 148 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 150 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 154 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 156 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.RIL; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 164 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 165 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 168 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 170 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 172 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 173 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 175 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 176 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 177 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 178 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 179 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 180 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 181 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 182 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 183 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 184 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 185 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 186 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 187 | import com.android.internal.util.HexDump; |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 188 | import com.android.phone.callcomposer.CallComposerPictureManager; |
| 189 | import com.android.phone.callcomposer.CallComposerPictureTransfer; |
| 190 | import com.android.phone.callcomposer.ImageData; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 191 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 192 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 193 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 194 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 195 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 196 | import com.android.services.telephony.TelecomAccountRegistry; |
| 197 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 198 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 199 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 200 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 201 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 202 | import java.io.IOException; |
| 203 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 204 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 205 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 206 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 207 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 208 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 209 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 210 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 211 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 212 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 213 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 214 | import java.util.Set; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 215 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 216 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 217 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 218 | |
| 219 | /** |
| 220 | * Implementation of the ITelephony interface. |
| 221 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 222 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 223 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 224 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 225 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 226 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 227 | |
| 228 | // Message codes used with mMainThreadHandler |
| 229 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 230 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 231 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 232 | private static final int CMD_OPEN_CHANNEL = 9; |
| 233 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 234 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 235 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 236 | private static final int CMD_NV_READ_ITEM = 13; |
| 237 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 238 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 239 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 240 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 241 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 242 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 243 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 244 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 245 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 246 | private static final int CMD_SEND_ENVELOPE = 25; |
| 247 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 248 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 249 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 250 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 251 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 252 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 253 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 254 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 255 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 256 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 257 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 258 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 259 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 260 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 261 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 262 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 263 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 264 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 265 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 266 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 267 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 268 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 269 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 270 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 271 | private static final int CMD_SWITCH_SLOTS = 50; |
| 272 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 273 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 274 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 275 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 276 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 277 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 278 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 279 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 280 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 281 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 282 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 283 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 284 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 285 | private static final int CMD_MODEM_REBOOT = 64; |
| 286 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 287 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 288 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 289 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 290 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 291 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 292 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 293 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 294 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 295 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 296 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 297 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 298 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 299 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 300 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 301 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 302 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 303 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 304 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 305 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 306 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 307 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 308 | private static final int CMD_GET_CALL_WAITING = 87; |
| 309 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 310 | private static final int CMD_SET_CALL_WAITING = 89; |
| 311 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 312 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 313 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 314 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 315 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 316 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 317 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 318 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 319 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 320 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 321 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 322 | private static final int CMD_SET_SIM_POWER = 101; |
| 323 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 324 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 325 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 326 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 327 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 328 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 329 | private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 330 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 331 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 332 | // Parameters of select command. |
| 333 | private static final int SELECT_COMMAND = 0xA4; |
| 334 | private static final int SELECT_P1 = 0x04; |
| 335 | private static final int SELECT_P2 = 0; |
| 336 | private static final int SELECT_P3 = 0x10; |
| 337 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 338 | /** The singleton instance. */ |
| 339 | private static PhoneInterfaceManager sInstance; |
| 340 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 341 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 342 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 343 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 344 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 345 | private AppOpsManager mAppOps; |
| 346 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 347 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 348 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 349 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 350 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 351 | /** User Activity */ |
| 352 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 353 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 354 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 355 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 356 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 357 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 358 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 359 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 360 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 361 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 362 | // String to store multi SIM allowed |
| 363 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 364 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 365 | // The AID of ISD-R. |
| 366 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 367 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 368 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 369 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 370 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 371 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 372 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 373 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
| 374 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 375 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 376 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 377 | */ |
| 378 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 379 | "reset_network_erase_modem_config_enabled"; |
| 380 | |
| 381 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 382 | * A request object to use for transmitting data to an ICC. |
| 383 | */ |
| 384 | private static final class IccAPDUArgument { |
| 385 | public int channel, cla, command, p1, p2, p3; |
| 386 | public String data; |
| 387 | |
| 388 | public IccAPDUArgument(int channel, int cla, int command, |
| 389 | int p1, int p2, int p3, String data) { |
| 390 | this.channel = channel; |
| 391 | this.cla = cla; |
| 392 | this.command = command; |
| 393 | this.p1 = p1; |
| 394 | this.p2 = p2; |
| 395 | this.p3 = p3; |
| 396 | this.data = data; |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 401 | * A request object to use for transmitting data to an ICC. |
| 402 | */ |
| 403 | private static final class ManualNetworkSelectionArgument { |
| 404 | public OperatorInfo operatorInfo; |
| 405 | public boolean persistSelection; |
| 406 | |
| 407 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 408 | this.operatorInfo = operatorInfo; |
| 409 | this.persistSelection = persistSelection; |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 414 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 415 | * request after sending. The main thread will notify the request when it is complete. |
| 416 | */ |
| 417 | private static final class MainThreadRequest { |
| 418 | /** The argument to use for the request */ |
| 419 | public Object argument; |
| 420 | /** The result of the request that is run on the main thread */ |
| 421 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 422 | // The subscriber id that this request applies to. Defaults to |
| 423 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 424 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 425 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 426 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 427 | public Phone phone; |
| 428 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 429 | public WorkSource workSource; |
| 430 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 431 | public MainThreadRequest(Object argument) { |
| 432 | this.argument = argument; |
| 433 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 434 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 435 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 436 | this.argument = argument; |
| 437 | if (phone != null) { |
| 438 | this.phone = phone; |
| 439 | } |
| 440 | this.workSource = workSource; |
| 441 | } |
| 442 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 443 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 444 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 445 | if (subId != null) { |
| 446 | this.subId = subId; |
| 447 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 448 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 449 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 450 | } |
| 451 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 452 | private static final class IncomingThirdPartyCallArgs { |
| 453 | public final ComponentName component; |
| 454 | public final String callId; |
| 455 | public final String callerDisplayName; |
| 456 | |
| 457 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 458 | String callerDisplayName) { |
| 459 | this.component = component; |
| 460 | this.callId = callId; |
| 461 | this.callerDisplayName = callerDisplayName; |
| 462 | } |
| 463 | } |
| 464 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 465 | /** |
| 466 | * A handler that processes messages on the main thread in the phone process. Since many |
| 467 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 468 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 469 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 470 | * on, which will be notified when the operation completes and will contain the result of the |
| 471 | * request. |
| 472 | * |
| 473 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 474 | * note that request.result must be set to something non-null for the calling thread to |
| 475 | * unblock. |
| 476 | */ |
| 477 | private final class MainThreadHandler extends Handler { |
| 478 | @Override |
| 479 | public void handleMessage(Message msg) { |
| 480 | MainThreadRequest request; |
| 481 | Message onCompleted; |
| 482 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 483 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 484 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 485 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 486 | |
| 487 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 488 | case CMD_HANDLE_USSD_REQUEST: { |
| 489 | request = (MainThreadRequest) msg.obj; |
| 490 | final Phone phone = getPhoneFromRequest(request); |
| 491 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 492 | String ussdRequest = ussdObject.first; |
| 493 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 494 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 495 | if (!isUssdApiAllowed(request.subId)) { |
| 496 | // Carrier does not support use of this API, return failure. |
| 497 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 498 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 499 | Bundle returnData = new Bundle(); |
| 500 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 501 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 502 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 503 | request.result = true; |
| 504 | notifyRequester(request); |
| 505 | return; |
| 506 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 507 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 508 | try { |
| 509 | request.result = phone != null |
| 510 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 511 | } catch (CallStateException cse) { |
| 512 | request.result = false; |
| 513 | } |
| 514 | // Wake up the requesting thread |
| 515 | notifyRequester(request); |
| 516 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 517 | } |
| 518 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 519 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 520 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 521 | final Phone phone = getPhoneFromRequest(request); |
| 522 | request.result = phone != null ? |
| 523 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 524 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 525 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 526 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 527 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 528 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 529 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 530 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 531 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 532 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 533 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 534 | if (uiccCard == null) { |
| 535 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 536 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 537 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 538 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 539 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 540 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 541 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 542 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 543 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 544 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 545 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 546 | break; |
| 547 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 548 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 549 | ar = (AsyncResult) msg.obj; |
| 550 | request = (MainThreadRequest) ar.userObj; |
| 551 | if (ar.exception == null && ar.result != null) { |
| 552 | request.result = ar.result; |
| 553 | } else { |
| 554 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 555 | if (ar.result == null) { |
| 556 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 557 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 558 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 559 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 560 | } else { |
| 561 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 562 | } |
| 563 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 564 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 565 | break; |
| 566 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 567 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 568 | request = (MainThreadRequest) msg.obj; |
| 569 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 570 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 571 | if (uiccCard == null) { |
| 572 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 573 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 574 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 575 | } else { |
| 576 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 577 | request); |
| 578 | uiccCard.iccTransmitApduBasicChannel( |
| 579 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 580 | iccArgument.p3, iccArgument.data, onCompleted); |
| 581 | } |
| 582 | break; |
| 583 | |
| 584 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 585 | ar = (AsyncResult) msg.obj; |
| 586 | request = (MainThreadRequest) ar.userObj; |
| 587 | if (ar.exception == null && ar.result != null) { |
| 588 | request.result = ar.result; |
| 589 | } else { |
| 590 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 591 | if (ar.result == null) { |
| 592 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 593 | } else if (ar.exception instanceof CommandException) { |
| 594 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 595 | ar.exception); |
| 596 | } else { |
| 597 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 598 | } |
| 599 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 600 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 601 | break; |
| 602 | |
| 603 | case CMD_EXCHANGE_SIM_IO: |
| 604 | request = (MainThreadRequest) msg.obj; |
| 605 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 606 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 607 | if (uiccCard == null) { |
| 608 | loge("iccExchangeSimIO: No UICC"); |
| 609 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 610 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 611 | } else { |
| 612 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 613 | request); |
| 614 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 615 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 616 | iccArgument.data, onCompleted); |
| 617 | } |
| 618 | break; |
| 619 | |
| 620 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 621 | ar = (AsyncResult) msg.obj; |
| 622 | request = (MainThreadRequest) ar.userObj; |
| 623 | if (ar.exception == null && ar.result != null) { |
| 624 | request.result = ar.result; |
| 625 | } else { |
| 626 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 627 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 628 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 629 | break; |
| 630 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 631 | case CMD_SEND_ENVELOPE: |
| 632 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 633 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 634 | if (uiccCard == null) { |
| 635 | loge("sendEnvelopeWithStatus: No UICC"); |
| 636 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 637 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 638 | } else { |
| 639 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 640 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 641 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 642 | break; |
| 643 | |
| 644 | case EVENT_SEND_ENVELOPE_DONE: |
| 645 | ar = (AsyncResult) msg.obj; |
| 646 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 647 | if (ar.exception == null && ar.result != null) { |
| 648 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 649 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 650 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 651 | if (ar.result == null) { |
| 652 | loge("sendEnvelopeWithStatus: Empty response"); |
| 653 | } else if (ar.exception instanceof CommandException) { |
| 654 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 655 | ar.exception); |
| 656 | } else { |
| 657 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 658 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 659 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 660 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 661 | break; |
| 662 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 663 | case CMD_OPEN_CHANNEL: |
| 664 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 665 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 666 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 667 | if (uiccCard == null) { |
| 668 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 669 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 670 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 671 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 672 | } else { |
| 673 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 674 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 675 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 676 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 677 | break; |
| 678 | |
| 679 | case EVENT_OPEN_CHANNEL_DONE: |
| 680 | ar = (AsyncResult) msg.obj; |
| 681 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 682 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 683 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 684 | int[] result = (int[]) ar.result; |
| 685 | int channelId = result[0]; |
| 686 | byte[] selectResponse = null; |
| 687 | if (result.length > 1) { |
| 688 | selectResponse = new byte[result.length - 1]; |
| 689 | for (int i = 1; i < result.length; ++i) { |
| 690 | selectResponse[i - 1] = (byte) result[i]; |
| 691 | } |
| 692 | } |
| 693 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 694 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 695 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 696 | if (ar.result == null) { |
| 697 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 698 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 699 | if (ar.exception != null) { |
| 700 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 701 | } |
| 702 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 703 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 704 | if (ar.exception instanceof CommandException) { |
| 705 | CommandException.Error error = |
| 706 | ((CommandException) (ar.exception)).getCommandError(); |
| 707 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 708 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 709 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 710 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 711 | } |
| 712 | } |
| 713 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 714 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 715 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 716 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 717 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 718 | break; |
| 719 | |
| 720 | case CMD_CLOSE_CHANNEL: |
| 721 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 722 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 723 | if (uiccCard == null) { |
| 724 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 725 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 726 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 727 | } else { |
| 728 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 729 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 730 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 731 | break; |
| 732 | |
| 733 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 734 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 735 | break; |
| 736 | |
| 737 | case CMD_NV_READ_ITEM: |
| 738 | request = (MainThreadRequest) msg.obj; |
| 739 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 740 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 741 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 742 | break; |
| 743 | |
| 744 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 745 | ar = (AsyncResult) msg.obj; |
| 746 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 747 | if (ar.exception == null && ar.result != null) { |
| 748 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 749 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 750 | request.result = ""; |
| 751 | if (ar.result == null) { |
| 752 | loge("nvReadItem: Empty response"); |
| 753 | } else if (ar.exception instanceof CommandException) { |
| 754 | loge("nvReadItem: CommandException: " + |
| 755 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 756 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 757 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 758 | } |
| 759 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 760 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 761 | break; |
| 762 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 763 | case CMD_NV_WRITE_ITEM: |
| 764 | request = (MainThreadRequest) msg.obj; |
| 765 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 766 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 767 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 768 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 769 | break; |
| 770 | |
| 771 | case EVENT_NV_WRITE_ITEM_DONE: |
| 772 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 773 | break; |
| 774 | |
| 775 | case CMD_NV_WRITE_CDMA_PRL: |
| 776 | request = (MainThreadRequest) msg.obj; |
| 777 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 778 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 779 | break; |
| 780 | |
| 781 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 782 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 783 | break; |
| 784 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 785 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 786 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 787 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 788 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 789 | break; |
| 790 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 791 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 792 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 793 | break; |
| 794 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 795 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 796 | request = (MainThreadRequest) msg.obj; |
| 797 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 798 | request); |
| 799 | Phone phone = getPhoneFromRequest(request); |
| 800 | if (phone != null) { |
| 801 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 802 | } else { |
| 803 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 804 | request.result = false; |
| 805 | notifyRequester(request); |
| 806 | } |
| 807 | break; |
| 808 | } |
| 809 | |
| 810 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 811 | ar = (AsyncResult) msg.obj; |
| 812 | request = (MainThreadRequest) ar.userObj; |
| 813 | if (ar.exception == null && ar.result != null) { |
| 814 | request.result = ar.result; |
| 815 | } else { |
| 816 | // request.result must be set to something non-null |
| 817 | // for the calling thread to unblock |
| 818 | if (request.result != null) { |
| 819 | request.result = ar.result; |
| 820 | } else { |
| 821 | request.result = false; |
| 822 | } |
| 823 | if (ar.result == null) { |
| 824 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 825 | } else if (ar.exception instanceof CommandException) { |
| 826 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 827 | + ar.exception); |
| 828 | } else { |
| 829 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 830 | } |
| 831 | } |
| 832 | notifyRequester(request); |
| 833 | break; |
| 834 | |
| 835 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 836 | request = (MainThreadRequest) msg.obj; |
| 837 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 838 | Phone phone = getPhoneFromRequest(request); |
| 839 | if (phone != null) { |
| 840 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 841 | request.workSource); |
| 842 | } else { |
| 843 | loge("enableNrDualConnectivity: No phone object"); |
| 844 | request.result = |
| 845 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 846 | notifyRequester(request); |
| 847 | } |
| 848 | break; |
| 849 | } |
| 850 | |
| 851 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 852 | ar = (AsyncResult) msg.obj; |
| 853 | request = (MainThreadRequest) ar.userObj; |
| 854 | if (ar.exception == null) { |
| 855 | request.result = |
| 856 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 857 | } else { |
| 858 | request.result = |
| 859 | TelephonyManager |
| 860 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 861 | if (ar.exception instanceof CommandException) { |
| 862 | CommandException.Error error = |
| 863 | ((CommandException) (ar.exception)).getCommandError(); |
| 864 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 865 | request.result = |
| 866 | TelephonyManager |
| 867 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 868 | } |
| 869 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 870 | + ar.exception); |
| 871 | } else { |
| 872 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 873 | } |
| 874 | } |
| 875 | notifyRequester(request); |
| 876 | break; |
| 877 | } |
| 878 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 879 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 880 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 881 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 882 | request); |
| 883 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 884 | break; |
| 885 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 886 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 887 | ar = (AsyncResult) msg.obj; |
| 888 | request = (MainThreadRequest) ar.userObj; |
| 889 | if (ar.exception == null && ar.result != null) { |
| 890 | request.result = ar.result; // Integer |
| 891 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 892 | // request.result must be set to something non-null |
| 893 | // for the calling thread to unblock |
| 894 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 895 | if (ar.result == null) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 896 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 897 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 898 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 899 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 900 | } else { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 901 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 902 | } |
| 903 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 904 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 905 | break; |
| 906 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 907 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 908 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 909 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 910 | request); |
| 911 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 912 | (Pair<Integer, Long>) request.argument; |
| 913 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 914 | reasonWithNetworkTypes.first, |
| 915 | reasonWithNetworkTypes.second, |
| 916 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 917 | break; |
| 918 | |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 919 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 920 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 921 | break; |
| 922 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 923 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 924 | request = (MainThreadRequest)msg.obj; |
| 925 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 926 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 927 | break; |
| 928 | |
| 929 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 930 | ar = (AsyncResult)msg.obj; |
| 931 | request = (MainThreadRequest)ar.userObj; |
| 932 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 933 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 934 | break; |
| 935 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 936 | case CMD_SET_VOICEMAIL_NUMBER: |
| 937 | request = (MainThreadRequest) msg.obj; |
| 938 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 939 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 940 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 941 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 942 | break; |
| 943 | |
| 944 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 945 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 946 | break; |
| 947 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 948 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 949 | request = (MainThreadRequest) msg.obj; |
| 950 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 951 | request); |
| 952 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 953 | break; |
| 954 | |
| 955 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 956 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 957 | break; |
| 958 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 959 | case CMD_PERFORM_NETWORK_SCAN: |
| 960 | request = (MainThreadRequest) msg.obj; |
| 961 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 962 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 963 | break; |
| 964 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 965 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 966 | request = (MainThreadRequest) msg.obj; |
| 967 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 968 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 969 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 970 | request.argument; |
| 971 | int callForwardingReason = args.first; |
| 972 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 973 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 974 | } |
| 975 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 976 | ar = (AsyncResult) msg.obj; |
| 977 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 978 | TelephonyManager.CallForwardingInfoCallback callback = |
| 979 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 980 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 981 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 982 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 983 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 984 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 985 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 986 | // any service for voice call. |
| 987 | if ((callForwardInfo.serviceClass |
| 988 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 989 | callForwardingInfo = new CallForwardingInfo(true, |
| 990 | callForwardInfo.reason, |
| 991 | callForwardInfo.number, |
| 992 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 993 | break; |
| 994 | } |
| 995 | } |
| 996 | // Didn't find a call forward info for voice call. |
| 997 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 998 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 999 | 0 /* reason */, null /* number */, 0 /* timeout */); |
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 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1002 | } else { |
| 1003 | if (ar.result == null) { |
| 1004 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1005 | } |
| 1006 | if (ar.exception != null) { |
| 1007 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1008 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1009 | int errorCode = TelephonyManager |
| 1010 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1011 | if (ar.exception instanceof CommandException) { |
| 1012 | CommandException.Error error = |
| 1013 | ((CommandException) (ar.exception)).getCommandError(); |
| 1014 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1015 | errorCode = TelephonyManager |
| 1016 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1017 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1018 | errorCode = TelephonyManager |
| 1019 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1020 | } |
| 1021 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1022 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1023 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1024 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1025 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1026 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1027 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1028 | request = (MainThreadRequest) msg.obj; |
| 1029 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1030 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1031 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1032 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1033 | request.argument).first; |
| 1034 | request.phone.setCallForwardingOption( |
| 1035 | callForwardingInfoToSet.isEnabled() |
| 1036 | ? CommandsInterface.CF_ACTION_ENABLE |
| 1037 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1038 | callForwardingInfoToSet.getReason(), |
| 1039 | callForwardingInfoToSet.getNumber(), |
| 1040 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1041 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1042 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1043 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1044 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1045 | ar = (AsyncResult) msg.obj; |
| 1046 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1047 | Consumer<Integer> callback = |
| 1048 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1049 | request.argument).second; |
| 1050 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1051 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1052 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1053 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1054 | if (ar.exception instanceof CommandException) { |
| 1055 | CommandException.Error error = |
| 1056 | ((CommandException) (ar.exception)).getCommandError(); |
| 1057 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1058 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1059 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1060 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1061 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1062 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1063 | } |
| 1064 | } |
| 1065 | callback.accept(errorCode); |
| 1066 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1067 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1068 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1069 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1070 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1071 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1072 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1073 | request = (MainThreadRequest) msg.obj; |
| 1074 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1075 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1076 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1077 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1078 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1079 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1080 | ar = (AsyncResult) msg.obj; |
| 1081 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1082 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1083 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1084 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1085 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1086 | // Service Class is a bit mask per 3gpp 27.007. |
| 1087 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1088 | if (callForwardResults.length > 1 |
| 1089 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1090 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1091 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1092 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1093 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1094 | } else { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1095 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1096 | } |
| 1097 | } else { |
| 1098 | if (ar.result == null) { |
| 1099 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1100 | } |
| 1101 | if (ar.exception != null) { |
| 1102 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1103 | } |
| 1104 | if (ar.exception instanceof CommandException) { |
| 1105 | CommandException.Error error = |
| 1106 | ((CommandException) (ar.exception)).getCommandError(); |
| 1107 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1108 | callForwardingStatus = |
| 1109 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1110 | } |
| 1111 | } |
| 1112 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1113 | callback.accept(callForwardingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1114 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1115 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1116 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1117 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1118 | request = (MainThreadRequest) msg.obj; |
| 1119 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1120 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1121 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
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 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1125 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1126 | ar = (AsyncResult) msg.obj; |
| 1127 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1128 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1129 | Consumer<Integer> callback = |
| 1130 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1131 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1132 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1133 | if (ar.exception instanceof CommandException) { |
| 1134 | CommandException.Error error = |
| 1135 | ((CommandException) (ar.exception)).getCommandError(); |
| 1136 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1137 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1138 | } else { |
| 1139 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1140 | } |
| 1141 | } else { |
| 1142 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1143 | } |
| 1144 | } else { |
| 1145 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1146 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1147 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1148 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1149 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1150 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1151 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1152 | ar = (AsyncResult) msg.obj; |
| 1153 | request = (MainThreadRequest) ar.userObj; |
| 1154 | CellNetworkScanResult cellScanResult; |
| 1155 | if (ar.exception == null && ar.result != null) { |
| 1156 | cellScanResult = new CellNetworkScanResult( |
| 1157 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1158 | (List<OperatorInfo>) ar.result); |
| 1159 | } else { |
| 1160 | if (ar.result == null) { |
| 1161 | loge("getCellNetworkScanResults: Empty response"); |
| 1162 | } |
| 1163 | if (ar.exception != null) { |
| 1164 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1165 | } |
| 1166 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1167 | if (ar.exception instanceof CommandException) { |
| 1168 | CommandException.Error error = |
| 1169 | ((CommandException) (ar.exception)).getCommandError(); |
| 1170 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1171 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1172 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1173 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1174 | } |
| 1175 | } |
| 1176 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1177 | } |
| 1178 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1179 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1180 | break; |
| 1181 | |
| 1182 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1183 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1184 | ManualNetworkSelectionArgument selArg = |
| 1185 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1186 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1187 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1188 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1189 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1190 | break; |
| 1191 | |
| 1192 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1193 | ar = (AsyncResult) msg.obj; |
| 1194 | request = (MainThreadRequest) ar.userObj; |
| 1195 | if (ar.exception == null) { |
| 1196 | request.result = true; |
| 1197 | } else { |
| 1198 | request.result = false; |
| 1199 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1200 | } |
| 1201 | notifyRequester(request); |
| 1202 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1203 | break; |
| 1204 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1205 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1206 | request = (MainThreadRequest) msg.obj; |
| 1207 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1208 | if (defaultPhone != null) { |
| 1209 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1210 | } else { |
| 1211 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1212 | Bundle bundle = new Bundle(); |
| 1213 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1214 | new ModemActivityInfo(0, 0, 0, |
| 1215 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1216 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1217 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1218 | break; |
| 1219 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1220 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1221 | ar = (AsyncResult) msg.obj; |
| 1222 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1223 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1224 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1225 | ModemActivityInfo ret = null; |
| 1226 | int error = 0; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1227 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1228 | // Update the last modem activity info and the result of the request. |
| 1229 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1230 | if (isModemActivityInfoValid(info)) { |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1231 | int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()]; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1232 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1233 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1234 | .getTransmitTimeMillis(); |
| 1235 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1236 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1237 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1238 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1239 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1240 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1241 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1242 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1243 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1244 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1245 | info.getReceiveTimeMillis() |
| 1246 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1247 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1248 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(), |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1249 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1250 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1251 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1252 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1253 | } else { |
| 1254 | if (ar.result == null) { |
| 1255 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1256 | error = TelephonyManager.ModemActivityInfoException |
| 1257 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1258 | } else if (ar.exception instanceof CommandException) { |
| 1259 | loge("queryModemActivityInfo: CommandException: " + |
| 1260 | ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1261 | error = TelephonyManager.ModemActivityInfoException |
| 1262 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1263 | } else { |
| 1264 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1265 | error = TelephonyManager.ModemActivityInfoException |
| 1266 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1267 | } |
| 1268 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1269 | Bundle bundle = new Bundle(); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1270 | if (ret != null) { |
| 1271 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1272 | } else { |
| 1273 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1274 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1275 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1276 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1277 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1278 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1279 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1280 | case CMD_SET_ALLOWED_CARRIERS: |
| 1281 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1282 | CarrierRestrictionRules argument = |
| 1283 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1284 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1285 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1286 | break; |
| 1287 | |
| 1288 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1289 | ar = (AsyncResult) msg.obj; |
| 1290 | request = (MainThreadRequest) ar.userObj; |
| 1291 | if (ar.exception == null && ar.result != null) { |
| 1292 | request.result = ar.result; |
| 1293 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1294 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1295 | if (ar.exception instanceof CommandException) { |
| 1296 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1297 | CommandException.Error error = |
| 1298 | ((CommandException) (ar.exception)).getCommandError(); |
| 1299 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1300 | request.result = |
| 1301 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1302 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1303 | } else { |
| 1304 | loge("setAllowedCarriers: 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 | |
| 1310 | case CMD_GET_ALLOWED_CARRIERS: |
| 1311 | request = (MainThreadRequest) msg.obj; |
| 1312 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1313 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1314 | break; |
| 1315 | |
| 1316 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1317 | ar = (AsyncResult) msg.obj; |
| 1318 | request = (MainThreadRequest) ar.userObj; |
| 1319 | if (ar.exception == null && ar.result != null) { |
| 1320 | request.result = ar.result; |
| 1321 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1322 | request.result = new IllegalStateException( |
| 1323 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1324 | if (ar.result == null) { |
| 1325 | loge("getAllowedCarriers: Empty response"); |
| 1326 | } else if (ar.exception instanceof CommandException) { |
| 1327 | loge("getAllowedCarriers: CommandException: " + |
| 1328 | ar.exception); |
| 1329 | } else { |
| 1330 | loge("getAllowedCarriers: Unknown exception"); |
| 1331 | } |
| 1332 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1333 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1334 | break; |
| 1335 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1336 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1337 | ar = (AsyncResult) msg.obj; |
| 1338 | request = (MainThreadRequest) ar.userObj; |
| 1339 | if (ar.exception == null && ar.result != null) { |
| 1340 | request.result = ar.result; |
| 1341 | } else { |
| 1342 | request.result = new IllegalArgumentException( |
| 1343 | "Failed to retrieve Forbidden Plmns"); |
| 1344 | if (ar.result == null) { |
| 1345 | loge("getForbiddenPlmns: Empty response"); |
| 1346 | } else { |
| 1347 | loge("getForbiddenPlmns: Unknown exception"); |
| 1348 | } |
| 1349 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1350 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1351 | break; |
| 1352 | |
| 1353 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1354 | request = (MainThreadRequest) msg.obj; |
| 1355 | uiccCard = getUiccCardFromRequest(request); |
| 1356 | if (uiccCard == null) { |
| 1357 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1358 | request.result = new IllegalArgumentException( |
| 1359 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1360 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1361 | break; |
| 1362 | } |
| 1363 | Integer appType = (Integer) request.argument; |
| 1364 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1365 | if (uiccApp == null) { |
| 1366 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1367 | + appType); |
| 1368 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1369 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1370 | break; |
| 1371 | } else { |
| 1372 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1373 | + " specified type -- " + appType); |
| 1374 | } |
| 1375 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1376 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1377 | onCompleted); |
| 1378 | break; |
| 1379 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1380 | case CMD_SWITCH_SLOTS: |
| 1381 | request = (MainThreadRequest) msg.obj; |
| 1382 | int[] physicalSlots = (int[]) request.argument; |
| 1383 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1384 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1385 | break; |
| 1386 | |
| 1387 | case EVENT_SWITCH_SLOTS_DONE: |
| 1388 | ar = (AsyncResult) msg.obj; |
| 1389 | request = (MainThreadRequest) ar.userObj; |
| 1390 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1391 | notifyRequester(request); |
| 1392 | break; |
| 1393 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1394 | request = (MainThreadRequest) msg.obj; |
| 1395 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1396 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1397 | break; |
| 1398 | |
| 1399 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1400 | ar = (AsyncResult) msg.obj; |
| 1401 | request = (MainThreadRequest) ar.userObj; |
| 1402 | if (ar.exception != null) { |
| 1403 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1404 | } else { |
| 1405 | int mode = ((int[]) ar.result)[0]; |
| 1406 | if (mode == 0) { |
| 1407 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1408 | } else { |
| 1409 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1410 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1411 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1412 | notifyRequester(request); |
| 1413 | break; |
| 1414 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1415 | request = (MainThreadRequest) msg.obj; |
| 1416 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1417 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1418 | break; |
| 1419 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1420 | ar = (AsyncResult) msg.obj; |
| 1421 | request = (MainThreadRequest) ar.userObj; |
| 1422 | if (ar.exception != null) { |
| 1423 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1424 | } else { |
| 1425 | request.result = ((int[]) ar.result)[0]; |
| 1426 | } |
| 1427 | notifyRequester(request); |
| 1428 | break; |
| 1429 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1430 | request = (MainThreadRequest) msg.obj; |
| 1431 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1432 | int mode = (int) request.argument; |
| 1433 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1434 | break; |
| 1435 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1436 | ar = (AsyncResult) msg.obj; |
| 1437 | request = (MainThreadRequest) ar.userObj; |
| 1438 | request.result = ar.exception == null; |
| 1439 | notifyRequester(request); |
| 1440 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1441 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1442 | request = (MainThreadRequest) msg.obj; |
| 1443 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1444 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1445 | break; |
| 1446 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1447 | ar = (AsyncResult) msg.obj; |
| 1448 | request = (MainThreadRequest) ar.userObj; |
| 1449 | if (ar.exception != null) { |
| 1450 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1451 | } else { |
| 1452 | request.result = ((int[]) ar.result)[0]; |
| 1453 | } |
| 1454 | notifyRequester(request); |
| 1455 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1456 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1457 | request = (MainThreadRequest) msg.obj; |
| 1458 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1459 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1460 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1461 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1462 | break; |
| 1463 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1464 | ar = (AsyncResult) msg.obj; |
| 1465 | request = (MainThreadRequest) ar.userObj; |
| 1466 | request.result = ar.exception == null; |
| 1467 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1468 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1469 | case CMD_GET_ALL_CELL_INFO: |
| 1470 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1471 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1472 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1473 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1474 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1475 | ar = (AsyncResult) msg.obj; |
| 1476 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1477 | // If a timeout occurs, the response will be null |
| 1478 | request.result = (ar.exception == null && ar.result != null) |
| 1479 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1480 | synchronized (request) { |
| 1481 | request.notifyAll(); |
| 1482 | } |
| 1483 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1484 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1485 | request = (MainThreadRequest) msg.obj; |
| 1486 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1487 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1488 | break; |
| 1489 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1490 | ar = (AsyncResult) msg.obj; |
| 1491 | request = (MainThreadRequest) ar.userObj; |
| 1492 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1493 | try { |
| 1494 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1495 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1496 | cb.onError( |
| 1497 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1498 | ar.exception.getClass().getName(), |
| 1499 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1500 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1501 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1502 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1503 | } else { |
| 1504 | // use the result as returned |
| 1505 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1506 | } |
| 1507 | } catch (RemoteException re) { |
| 1508 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1509 | } |
| 1510 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1511 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1512 | request = (MainThreadRequest) msg.obj; |
| 1513 | WorkSource ws = (WorkSource) request.argument; |
| 1514 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1515 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1516 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1517 | } |
| 1518 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1519 | ar = (AsyncResult) msg.obj; |
| 1520 | request = (MainThreadRequest) ar.userObj; |
| 1521 | if (ar.exception == null) { |
| 1522 | request.result = ar.result; |
| 1523 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1524 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1525 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1526 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1527 | } |
| 1528 | |
| 1529 | synchronized (request) { |
| 1530 | request.notifyAll(); |
| 1531 | } |
| 1532 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1533 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1534 | case CMD_MODEM_REBOOT: |
| 1535 | request = (MainThreadRequest) msg.obj; |
| 1536 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1537 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1538 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1539 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1540 | handleNullReturnEvent(msg, "rebootModem"); |
| 1541 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1542 | case CMD_REQUEST_ENABLE_MODEM: |
| 1543 | request = (MainThreadRequest) msg.obj; |
| 1544 | boolean enable = (boolean) request.argument; |
| 1545 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1546 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1547 | PhoneConfigurationManager.getInstance() |
| 1548 | .enablePhone(request.phone, enable, onCompleted); |
| 1549 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1550 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1551 | ar = (AsyncResult) msg.obj; |
| 1552 | request = (MainThreadRequest) ar.userObj; |
| 1553 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1554 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1555 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1556 | if ((boolean) request.result) { |
| 1557 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1558 | updateModemStateMetrics(); |
| 1559 | } else { |
| 1560 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1561 | + ar.exception); |
| 1562 | } |
| 1563 | notifyRequester(request); |
| 1564 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1565 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1566 | case CMD_GET_MODEM_STATUS: |
| 1567 | request = (MainThreadRequest) msg.obj; |
| 1568 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1569 | PhoneConfigurationManager.getInstance() |
| 1570 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1571 | break; |
| 1572 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1573 | ar = (AsyncResult) msg.obj; |
| 1574 | request = (MainThreadRequest) ar.userObj; |
| 1575 | int id = request.phone.getPhoneId(); |
| 1576 | if (ar.exception == null && ar.result != null) { |
| 1577 | request.result = ar.result; |
| 1578 | //update the cache as modem status has changed |
| 1579 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1580 | (boolean) request.result); |
| 1581 | } else { |
| 1582 | // Return true if modem status cannot be retrieved. For most cases, |
| 1583 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1584 | // and disable modem are not supported. Modem is always on. |
| 1585 | // TODO: this should be fixed in R to support a third |
| 1586 | // status UNKNOWN b/131631629 |
| 1587 | request.result = true; |
| 1588 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1589 | + ar.exception); |
| 1590 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1591 | notifyRequester(request); |
| 1592 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1593 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1594 | request = (MainThreadRequest) msg.obj; |
| 1595 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1596 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1597 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1598 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1599 | break; |
| 1600 | } |
| 1601 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1602 | ar = (AsyncResult) msg.obj; |
| 1603 | request = (MainThreadRequest) ar.userObj; |
| 1604 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1605 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1606 | args.second.accept(ar.exception == null); |
| 1607 | notifyRequester(request); |
| 1608 | break; |
| 1609 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1610 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1611 | request = (MainThreadRequest) msg.obj; |
| 1612 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1613 | Phone phone = getPhoneFromRequest(request); |
| 1614 | if (phone != null) { |
| 1615 | phone.getSystemSelectionChannels(onCompleted); |
| 1616 | } else { |
| 1617 | loge("getSystemSelectionChannels: No phone object"); |
| 1618 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1619 | notifyRequester(request); |
| 1620 | } |
| 1621 | break; |
| 1622 | } |
| 1623 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1624 | ar = (AsyncResult) msg.obj; |
| 1625 | request = (MainThreadRequest) ar.userObj; |
| 1626 | if (ar.exception == null && ar.result != null) { |
| 1627 | request.result = ar.result; |
| 1628 | } else { |
| 1629 | request.result = new IllegalArgumentException( |
| 1630 | "Failed to retrieve system selection channels"); |
| 1631 | if (ar.result == null) { |
| 1632 | loge("getSystemSelectionChannels: Empty response"); |
| 1633 | } else { |
| 1634 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1635 | } |
| 1636 | } |
| 1637 | notifyRequester(request); |
| 1638 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1639 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1640 | ar = (AsyncResult) msg.obj; |
| 1641 | request = (MainThreadRequest) ar.userObj; |
| 1642 | if (ar.exception == null && ar.result != null) { |
| 1643 | request.result = ar.result; |
| 1644 | } else { |
| 1645 | request.result = -1; |
| 1646 | loge("Failed to set Forbidden Plmns"); |
| 1647 | if (ar.result == null) { |
| 1648 | loge("setForbidenPlmns: Empty response"); |
| 1649 | } else if (ar.exception != null) { |
| 1650 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1651 | request.result = -1; |
| 1652 | } else { |
| 1653 | loge("setForbiddenPlmns: Unknown exception"); |
| 1654 | } |
| 1655 | } |
| 1656 | notifyRequester(request); |
| 1657 | break; |
| 1658 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1659 | request = (MainThreadRequest) msg.obj; |
| 1660 | uiccCard = getUiccCardFromRequest(request); |
| 1661 | if (uiccCard == null) { |
| 1662 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1663 | request.result = -1; |
| 1664 | notifyRequester(request); |
| 1665 | break; |
| 1666 | } |
| 1667 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1668 | (Pair<Integer, List<String>>) request.argument; |
| 1669 | appType = setFplmnsArgs.first; |
| 1670 | List<String> fplmns = setFplmnsArgs.second; |
| 1671 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1672 | if (uiccApp == null) { |
| 1673 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1674 | request.result = -1; |
| 1675 | loge("Failed to get UICC App"); |
| 1676 | notifyRequester(request); |
| 1677 | } else { |
| 1678 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1679 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1680 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1681 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1682 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1683 | case CMD_ERASE_MODEM_CONFIG: |
| 1684 | request = (MainThreadRequest) msg.obj; |
| 1685 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1686 | defaultPhone.eraseModemConfig(onCompleted); |
| 1687 | break; |
| 1688 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1689 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1690 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1691 | |
| 1692 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1693 | request = (MainThreadRequest) msg.obj; |
| 1694 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1695 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1696 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1697 | changed.first, changed.second, onCompleted); |
| 1698 | break; |
| 1699 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1700 | ar = (AsyncResult) msg.obj; |
| 1701 | request = (MainThreadRequest) ar.userObj; |
| 1702 | if (ar.exception == null) { |
| 1703 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1704 | // If the operation is successful, update the PIN storage |
| 1705 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1706 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1707 | UiccController.getInstance().getPinStorage() |
| 1708 | .storePin(passwords.second, phoneId); |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1709 | } else { |
| 1710 | request.result = msg.arg1; |
| 1711 | } |
| 1712 | notifyRequester(request); |
| 1713 | break; |
| 1714 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1715 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1716 | request = (MainThreadRequest) msg.obj; |
| 1717 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1718 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1719 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1720 | enabled.first, enabled.second, onCompleted); |
| 1721 | break; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1722 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1723 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1724 | ar = (AsyncResult) msg.obj; |
| 1725 | request = (MainThreadRequest) ar.userObj; |
| 1726 | if (ar.exception == null) { |
| 1727 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1728 | // If the operation is successful, update the PIN storage |
| 1729 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1730 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1731 | if (enabled.first) { |
| 1732 | UiccController.getInstance().getPinStorage() |
| 1733 | .storePin(enabled.second, phoneId); |
| 1734 | } else { |
| 1735 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1736 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1737 | } else { |
| 1738 | request.result = msg.arg1; |
| 1739 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1740 | |
| 1741 | |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1742 | notifyRequester(request); |
| 1743 | break; |
| 1744 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1745 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1746 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1747 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1748 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1749 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1750 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1751 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1752 | |
| 1753 | case CMD_SET_DATA_THROTTLING: { |
| 1754 | request = (MainThreadRequest) msg.obj; |
| 1755 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1756 | DataThrottlingRequest dataThrottlingRequest = |
| 1757 | (DataThrottlingRequest) request.argument; |
| 1758 | Phone phone = getPhoneFromRequest(request); |
| 1759 | if (phone != null) { |
| 1760 | phone.setDataThrottling(onCompleted, |
| 1761 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1762 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1763 | } else { |
| 1764 | loge("setDataThrottling: No phone object"); |
| 1765 | request.result = |
| 1766 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1767 | notifyRequester(request); |
| 1768 | } |
| 1769 | |
| 1770 | break; |
| 1771 | } |
| 1772 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1773 | ar = (AsyncResult) msg.obj; |
| 1774 | request = (MainThreadRequest) ar.userObj; |
| 1775 | |
| 1776 | if (ar.exception == null) { |
| 1777 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1778 | } else if (ar.exception instanceof CommandException) { |
| 1779 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1780 | CommandException.Error error = |
| 1781 | ((CommandException) (ar.exception)).getCommandError(); |
| 1782 | |
| 1783 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1784 | request.result = TelephonyManager |
| 1785 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1786 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1787 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
| 1788 | } else { |
| 1789 | request.result = |
| 1790 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1791 | } |
| 1792 | } else { |
| 1793 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1794 | } |
| 1795 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1796 | notifyRequester(request); |
| 1797 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1798 | |
| 1799 | case CMD_SET_SIM_POWER: { |
| 1800 | request = (MainThreadRequest) msg.obj; |
| 1801 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1802 | request = (MainThreadRequest) msg.obj; |
| 1803 | int stateToSet = |
| 1804 | ((Pair<Integer, IIntegerConsumer>) |
| 1805 | request.argument).first; |
| 1806 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1807 | break; |
| 1808 | } |
| 1809 | case EVENT_SET_SIM_POWER_DONE: { |
| 1810 | ar = (AsyncResult) msg.obj; |
| 1811 | request = (MainThreadRequest) ar.userObj; |
| 1812 | IIntegerConsumer callback = |
| 1813 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 1814 | if (ar.exception != null) { |
| 1815 | loge("setSimPower exception: " + ar.exception); |
| 1816 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1817 | .RESULT_ERROR_UNKNOWN; |
| 1818 | if (ar.exception instanceof CommandException) { |
| 1819 | CommandException.Error error = |
| 1820 | ((CommandException) (ar.exception)).getCommandError(); |
| 1821 | if (error == CommandException.Error.SIM_ERR) { |
| 1822 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 1823 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1824 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 1825 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1826 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 1827 | } else { |
| 1828 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 1829 | } |
| 1830 | } |
| 1831 | try { |
| 1832 | callback.accept(errorCode); |
| 1833 | } catch (RemoteException e) { |
| 1834 | // Ignore if the remote process is no longer available to call back. |
| 1835 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1836 | } |
| 1837 | } else { |
| 1838 | try { |
| 1839 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 1840 | } catch (RemoteException e) { |
| 1841 | // Ignore if the remote process is no longer available to call back. |
| 1842 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1843 | } |
| 1844 | } |
| 1845 | break; |
| 1846 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 1847 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1848 | request = (MainThreadRequest) msg.obj; |
| 1849 | |
| 1850 | final Phone phone = getPhoneFromRequest(request); |
| 1851 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1852 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1853 | notifyRequester(request); |
| 1854 | break; |
| 1855 | } |
| 1856 | |
| 1857 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1858 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1859 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1860 | request); |
| 1861 | phone.getServiceStateTracker().setSignalStrengthUpdateRequest( |
| 1862 | request.subId, pair.first /*callingUid*/, |
| 1863 | pair.second /*request*/, onCompleted); |
| 1864 | break; |
| 1865 | } |
| 1866 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1867 | ar = (AsyncResult) msg.obj; |
| 1868 | request = (MainThreadRequest) ar.userObj; |
| 1869 | // request.result will be the exception of ar if present, true otherwise. |
| 1870 | // Be cautious not to leave result null which will wait() forever |
| 1871 | request.result = ar.exception != null ? ar.exception : true; |
| 1872 | notifyRequester(request); |
| 1873 | break; |
| 1874 | } |
| 1875 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1876 | request = (MainThreadRequest) msg.obj; |
| 1877 | |
| 1878 | Phone phone = getPhoneFromRequest(request); |
| 1879 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1880 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1881 | notifyRequester(request); |
| 1882 | break; |
| 1883 | } |
| 1884 | |
| 1885 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1886 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1887 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1888 | request); |
| 1889 | phone.getServiceStateTracker().clearSignalStrengthUpdateRequest( |
| 1890 | request.subId, pair.first /*callingUid*/, |
| 1891 | pair.second /*request*/, onCompleted); |
| 1892 | break; |
| 1893 | } |
| 1894 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1895 | ar = (AsyncResult) msg.obj; |
| 1896 | request = (MainThreadRequest) ar.userObj; |
| 1897 | request.result = ar.exception != null ? ar.exception : true; |
| 1898 | notifyRequester(request); |
| 1899 | break; |
| 1900 | } |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1901 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1902 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 1903 | request = (MainThreadRequest) msg.obj; |
| 1904 | request.result = |
| 1905 | UiccController.getInstance().getPinStorage().prepareUnattendedReboot(); |
| 1906 | notifyRequester(request); |
| 1907 | break; |
| 1908 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1909 | default: |
| 1910 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1911 | break; |
| 1912 | } |
| 1913 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1914 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1915 | private void notifyRequester(MainThreadRequest request) { |
| 1916 | synchronized (request) { |
| 1917 | request.notifyAll(); |
| 1918 | } |
| 1919 | } |
| 1920 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1921 | private void handleNullReturnEvent(Message msg, String command) { |
| 1922 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1923 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1924 | if (ar.exception == null) { |
| 1925 | request.result = true; |
| 1926 | } else { |
| 1927 | request.result = false; |
| 1928 | if (ar.exception instanceof CommandException) { |
| 1929 | loge(command + ": CommandException: " + ar.exception); |
| 1930 | } else { |
| 1931 | loge(command + ": Unknown exception"); |
| 1932 | } |
| 1933 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1934 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1935 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1936 | } |
| 1937 | |
| 1938 | /** |
| 1939 | * Posts the specified command to be executed on the main thread, |
| 1940 | * waits for the request to complete, and returns the result. |
| 1941 | * @see #sendRequestAsync |
| 1942 | */ |
| 1943 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1944 | return sendRequest( |
| 1945 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | /** |
| 1949 | * Posts the specified command to be executed on the main thread, |
| 1950 | * waits for the request to complete, and returns the result. |
| 1951 | * @see #sendRequestAsync |
| 1952 | */ |
| 1953 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1954 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1955 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1956 | } |
| 1957 | |
| 1958 | /** |
| 1959 | * Posts the specified command to be executed on the main thread, |
| 1960 | * waits for the request to complete, and returns the result. |
| 1961 | * @see #sendRequestAsync |
| 1962 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1963 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1964 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1965 | } |
| 1966 | |
| 1967 | /** |
| 1968 | * Posts the specified command to be executed on the main thread, |
| 1969 | * waits for the request to complete, and returns the result. |
| 1970 | * @see #sendRequestAsync |
| 1971 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1972 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1973 | return sendRequest(command, argument, subId, null, workSource); |
| 1974 | } |
| 1975 | |
| 1976 | /** |
| 1977 | * Posts the specified command to be executed on the main thread, |
| 1978 | * waits for the request to complete, and returns the result. |
| 1979 | * @see #sendRequestAsync |
| 1980 | */ |
| 1981 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1982 | return sendRequest( |
| 1983 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1984 | } |
| 1985 | |
| 1986 | /** |
| 1987 | * Posts the specified command to be executed on the main thread, |
| 1988 | * waits for the request to complete, and returns the result. |
| 1989 | * @see #sendRequestAsync |
| 1990 | */ |
| 1991 | private Object sendRequest( |
| 1992 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1993 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1994 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1995 | } |
| 1996 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1997 | MainThreadRequest request = null; |
| 1998 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1999 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 2000 | } else if (phone != null) { |
| 2001 | request = new MainThreadRequest(argument, phone, workSource); |
| 2002 | } else { |
| 2003 | request = new MainThreadRequest(argument, subId, workSource); |
| 2004 | } |
| 2005 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2006 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2007 | msg.sendToTarget(); |
| 2008 | |
| 2009 | // Wait for the request to complete |
| 2010 | synchronized (request) { |
| 2011 | while (request.result == null) { |
| 2012 | try { |
| 2013 | request.wait(); |
| 2014 | } catch (InterruptedException e) { |
| 2015 | // Do nothing, go back and wait until the request is complete |
| 2016 | } |
| 2017 | } |
| 2018 | } |
| 2019 | return request.result; |
| 2020 | } |
| 2021 | |
| 2022 | /** |
| 2023 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2024 | * Posts the specified command to be executed on the main thread, and |
| 2025 | * returns immediately. |
| 2026 | * @see #sendRequest |
| 2027 | */ |
| 2028 | private void sendRequestAsync(int command) { |
| 2029 | mMainThreadHandler.sendEmptyMessage(command); |
| 2030 | } |
| 2031 | |
| 2032 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2033 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2034 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2035 | */ |
| 2036 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2037 | sendRequestAsync(command, argument, null, null); |
| 2038 | } |
| 2039 | |
| 2040 | /** |
| 2041 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2042 | * @see {@link #sendRequest(int,Object)} |
| 2043 | */ |
| 2044 | private void sendRequestAsync( |
| 2045 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2046 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2047 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2048 | msg.sendToTarget(); |
| 2049 | } |
| 2050 | |
| 2051 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2052 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2053 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2054 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2055 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2056 | synchronized (PhoneInterfaceManager.class) { |
| 2057 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2058 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2059 | } else { |
| 2060 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2061 | } |
| 2062 | return sInstance; |
| 2063 | } |
| 2064 | } |
| 2065 | |
| 2066 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2067 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2068 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2069 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 2070 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2071 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2072 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2073 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2074 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2075 | mTelephonySharedPreferences = |
| 2076 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2077 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2078 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2079 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2080 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2081 | publish(); |
| 2082 | } |
| 2083 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2084 | private Phone getDefaultPhone() { |
| 2085 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2086 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2087 | } |
| 2088 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2089 | private void publish() { |
| 2090 | if (DBG) log("publish: " + this); |
| 2091 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2092 | TelephonyFrameworkInitializer |
| 2093 | .getTelephonyServiceManager() |
| 2094 | .getTelephonyServiceRegisterer() |
| 2095 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2096 | } |
| 2097 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2098 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2099 | if (request.phone != null) { |
| 2100 | return request.phone; |
| 2101 | } else { |
| 2102 | return getPhoneFromSubId(request.subId); |
| 2103 | } |
| 2104 | } |
| 2105 | |
| 2106 | private Phone getPhoneFromSubId(int subId) { |
| 2107 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2108 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2109 | } |
| 2110 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2111 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 2112 | Phone phone = getPhoneFromRequest(request); |
| 2113 | return phone == null ? null : |
| 2114 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 2115 | } |
| 2116 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2117 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2118 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2119 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2120 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2121 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2122 | private void sendEraseModemConfig(Phone phone) { |
| 2123 | if (phone != null) { |
| 2124 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2125 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 2126 | final long identity = Binder.clearCallingIdentity(); |
| 2127 | try { |
| 2128 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2129 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2130 | } finally { |
| 2131 | Binder.restoreCallingIdentity(identity); |
| 2132 | } |
| 2133 | } |
| 2134 | } |
| 2135 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2136 | private boolean isImsAvailableOnDevice() { |
| 2137 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2138 | if (pm == null) { |
| 2139 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2140 | // so do not throw error and allow. |
| 2141 | return true; |
| 2142 | } |
| 2143 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2144 | } |
| 2145 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2146 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2147 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2148 | } |
| 2149 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2150 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2151 | if (DBG) log("dial: " + number); |
| 2152 | // No permission check needed here: This is just a wrapper around the |
| 2153 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2154 | // the UI before it does anything. |
| 2155 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2156 | final long identity = Binder.clearCallingIdentity(); |
| 2157 | try { |
| 2158 | String url = createTelUrl(number); |
| 2159 | if (url == null) { |
| 2160 | return; |
| 2161 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2162 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2163 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2164 | PhoneConstants.State state = mCM.getState(subId); |
| 2165 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2166 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2167 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2168 | mApp.startActivity(intent); |
| 2169 | } |
| 2170 | } finally { |
| 2171 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2172 | } |
| 2173 | } |
| 2174 | |
| 2175 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2176 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2177 | } |
| 2178 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2179 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2180 | if (DBG) log("call: " + number); |
| 2181 | |
| 2182 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2183 | // need to do a permission check since we're calling startActivity() |
| 2184 | // from the context of the phone app. |
| 2185 | enforceCallPermission(); |
| 2186 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2187 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2188 | != AppOpsManager.MODE_ALLOWED) { |
| 2189 | return; |
| 2190 | } |
| 2191 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2192 | final long identity = Binder.clearCallingIdentity(); |
| 2193 | try { |
| 2194 | String url = createTelUrl(number); |
| 2195 | if (url == null) { |
| 2196 | return; |
| 2197 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2198 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2199 | boolean isValid = false; |
| 2200 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2201 | if (slist != null) { |
| 2202 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2203 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2204 | isValid = true; |
| 2205 | break; |
| 2206 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2207 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2208 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2209 | if (!isValid) { |
| 2210 | return; |
| 2211 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2212 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2213 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2214 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2215 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2216 | mApp.startActivity(intent); |
| 2217 | } finally { |
| 2218 | Binder.restoreCallingIdentity(identity); |
| 2219 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2220 | } |
| 2221 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2222 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2223 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2224 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2225 | } |
| 2226 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2227 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2228 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2229 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2230 | } |
| 2231 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2232 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2233 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2234 | |
| 2235 | final long identity = Binder.clearCallingIdentity(); |
| 2236 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2237 | Phone phone = getPhone(subId); |
| 2238 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2239 | checkSimPin.start(); |
| 2240 | return checkSimPin.unlockSim(null, pin); |
| 2241 | } finally { |
| 2242 | Binder.restoreCallingIdentity(identity); |
| 2243 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2244 | } |
| 2245 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2246 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2247 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2248 | |
| 2249 | final long identity = Binder.clearCallingIdentity(); |
| 2250 | try { |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2251 | Phone phone = getPhone(subId); |
| 2252 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2253 | checkSimPuk.start(); |
| 2254 | return checkSimPuk.unlockSim(puk, pin); |
| 2255 | } finally { |
| 2256 | Binder.restoreCallingIdentity(identity); |
| 2257 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2258 | } |
| 2259 | |
| 2260 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2261 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2262 | * a synchronous one. |
| 2263 | */ |
| 2264 | private static class UnlockSim extends Thread { |
| 2265 | |
| 2266 | private final IccCard mSimCard; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2267 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2268 | |
| 2269 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2270 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2271 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2272 | |
| 2273 | // For replies from SimCard interface |
| 2274 | private Handler mHandler; |
| 2275 | |
| 2276 | // For async handler to identify request type |
| 2277 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2278 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2279 | UnlockSim(int phoneId, IccCard simCard) { |
| 2280 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2281 | mSimCard = simCard; |
| 2282 | } |
| 2283 | |
| 2284 | @Override |
| 2285 | public void run() { |
| 2286 | Looper.prepare(); |
| 2287 | synchronized (UnlockSim.this) { |
| 2288 | mHandler = new Handler() { |
| 2289 | @Override |
| 2290 | public void handleMessage(Message msg) { |
| 2291 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2292 | switch (msg.what) { |
| 2293 | case SUPPLY_PIN_COMPLETE: |
| 2294 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2295 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2296 | mRetryCount = msg.arg1; |
| 2297 | if (ar.exception != null) { |
| 2298 | if (ar.exception instanceof CommandException && |
| 2299 | ((CommandException)(ar.exception)).getCommandError() |
| 2300 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2301 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2302 | } //When UiccCardApp dispose,handle message and return exception |
| 2303 | else if (ar.exception instanceof CommandException && |
| 2304 | ((CommandException) (ar.exception)).getCommandError() |
| 2305 | == CommandException.Error.ABORTED) { |
| 2306 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2307 | } else { |
| 2308 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2309 | } |
| 2310 | } else { |
| 2311 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2312 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2313 | mDone = true; |
| 2314 | UnlockSim.this.notifyAll(); |
| 2315 | } |
| 2316 | break; |
| 2317 | } |
| 2318 | } |
| 2319 | }; |
| 2320 | UnlockSim.this.notifyAll(); |
| 2321 | } |
| 2322 | Looper.loop(); |
| 2323 | } |
| 2324 | |
| 2325 | /* |
| 2326 | * Use PIN or PUK to unlock SIM card |
| 2327 | * |
| 2328 | * If PUK is null, unlock SIM card with PIN |
| 2329 | * |
| 2330 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2331 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2332 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2333 | |
| 2334 | while (mHandler == null) { |
| 2335 | try { |
| 2336 | wait(); |
| 2337 | } catch (InterruptedException e) { |
| 2338 | Thread.currentThread().interrupt(); |
| 2339 | } |
| 2340 | } |
| 2341 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2342 | |
| 2343 | if (puk == null) { |
| 2344 | mSimCard.supplyPin(pin, callback); |
| 2345 | } else { |
| 2346 | mSimCard.supplyPuk(puk, pin, callback); |
| 2347 | } |
| 2348 | |
| 2349 | while (!mDone) { |
| 2350 | try { |
| 2351 | Log.d(LOG_TAG, "wait for done"); |
| 2352 | wait(); |
| 2353 | } catch (InterruptedException e) { |
| 2354 | // Restore the interrupted status |
| 2355 | Thread.currentThread().interrupt(); |
| 2356 | } |
| 2357 | } |
| 2358 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2359 | int[] resultArray = new int[2]; |
| 2360 | resultArray[0] = mResult; |
| 2361 | resultArray[1] = mRetryCount; |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2362 | |
| 2363 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
| 2364 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
| 2365 | } |
| 2366 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2367 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2368 | } |
| 2369 | } |
| 2370 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2371 | /** |
| 2372 | * This method has been removed due to privacy and stability concerns. |
| 2373 | */ |
| 2374 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2375 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2376 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2377 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2378 | } |
| 2379 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2380 | @Override |
| 2381 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2382 | mApp.getSystemService(AppOpsManager.class) |
| 2383 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2384 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2385 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2386 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2387 | // Callers targeting S have no business invoking this method. |
| 2388 | return; |
| 2389 | } |
| 2390 | |
| 2391 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2392 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2393 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2394 | .setCallingPackage(callingPackage) |
| 2395 | .setCallingFeatureId(null) |
| 2396 | .setCallingPid(Binder.getCallingPid()) |
| 2397 | .setCallingUid(Binder.getCallingUid()) |
| 2398 | .setMethod("updateServiceLocation") |
| 2399 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2400 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2401 | .build()); |
| 2402 | // Apps that lack location permission have no business calling this method; |
| 2403 | // however, because no permission was declared in the public API, denials must |
| 2404 | // all be "soft". |
| 2405 | switch (locationResult) { |
| 2406 | case DENIED_HARD: /* fall through */ |
| 2407 | case DENIED_SOFT: |
| 2408 | return; |
| 2409 | } |
| 2410 | |
| 2411 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2412 | final long identity = Binder.clearCallingIdentity(); |
| 2413 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2414 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2415 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2416 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2417 | } |
| 2418 | } finally { |
| 2419 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2420 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2421 | } |
| 2422 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2423 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2424 | @Override |
| 2425 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2426 | return isRadioOnWithFeature(callingPackage, null); |
| 2427 | } |
| 2428 | |
| 2429 | |
| 2430 | @Override |
| 2431 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2432 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2433 | callingFeatureId); |
| 2434 | } |
| 2435 | |
| 2436 | @Deprecated |
| 2437 | @Override |
| 2438 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2439 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2440 | } |
| 2441 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2442 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2443 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2444 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2445 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2446 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2447 | return false; |
| 2448 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2449 | |
| 2450 | final long identity = Binder.clearCallingIdentity(); |
| 2451 | try { |
| 2452 | return isRadioOnForSubscriber(subId); |
| 2453 | } finally { |
| 2454 | Binder.restoreCallingIdentity(identity); |
| 2455 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2456 | } |
| 2457 | |
| 2458 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2459 | final long identity = Binder.clearCallingIdentity(); |
| 2460 | try { |
| 2461 | final Phone phone = getPhone(subId); |
| 2462 | if (phone != null) { |
| 2463 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2464 | } else { |
| 2465 | return false; |
| 2466 | } |
| 2467 | } finally { |
| 2468 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2469 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2470 | } |
| 2471 | |
| 2472 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2473 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2474 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2475 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2476 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2477 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2478 | |
| 2479 | final long identity = Binder.clearCallingIdentity(); |
| 2480 | try { |
| 2481 | final Phone phone = getPhone(subId); |
| 2482 | if (phone != null) { |
| 2483 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2484 | } |
| 2485 | } finally { |
| 2486 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2487 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2488 | } |
| 2489 | |
| 2490 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2491 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2492 | } |
| 2493 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2494 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2495 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2496 | |
| 2497 | final long identity = Binder.clearCallingIdentity(); |
| 2498 | try { |
| 2499 | final Phone phone = getPhone(subId); |
| 2500 | if (phone == null) { |
| 2501 | return false; |
| 2502 | } |
| 2503 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2504 | toggleRadioOnOffForSubscriber(subId); |
| 2505 | } |
| 2506 | return true; |
| 2507 | } finally { |
| 2508 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2509 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2510 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2511 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2512 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2513 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2514 | /* |
| 2515 | * If any of the Radios are available, it will need to be |
| 2516 | * shutdown. So return true if any Radio is available. |
| 2517 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2518 | final long identity = Binder.clearCallingIdentity(); |
| 2519 | try { |
| 2520 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2521 | Phone phone = PhoneFactory.getPhone(i); |
| 2522 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2523 | } |
| 2524 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2525 | return false; |
| 2526 | } finally { |
| 2527 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2528 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2529 | } |
| 2530 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2531 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2532 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2533 | enforceModifyPermission(); |
| 2534 | |
| 2535 | final long identity = Binder.clearCallingIdentity(); |
| 2536 | try { |
| 2537 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2538 | logv("Shutting down Phone " + i); |
| 2539 | shutdownRadioUsingPhoneId(i); |
| 2540 | } |
| 2541 | } finally { |
| 2542 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2543 | } |
| 2544 | } |
| 2545 | |
| 2546 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2547 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2548 | if (phone != null && phone.isRadioAvailable()) { |
| 2549 | phone.shutdownRadio(); |
| 2550 | } |
| 2551 | } |
| 2552 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2553 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2554 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2555 | |
| 2556 | final long identity = Binder.clearCallingIdentity(); |
| 2557 | try { |
| 2558 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2559 | if (defaultPhone != null) { |
| 2560 | defaultPhone.setRadioPower(turnOn); |
| 2561 | return true; |
| 2562 | } else { |
| 2563 | loge("There's no default phone."); |
| 2564 | return false; |
| 2565 | } |
| 2566 | } finally { |
| 2567 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2568 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2569 | } |
| 2570 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2571 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2572 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2573 | |
| 2574 | final long identity = Binder.clearCallingIdentity(); |
| 2575 | try { |
| 2576 | final Phone phone = getPhone(subId); |
| 2577 | if (phone != null) { |
| 2578 | phone.setRadioPower(turnOn); |
| 2579 | return true; |
| 2580 | } else { |
| 2581 | return false; |
| 2582 | } |
| 2583 | } finally { |
| 2584 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2585 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2586 | } |
| 2587 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2588 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2589 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2590 | public boolean enableDataConnectivity() { |
| 2591 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2592 | |
| 2593 | final long identity = Binder.clearCallingIdentity(); |
| 2594 | try { |
| 2595 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2596 | final Phone phone = getPhone(subId); |
| 2597 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2598 | phone.getDataEnabledSettings().setDataEnabled( |
| 2599 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2600 | return true; |
| 2601 | } else { |
| 2602 | return false; |
| 2603 | } |
| 2604 | } finally { |
| 2605 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2606 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2607 | } |
| 2608 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2609 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2610 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2611 | public boolean disableDataConnectivity() { |
| 2612 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2613 | |
| 2614 | final long identity = Binder.clearCallingIdentity(); |
| 2615 | try { |
| 2616 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2617 | final Phone phone = getPhone(subId); |
| 2618 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2619 | phone.getDataEnabledSettings().setDataEnabled( |
| 2620 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2621 | return true; |
| 2622 | } else { |
| 2623 | return false; |
| 2624 | } |
| 2625 | } finally { |
| 2626 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2627 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2628 | } |
| 2629 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2630 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2631 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2632 | final long identity = Binder.clearCallingIdentity(); |
| 2633 | try { |
| 2634 | final Phone phone = getPhone(subId); |
| 2635 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2636 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2637 | } else { |
| 2638 | return false; |
| 2639 | } |
| 2640 | } finally { |
| 2641 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2642 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2643 | } |
| 2644 | |
| 2645 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2646 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2647 | } |
| 2648 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2649 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2650 | enforceCallPermission(); |
| 2651 | |
| 2652 | final long identity = Binder.clearCallingIdentity(); |
| 2653 | try { |
| 2654 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2655 | return; |
| 2656 | } |
| 2657 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2658 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2659 | } finally { |
| 2660 | Binder.restoreCallingIdentity(identity); |
| 2661 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2662 | }; |
| 2663 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2664 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2665 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2666 | |
| 2667 | final long identity = Binder.clearCallingIdentity(); |
| 2668 | try { |
| 2669 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2670 | return false; |
| 2671 | } |
| 2672 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2673 | } finally { |
| 2674 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2675 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2676 | } |
| 2677 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2678 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2679 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2680 | } |
| 2681 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2682 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2683 | final long identity = Binder.clearCallingIdentity(); |
| 2684 | try { |
| 2685 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2686 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2687 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2688 | } finally { |
| 2689 | Binder.restoreCallingIdentity(identity); |
| 2690 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2691 | } |
| 2692 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2693 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2694 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2695 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2696 | } |
| 2697 | |
| 2698 | @Override |
| 2699 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2700 | final long identity = Binder.clearCallingIdentity(); |
| 2701 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2702 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2703 | if (phone != null) { |
| 2704 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2705 | } else { |
| 2706 | return PhoneConstantConversions.convertDataState( |
| 2707 | PhoneConstants.DataState.DISCONNECTED); |
| 2708 | } |
| 2709 | } finally { |
| 2710 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2711 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2712 | } |
| 2713 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2714 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2715 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2716 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2717 | } |
| 2718 | |
| 2719 | @Override |
| 2720 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2721 | final long identity = Binder.clearCallingIdentity(); |
| 2722 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2723 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2724 | if (phone != null) { |
| 2725 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2726 | } else { |
| 2727 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2728 | } |
| 2729 | } finally { |
| 2730 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2731 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2732 | } |
| 2733 | |
| 2734 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2735 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2736 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2737 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2738 | |
| 2739 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2740 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2741 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2742 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2743 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2744 | .setCallingPid(Binder.getCallingPid()) |
| 2745 | .setCallingUid(Binder.getCallingUid()) |
| 2746 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2747 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2748 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2749 | .build()); |
| 2750 | switch (locationResult) { |
| 2751 | case DENIED_HARD: |
| 2752 | throw new SecurityException("Not allowed to access cell location"); |
| 2753 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2754 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2755 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2756 | } |
| 2757 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2758 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2759 | final long identity = Binder.clearCallingIdentity(); |
| 2760 | try { |
| 2761 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2762 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2763 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2764 | } finally { |
| 2765 | Binder.restoreCallingIdentity(identity); |
| 2766 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2767 | } |
| 2768 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2769 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2770 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2771 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2772 | // registered cell info, so return a NULL country instead. |
| 2773 | final long identity = Binder.clearCallingIdentity(); |
| 2774 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2775 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2776 | // Get default phone in this case. |
| 2777 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2778 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2779 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2780 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2781 | if (phone == null) return ""; |
| 2782 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2783 | if (sst == null) return ""; |
| 2784 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2785 | if (lt == null) return ""; |
| 2786 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry(); |
| 2787 | EmergencyNumberTracker ent = phone.getEmergencyNumberTracker(); |
| 2788 | return (ent == null) ? "" : ent.getEmergencyCountryIso(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2789 | } finally { |
| 2790 | Binder.restoreCallingIdentity(identity); |
| 2791 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2792 | } |
| 2793 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2794 | /** |
| 2795 | * This method was removed due to potential issues caused by performing partial |
| 2796 | * updates of service state, and lack of a credible use case. |
| 2797 | * |
| 2798 | * This has the ability to break the telephony implementation by disabling notification of |
| 2799 | * changes in device connectivity. DO NOT USE THIS! |
| 2800 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2801 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2802 | public void enableLocationUpdates() { |
| 2803 | mApp.enforceCallingOrSelfPermission( |
| 2804 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2805 | } |
| 2806 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2807 | /** |
| 2808 | * This method was removed due to potential issues caused by performing partial |
| 2809 | * updates of service state, and lack of a credible use case. |
| 2810 | * |
| 2811 | * This has the ability to break the telephony implementation by disabling notification of |
| 2812 | * changes in device connectivity. DO NOT USE THIS! |
| 2813 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2814 | @Override |
| 2815 | public void disableLocationUpdates() { |
| 2816 | mApp.enforceCallingOrSelfPermission( |
| 2817 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2818 | } |
| 2819 | |
| 2820 | @Override |
| 2821 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2822 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2823 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2824 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2825 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2826 | throw new SecurityException( |
| 2827 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2828 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2829 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2830 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2831 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2832 | return null; |
| 2833 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2834 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2835 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2836 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2837 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2838 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2839 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2840 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2841 | for (CellInfo ci : info) { |
| 2842 | if (ci instanceof CellInfoGsm) { |
| 2843 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2844 | } else if (ci instanceof CellInfoWcdma) { |
| 2845 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2846 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2847 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2848 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2849 | } |
| 2850 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2851 | private List<CellInfo> getCachedCellInfo() { |
| 2852 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2853 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2854 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2855 | if (info != null) cellInfos.addAll(info); |
| 2856 | } |
| 2857 | return cellInfos; |
| 2858 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2859 | |
| 2860 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2861 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2862 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2863 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2864 | |
| 2865 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2866 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2867 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2868 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2869 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2870 | .setCallingPid(Binder.getCallingPid()) |
| 2871 | .setCallingUid(Binder.getCallingUid()) |
| 2872 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2873 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2874 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2875 | .build()); |
| 2876 | switch (locationResult) { |
| 2877 | case DENIED_HARD: |
| 2878 | throw new SecurityException("Not allowed to access cell info"); |
| 2879 | case DENIED_SOFT: |
| 2880 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2881 | } |
| 2882 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2883 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2884 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2885 | return getCachedCellInfo(); |
| 2886 | } |
| 2887 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2888 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2889 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2890 | final long identity = Binder.clearCallingIdentity(); |
| 2891 | try { |
| 2892 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2893 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2894 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2895 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2896 | if (info != null) cellInfos.addAll(info); |
| 2897 | } |
| 2898 | return cellInfos; |
| 2899 | } finally { |
| 2900 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2901 | } |
| 2902 | } |
| 2903 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2904 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2905 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2906 | String callingFeatureId) { |
| 2907 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2908 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2909 | } |
| 2910 | |
| 2911 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2912 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2913 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2914 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2915 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2916 | } |
| 2917 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2918 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2919 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2920 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2921 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2922 | |
| 2923 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2924 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2925 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2926 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2927 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2928 | .setCallingPid(Binder.getCallingPid()) |
| 2929 | .setCallingUid(Binder.getCallingUid()) |
| 2930 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2931 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2932 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2933 | .build()); |
| 2934 | switch (locationResult) { |
| 2935 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2936 | if (TelephonyPermissions |
| 2937 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2938 | // Safetynet logging for b/154934934 |
| 2939 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2940 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2941 | throw new SecurityException("Not allowed to access cell info"); |
| 2942 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2943 | if (TelephonyPermissions |
| 2944 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2945 | // Safetynet logging for b/154934934 |
| 2946 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2947 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2948 | try { |
| 2949 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2950 | } catch (RemoteException re) { |
| 2951 | // Drop without consequences |
| 2952 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2953 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2954 | } |
| 2955 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2956 | |
| 2957 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2958 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2959 | |
| 2960 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2961 | } |
| 2962 | |
| 2963 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2964 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2965 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2966 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2967 | |
| 2968 | final long identity = Binder.clearCallingIdentity(); |
| 2969 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2970 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2971 | } finally { |
| 2972 | Binder.restoreCallingIdentity(identity); |
| 2973 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2974 | } |
| 2975 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2976 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2977 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2978 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2979 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2980 | return null; |
| 2981 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2982 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2983 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2984 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2985 | return null; |
| 2986 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2987 | |
| 2988 | final long identity = Binder.clearCallingIdentity(); |
| 2989 | try { |
| 2990 | return phone.getImei(); |
| 2991 | } finally { |
| 2992 | Binder.restoreCallingIdentity(identity); |
| 2993 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2994 | } |
| 2995 | |
| 2996 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2997 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2998 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2999 | String tac = null; |
| 3000 | if (phone != null) { |
| 3001 | String imei = phone.getImei(); |
| 3002 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3003 | } |
| 3004 | return tac; |
| 3005 | } |
| 3006 | |
| 3007 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3008 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3009 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3010 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3011 | return null; |
| 3012 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3013 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3014 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3015 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3016 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3017 | return null; |
| 3018 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3019 | |
| 3020 | final long identity = Binder.clearCallingIdentity(); |
| 3021 | try { |
| 3022 | return phone.getMeid(); |
| 3023 | } finally { |
| 3024 | Binder.restoreCallingIdentity(identity); |
| 3025 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3026 | } |
| 3027 | |
| 3028 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3029 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3030 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3031 | String manufacturerCode = null; |
| 3032 | if (phone != null) { |
| 3033 | String meid = phone.getMeid(); |
| 3034 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3035 | } |
| 3036 | return manufacturerCode; |
| 3037 | } |
| 3038 | |
| 3039 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3040 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3041 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3042 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3043 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3044 | return null; |
| 3045 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3046 | int subId = phone.getSubId(); |
| 3047 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3048 | mApp, subId, callingPackage, callingFeatureId, |
| 3049 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3050 | return null; |
| 3051 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3052 | |
| 3053 | final long identity = Binder.clearCallingIdentity(); |
| 3054 | try { |
| 3055 | return phone.getDeviceSvn(); |
| 3056 | } finally { |
| 3057 | Binder.restoreCallingIdentity(identity); |
| 3058 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3059 | } |
| 3060 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3061 | @Override |
| 3062 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3063 | final long identity = Binder.clearCallingIdentity(); |
| 3064 | try { |
| 3065 | final Phone phone = getPhone(subId); |
| 3066 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3067 | } finally { |
| 3068 | Binder.restoreCallingIdentity(identity); |
| 3069 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3070 | } |
| 3071 | |
| 3072 | @Override |
| 3073 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3074 | final long identity = Binder.clearCallingIdentity(); |
| 3075 | try { |
| 3076 | final Phone phone = getPhone(subId); |
| 3077 | return phone == null ? null : phone.getCarrierName(); |
| 3078 | } finally { |
| 3079 | Binder.restoreCallingIdentity(identity); |
| 3080 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3081 | } |
| 3082 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3083 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3084 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3085 | final long identity = Binder.clearCallingIdentity(); |
| 3086 | try { |
| 3087 | final Phone phone = getPhone(subId); |
| 3088 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3089 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3090 | } finally { |
| 3091 | Binder.restoreCallingIdentity(identity); |
| 3092 | } |
| 3093 | } |
| 3094 | |
| 3095 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3096 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3097 | final long identity = Binder.clearCallingIdentity(); |
| 3098 | try { |
| 3099 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3100 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3101 | } finally { |
| 3102 | Binder.restoreCallingIdentity(identity); |
| 3103 | } |
| 3104 | } |
| 3105 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3106 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3107 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3108 | if (!isSubscriptionMccMnc) { |
| 3109 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3110 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3111 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3112 | if (phone == null) { |
| 3113 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3114 | } |
| 3115 | final long identity = Binder.clearCallingIdentity(); |
| 3116 | try { |
| 3117 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3118 | } finally { |
| 3119 | Binder.restoreCallingIdentity(identity); |
| 3120 | } |
| 3121 | } |
| 3122 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3123 | // |
| 3124 | // Internal helper methods. |
| 3125 | // |
| 3126 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3127 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3128 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3129 | * |
| 3130 | * @throws SecurityException if the caller does not have the required permission |
| 3131 | */ |
| 3132 | private void enforceModifyPermission() { |
| 3133 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3134 | } |
| 3135 | |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3136 | /** |
| 3137 | * Make sure the caller is system. |
| 3138 | * |
| 3139 | * @throws SecurityException if the caller is not system. |
| 3140 | */ |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 3141 | private static void enforceSystemCaller() { |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3142 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 3143 | throw new SecurityException("Caller must be system"); |
| 3144 | } |
| 3145 | } |
| 3146 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3147 | private void enforceActiveEmergencySessionPermission() { |
| 3148 | mApp.enforceCallingOrSelfPermission( |
| 3149 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3150 | } |
| 3151 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3152 | /** |
| 3153 | * Make sure the caller has the CALL_PHONE permission. |
| 3154 | * |
| 3155 | * @throws SecurityException if the caller does not have the required permission |
| 3156 | */ |
| 3157 | private void enforceCallPermission() { |
| 3158 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3159 | } |
| 3160 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3161 | private void enforceSettingsPermission() { |
| 3162 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3163 | } |
| 3164 | |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3165 | private void enforceRebootPermission() { |
| 3166 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3167 | } |
| 3168 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3169 | private String createTelUrl(String number) { |
| 3170 | if (TextUtils.isEmpty(number)) { |
| 3171 | return null; |
| 3172 | } |
| 3173 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3174 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3175 | } |
| 3176 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3177 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3178 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3179 | } |
| 3180 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3181 | private static void logv(String msg) { |
| 3182 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3183 | } |
| 3184 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3185 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3186 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3187 | } |
| 3188 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3189 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3190 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3191 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3192 | } |
| 3193 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3194 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3195 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3196 | final long identity = Binder.clearCallingIdentity(); |
| 3197 | try { |
| 3198 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3199 | if (phone == null) { |
| 3200 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3201 | } else { |
| 3202 | return phone.getPhoneType(); |
| 3203 | } |
| 3204 | } finally { |
| 3205 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3206 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3207 | } |
| 3208 | |
| 3209 | /** |
| 3210 | * Returns the CDMA ERI icon index to display |
| 3211 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3212 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3213 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3214 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3215 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3216 | } |
| 3217 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3218 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3219 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3220 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3221 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3222 | mApp, subId, callingPackage, callingFeatureId, |
| 3223 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3224 | return -1; |
| 3225 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3226 | |
| 3227 | final long identity = Binder.clearCallingIdentity(); |
| 3228 | try { |
| 3229 | final Phone phone = getPhone(subId); |
| 3230 | if (phone != null) { |
| 3231 | return phone.getCdmaEriIconIndex(); |
| 3232 | } else { |
| 3233 | return -1; |
| 3234 | } |
| 3235 | } finally { |
| 3236 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3237 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3238 | } |
| 3239 | |
| 3240 | /** |
| 3241 | * Returns the CDMA ERI icon mode, |
| 3242 | * 0 - ON |
| 3243 | * 1 - FLASHING |
| 3244 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3245 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3246 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3247 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3248 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3249 | } |
| 3250 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3251 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3252 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3253 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3254 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3255 | mApp, subId, callingPackage, callingFeatureId, |
| 3256 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3257 | return -1; |
| 3258 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3259 | |
| 3260 | final long identity = Binder.clearCallingIdentity(); |
| 3261 | try { |
| 3262 | final Phone phone = getPhone(subId); |
| 3263 | if (phone != null) { |
| 3264 | return phone.getCdmaEriIconMode(); |
| 3265 | } else { |
| 3266 | return -1; |
| 3267 | } |
| 3268 | } finally { |
| 3269 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3270 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3271 | } |
| 3272 | |
| 3273 | /** |
| 3274 | * Returns the CDMA ERI text, |
| 3275 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3276 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3277 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3278 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3279 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3280 | } |
| 3281 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3282 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3283 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3284 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3285 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3286 | mApp, subId, callingPackage, callingFeatureId, |
| 3287 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3288 | return null; |
| 3289 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3290 | |
| 3291 | final long identity = Binder.clearCallingIdentity(); |
| 3292 | try { |
| 3293 | final Phone phone = getPhone(subId); |
| 3294 | if (phone != null) { |
| 3295 | return phone.getCdmaEriText(); |
| 3296 | } else { |
| 3297 | return null; |
| 3298 | } |
| 3299 | } finally { |
| 3300 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3301 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3302 | } |
| 3303 | |
| 3304 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3305 | * Returns the CDMA MDN. |
| 3306 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3307 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3308 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3309 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3310 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3311 | |
| 3312 | final long identity = Binder.clearCallingIdentity(); |
| 3313 | try { |
| 3314 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3315 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3316 | return phone.getLine1Number(); |
| 3317 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3318 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3319 | return null; |
| 3320 | } |
| 3321 | } finally { |
| 3322 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3323 | } |
| 3324 | } |
| 3325 | |
| 3326 | /** |
| 3327 | * Returns the CDMA MIN. |
| 3328 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3329 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3330 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3331 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3332 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3333 | |
| 3334 | final long identity = Binder.clearCallingIdentity(); |
| 3335 | try { |
| 3336 | final Phone phone = getPhone(subId); |
| 3337 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3338 | return phone.getCdmaMin(); |
| 3339 | } else { |
| 3340 | return null; |
| 3341 | } |
| 3342 | } finally { |
| 3343 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3344 | } |
| 3345 | } |
| 3346 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3347 | @Override |
| 3348 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3349 | INumberVerificationCallback callback, String callingPackage) { |
| 3350 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3351 | != PERMISSION_GRANTED) { |
| 3352 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3353 | } |
| 3354 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3355 | |
| 3356 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3357 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3358 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3359 | + "calling package: " + callingPackage |
| 3360 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3361 | } |
| 3362 | |
| 3363 | if (range == null) { |
| 3364 | throw new NullPointerException("Range must be non-null"); |
| 3365 | } |
| 3366 | |
| 3367 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3368 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3369 | |
| 3370 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3371 | } |
| 3372 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3373 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3374 | * Returns true if CDMA provisioning needs to run. |
| 3375 | */ |
| 3376 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3377 | final long identity = Binder.clearCallingIdentity(); |
| 3378 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3379 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3380 | } finally { |
| 3381 | Binder.restoreCallingIdentity(identity); |
| 3382 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3383 | } |
| 3384 | |
| 3385 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3386 | * Sets the voice mail number of a given subId. |
| 3387 | */ |
| 3388 | @Override |
| 3389 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3390 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3391 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3392 | |
| 3393 | final long identity = Binder.clearCallingIdentity(); |
| 3394 | try { |
| 3395 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3396 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3397 | return success; |
| 3398 | } finally { |
| 3399 | Binder.restoreCallingIdentity(identity); |
| 3400 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3401 | } |
| 3402 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3403 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3404 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3405 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3406 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3407 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3408 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3409 | throw new SecurityException("caller must be system dialer"); |
| 3410 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3411 | |
| 3412 | final long identity = Binder.clearCallingIdentity(); |
| 3413 | try { |
| 3414 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3415 | if (phoneAccountHandle == null) { |
| 3416 | return null; |
| 3417 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3418 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3419 | } finally { |
| 3420 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3421 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3422 | } |
| 3423 | |
| 3424 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3425 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3426 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3427 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3428 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3429 | mApp, subId, callingPackage, callingFeatureId, |
| 3430 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3431 | return null; |
| 3432 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3433 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3434 | final long identity = Binder.clearCallingIdentity(); |
| 3435 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3436 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3437 | } finally { |
| 3438 | Binder.restoreCallingIdentity(identity); |
| 3439 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3440 | } |
| 3441 | |
| 3442 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3443 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3444 | VisualVoicemailSmsFilterSettings settings) { |
| 3445 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3446 | |
| 3447 | final long identity = Binder.clearCallingIdentity(); |
| 3448 | try { |
| 3449 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3450 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3451 | } finally { |
| 3452 | Binder.restoreCallingIdentity(identity); |
| 3453 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3454 | } |
| 3455 | |
| 3456 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3457 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3458 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3459 | |
| 3460 | final long identity = Binder.clearCallingIdentity(); |
| 3461 | try { |
| 3462 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3463 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3464 | } finally { |
| 3465 | Binder.restoreCallingIdentity(identity); |
| 3466 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3467 | } |
| 3468 | |
| 3469 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3470 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3471 | String callingPackage, int subId) { |
| 3472 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3473 | |
| 3474 | final long identity = Binder.clearCallingIdentity(); |
| 3475 | try { |
| 3476 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3477 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3478 | } finally { |
| 3479 | Binder.restoreCallingIdentity(identity); |
| 3480 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3481 | } |
| 3482 | |
| 3483 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3484 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3485 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3486 | |
| 3487 | final long identity = Binder.clearCallingIdentity(); |
| 3488 | try { |
| 3489 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3490 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3491 | } finally { |
| 3492 | Binder.restoreCallingIdentity(identity); |
| 3493 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3494 | } |
| 3495 | |
| 3496 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3497 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3498 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3499 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3500 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3501 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3502 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3503 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3504 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3505 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3506 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3507 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3508 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3509 | * Sets the voice activation state of a given subId. |
| 3510 | */ |
| 3511 | @Override |
| 3512 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3513 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3514 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3515 | |
| 3516 | final long identity = Binder.clearCallingIdentity(); |
| 3517 | try { |
| 3518 | final Phone phone = getPhone(subId); |
| 3519 | if (phone != null) { |
| 3520 | phone.setVoiceActivationState(activationState); |
| 3521 | } else { |
| 3522 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3523 | } |
| 3524 | } finally { |
| 3525 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3526 | } |
| 3527 | } |
| 3528 | |
| 3529 | /** |
| 3530 | * Sets the data activation state of a given subId. |
| 3531 | */ |
| 3532 | @Override |
| 3533 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3534 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3535 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3536 | |
| 3537 | final long identity = Binder.clearCallingIdentity(); |
| 3538 | try { |
| 3539 | final Phone phone = getPhone(subId); |
| 3540 | if (phone != null) { |
| 3541 | phone.setDataActivationState(activationState); |
| 3542 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3543 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3544 | } |
| 3545 | } finally { |
| 3546 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3547 | } |
| 3548 | } |
| 3549 | |
| 3550 | /** |
| 3551 | * Returns the voice activation state of a given subId. |
| 3552 | */ |
| 3553 | @Override |
| 3554 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3555 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3556 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3557 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3558 | final long identity = Binder.clearCallingIdentity(); |
| 3559 | try { |
| 3560 | if (phone != null) { |
| 3561 | return phone.getVoiceActivationState(); |
| 3562 | } else { |
| 3563 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3564 | } |
| 3565 | } finally { |
| 3566 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3567 | } |
| 3568 | } |
| 3569 | |
| 3570 | /** |
| 3571 | * Returns the data activation state of a given subId. |
| 3572 | */ |
| 3573 | @Override |
| 3574 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3575 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3576 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3577 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3578 | final long identity = Binder.clearCallingIdentity(); |
| 3579 | try { |
| 3580 | if (phone != null) { |
| 3581 | return phone.getDataActivationState(); |
| 3582 | } else { |
| 3583 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3584 | } |
| 3585 | } finally { |
| 3586 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3587 | } |
| 3588 | } |
| 3589 | |
| 3590 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3591 | * Returns the unread count of voicemails for a subId |
| 3592 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3593 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3594 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3595 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3596 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3597 | mApp, subId, callingPackage, callingFeatureId, |
| 3598 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3599 | return 0; |
| 3600 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3601 | final long identity = Binder.clearCallingIdentity(); |
| 3602 | try { |
| 3603 | final Phone phone = getPhone(subId); |
| 3604 | if (phone != null) { |
| 3605 | return phone.getVoiceMessageCount(); |
| 3606 | } else { |
| 3607 | return 0; |
| 3608 | } |
| 3609 | } finally { |
| 3610 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3611 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3612 | } |
| 3613 | |
| 3614 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3615 | * returns true, if the device is in a state where both voice and data |
| 3616 | * are supported simultaneously. This can change based on location or network condition. |
| 3617 | */ |
| 3618 | @Override |
| 3619 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3620 | final long identity = Binder.clearCallingIdentity(); |
| 3621 | try { |
| 3622 | final Phone phone = getPhone(subId); |
| 3623 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3624 | } finally { |
| 3625 | Binder.restoreCallingIdentity(identity); |
| 3626 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3627 | } |
| 3628 | |
| 3629 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3630 | * Send the dialer code if called from the current default dialer or the caller has |
| 3631 | * carrier privilege. |
| 3632 | * @param inputCode The dialer code to send |
| 3633 | */ |
| 3634 | @Override |
| 3635 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3636 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3637 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3638 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3639 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3640 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3641 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3642 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3643 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3644 | |
| 3645 | final long identity = Binder.clearCallingIdentity(); |
| 3646 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3647 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3648 | } finally { |
| 3649 | Binder.restoreCallingIdentity(identity); |
| 3650 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3651 | } |
| 3652 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3653 | @Override |
| 3654 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3655 | TelephonyPermissions |
| 3656 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3657 | mApp, subId, "getNetworkSelectionMode"); |
| 3658 | final long identity = Binder.clearCallingIdentity(); |
| 3659 | try { |
| 3660 | if (!isActiveSubscription(subId)) { |
| 3661 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3662 | } |
| 3663 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3664 | } finally { |
| 3665 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3666 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3667 | } |
| 3668 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3669 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3670 | public boolean isInEmergencySmsMode() { |
| 3671 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3672 | final long identity = Binder.clearCallingIdentity(); |
| 3673 | try { |
| 3674 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3675 | if (phone.isInEmergencySmsMode()) { |
| 3676 | return true; |
| 3677 | } |
| 3678 | } |
| 3679 | } finally { |
| 3680 | Binder.restoreCallingIdentity(identity); |
| 3681 | } |
| 3682 | return false; |
| 3683 | } |
| 3684 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3685 | /** |
| 3686 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3687 | * @param subId The subscription to use to check the configuration. |
| 3688 | * @param c The callback that will be used to send the result. |
| 3689 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3690 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3691 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3692 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3693 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3694 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3695 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3696 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3697 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3698 | "IMS not available on device."); |
| 3699 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3700 | final long token = Binder.clearCallingIdentity(); |
| 3701 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3702 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3703 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3704 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3705 | } catch (ImsException e) { |
| 3706 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3707 | } finally { |
| 3708 | Binder.restoreCallingIdentity(token); |
| 3709 | } |
| 3710 | } |
| 3711 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3712 | /** |
| 3713 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3714 | * @param subId The subscription to use to check the configuration. |
| 3715 | * @param c The callback that will be used to send the result. |
| 3716 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3717 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3718 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3719 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3720 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3721 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3722 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3723 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3724 | final long token = Binder.clearCallingIdentity(); |
| 3725 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3726 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3727 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3728 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3729 | } catch (ImsException e) { |
| 3730 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3731 | + "is inactive, ignoring unregister."); |
| 3732 | // If the subscription is no longer active, just return, since the callback |
| 3733 | // will already have been removed internally. |
| 3734 | } finally { |
| 3735 | Binder.restoreCallingIdentity(token); |
| 3736 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3737 | } |
| 3738 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3739 | /** |
| 3740 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3741 | */ |
| 3742 | @Override |
| 3743 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3744 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3745 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3746 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3747 | "IMS not available on device."); |
| 3748 | } |
| 3749 | final long token = Binder.clearCallingIdentity(); |
| 3750 | try { |
| 3751 | Phone phone = getPhone(subId); |
| 3752 | if (phone == null) { |
| 3753 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3754 | + subId + "'"); |
| 3755 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3756 | } |
| 3757 | phone.getImsRegistrationState(regState -> { |
| 3758 | try { |
| 3759 | consumer.accept((regState == null) |
| 3760 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3761 | } catch (RemoteException e) { |
| 3762 | // Ignore if the remote process is no longer available to call back. |
| 3763 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3764 | } |
| 3765 | }); |
| 3766 | } finally { |
| 3767 | Binder.restoreCallingIdentity(token); |
| 3768 | } |
| 3769 | } |
| 3770 | |
| 3771 | /** |
| 3772 | * Get the transport type for the IMS service registration state. |
| 3773 | */ |
| 3774 | @Override |
| 3775 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3776 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3777 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3778 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3779 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3780 | "IMS not available on device."); |
| 3781 | } |
| 3782 | final long token = Binder.clearCallingIdentity(); |
| 3783 | try { |
| 3784 | Phone phone = getPhone(subId); |
| 3785 | if (phone == null) { |
| 3786 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3787 | + subId + "'"); |
| 3788 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3789 | } |
| 3790 | phone.getImsRegistrationTech(regTech -> { |
| 3791 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3792 | int regTechConverted = (regTech == null) |
| 3793 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3794 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3795 | regTechConverted); |
| 3796 | try { |
| 3797 | consumer.accept(regTechConverted); |
| 3798 | } catch (RemoteException e) { |
| 3799 | // Ignore if the remote process is no longer available to call back. |
| 3800 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3801 | } |
| 3802 | }); |
| 3803 | } finally { |
| 3804 | Binder.restoreCallingIdentity(token); |
| 3805 | } |
| 3806 | } |
| 3807 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3808 | /** |
| 3809 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3810 | * @param subId The subscription to use to check the configuration. |
| 3811 | * @param c The callback that will be used to send the result. |
| 3812 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3813 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3814 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3815 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3816 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3817 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3818 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3819 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3820 | "IMS not available on device."); |
| 3821 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3822 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3823 | final long token = Binder.clearCallingIdentity(); |
| 3824 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3825 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3826 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3827 | } catch (ImsException e) { |
| 3828 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3829 | } finally { |
| 3830 | Binder.restoreCallingIdentity(token); |
| 3831 | } |
| 3832 | } |
| 3833 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3834 | /** |
| 3835 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3836 | * @param subId The subscription to use to check the configuration. |
| 3837 | * @param c The callback that will be used to send the result. |
| 3838 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3839 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3840 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3841 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3842 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3843 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3844 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3845 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3846 | |
| 3847 | final long token = Binder.clearCallingIdentity(); |
| 3848 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3849 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3850 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3851 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3852 | } catch (ImsException e) { |
| 3853 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3854 | + "is inactive, ignoring unregister."); |
| 3855 | // If the subscription is no longer active, just return, since the callback |
| 3856 | // will already have been removed internally. |
| 3857 | } finally { |
| 3858 | Binder.restoreCallingIdentity(token); |
| 3859 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3860 | } |
| 3861 | |
| 3862 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3863 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3864 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3865 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3866 | final long token = Binder.clearCallingIdentity(); |
| 3867 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3868 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3869 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3870 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3871 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3872 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3873 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3874 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3875 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3876 | } finally { |
| 3877 | Binder.restoreCallingIdentity(token); |
| 3878 | } |
| 3879 | } |
| 3880 | |
| 3881 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3882 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3883 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3884 | final long token = Binder.clearCallingIdentity(); |
| 3885 | try { |
| 3886 | Phone phone = getPhone(subId); |
| 3887 | if (phone == null) return false; |
| 3888 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3889 | } catch (com.android.ims.ImsException e) { |
| 3890 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3891 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3892 | } finally { |
| 3893 | Binder.restoreCallingIdentity(token); |
| 3894 | } |
| 3895 | } |
| 3896 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3897 | /** |
| 3898 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3899 | * subscription. |
| 3900 | * @param subId The subscription to use to check the configuration. |
| 3901 | * @param callback The callback that will be used to send the result. |
| 3902 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3903 | * @param transportType The transport type of the MmTelFeature capability. |
| 3904 | */ |
| 3905 | @Override |
| 3906 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3907 | int transportType) { |
| 3908 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3909 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3910 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3911 | "IMS not available on device."); |
| 3912 | } |
| 3913 | final long token = Binder.clearCallingIdentity(); |
| 3914 | try { |
| 3915 | int slotId = getSlotIndex(subId); |
| 3916 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3917 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3918 | + subId + "'"); |
| 3919 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3920 | } |
| 3921 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3922 | transportType, aBoolean -> { |
| 3923 | try { |
| 3924 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3925 | } catch (RemoteException e) { |
| 3926 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3927 | + "running. Ignore"); |
| 3928 | } |
| 3929 | }); |
| 3930 | } finally { |
| 3931 | Binder.restoreCallingIdentity(token); |
| 3932 | } |
| 3933 | } |
| 3934 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3935 | /** |
| 3936 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3937 | * @param subId The subscription to use to check the configuration. |
| 3938 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3939 | @Override |
| 3940 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3941 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3942 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3943 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3944 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3945 | final long token = Binder.clearCallingIdentity(); |
| 3946 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3947 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3948 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3949 | } catch (ImsException e) { |
| 3950 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3951 | } finally { |
| 3952 | Binder.restoreCallingIdentity(token); |
| 3953 | } |
| 3954 | } |
| 3955 | |
| 3956 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3957 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3958 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3959 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3960 | final long identity = Binder.clearCallingIdentity(); |
| 3961 | try { |
| 3962 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3963 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3964 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3965 | } catch (ImsException e) { |
| 3966 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3967 | } finally { |
| 3968 | Binder.restoreCallingIdentity(identity); |
| 3969 | } |
| 3970 | } |
| 3971 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3972 | /** |
| 3973 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3974 | * @param subId The subscription to use to check the configuration. |
| 3975 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3976 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3977 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3978 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3979 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3980 | final long identity = Binder.clearCallingIdentity(); |
| 3981 | try { |
| 3982 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3983 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3984 | } catch (ImsException e) { |
| 3985 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3986 | } finally { |
| 3987 | Binder.restoreCallingIdentity(identity); |
| 3988 | } |
| 3989 | } |
| 3990 | |
| 3991 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3992 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3993 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3994 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3995 | final long identity = Binder.clearCallingIdentity(); |
| 3996 | try { |
| 3997 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3998 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3999 | } catch (ImsException e) { |
| 4000 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4001 | } finally { |
| 4002 | Binder.restoreCallingIdentity(identity); |
| 4003 | } |
| 4004 | } |
| 4005 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4006 | /** |
| 4007 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4008 | * @param subId The subscription to use to check the configuration. |
| 4009 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4010 | @Override |
| 4011 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4012 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4013 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4014 | final long identity = Binder.clearCallingIdentity(); |
| 4015 | try { |
| 4016 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4017 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4018 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
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 |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4027 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4028 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4029 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4030 | final long identity = Binder.clearCallingIdentity(); |
| 4031 | try { |
| 4032 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4033 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
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 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4041 | /** |
Sooraj Sasindran | e655add | 2020-11-23 19:40:38 -0800 | [diff] [blame] | 4042 | * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not |
| 4043 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4044 | * @param subId The subscription to use to check the configuration. |
| 4045 | */ |
| 4046 | @Override |
| 4047 | public boolean isCrossSimCallingEnabledByUser(int subId) { |
| 4048 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4049 | mApp, subId, "isCrossSimCallingEnabledByUser"); |
| 4050 | final long identity = Binder.clearCallingIdentity(); |
| 4051 | try { |
| 4052 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4053 | return ImsManager.getInstance(mApp, |
| 4054 | getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser(); |
| 4055 | } catch (ImsException e) { |
| 4056 | throw new ServiceSpecificException(e.getCode()); |
| 4057 | } finally { |
| 4058 | Binder.restoreCallingIdentity(identity); |
| 4059 | } |
| 4060 | } |
| 4061 | |
| 4062 | /** |
| 4063 | * Sets the user's setting for whether or not Voice over Cross SIM is enabled. |
| 4064 | * Requires MODIFY_PHONE_STATE permission. |
| 4065 | * @param subId The subscription to use to check the configuration. |
| 4066 | * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled, |
| 4067 | * false otherwise |
| 4068 | */ |
| 4069 | @Override |
| 4070 | public void setCrossSimCallingEnabled(int subId, boolean isEnabled) { |
| 4071 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4072 | "setCrossSimCallingEnabled"); |
| 4073 | final long identity = Binder.clearCallingIdentity(); |
| 4074 | try { |
| 4075 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4076 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 4077 | .setCrossSimCallingEnabled(isEnabled); |
| 4078 | } catch (ImsException e) { |
| 4079 | throw new ServiceSpecificException(e.getCode()); |
| 4080 | } finally { |
| 4081 | Binder.restoreCallingIdentity(identity); |
| 4082 | } |
| 4083 | } |
| 4084 | |
| 4085 | /** |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4086 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4087 | * @param subId The subscription to use to check the configuration. |
| 4088 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4089 | @Override |
| 4090 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4091 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4092 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4093 | final long identity = Binder.clearCallingIdentity(); |
| 4094 | try { |
| 4095 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4096 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4097 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4098 | } catch (ImsException e) { |
| 4099 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4100 | } finally { |
| 4101 | Binder.restoreCallingIdentity(identity); |
| 4102 | } |
| 4103 | } |
| 4104 | |
| 4105 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4106 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4107 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4108 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4109 | final long identity = Binder.clearCallingIdentity(); |
| 4110 | try { |
| 4111 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4112 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4113 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4114 | } catch (ImsException e) { |
| 4115 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4116 | } finally { |
| 4117 | Binder.restoreCallingIdentity(identity); |
| 4118 | } |
| 4119 | } |
| 4120 | |
| 4121 | @Override |
| 4122 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4123 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4124 | "setVoWiFiNonPersistent"); |
| 4125 | final long identity = Binder.clearCallingIdentity(); |
| 4126 | try { |
| 4127 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4128 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 4129 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4130 | } catch (ImsException e) { |
| 4131 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4132 | } finally { |
| 4133 | Binder.restoreCallingIdentity(identity); |
| 4134 | } |
| 4135 | } |
| 4136 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4137 | /** |
| 4138 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4139 | * @param subId The subscription to use to check the configuration. |
| 4140 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4141 | @Override |
| 4142 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4143 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4144 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4145 | final long identity = Binder.clearCallingIdentity(); |
| 4146 | try { |
| 4147 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4148 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4149 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4150 | } catch (ImsException e) { |
| 4151 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4152 | } finally { |
| 4153 | Binder.restoreCallingIdentity(identity); |
| 4154 | } |
| 4155 | } |
| 4156 | |
| 4157 | @Override |
| 4158 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4159 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4160 | "setVoWiFiModeSetting"); |
| 4161 | final long identity = Binder.clearCallingIdentity(); |
| 4162 | try { |
| 4163 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4164 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4165 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4166 | } catch (ImsException e) { |
| 4167 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4168 | } finally { |
| 4169 | Binder.restoreCallingIdentity(identity); |
| 4170 | } |
| 4171 | } |
| 4172 | |
| 4173 | @Override |
| 4174 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4175 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4176 | final long identity = Binder.clearCallingIdentity(); |
| 4177 | try { |
| 4178 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4179 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4180 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4181 | } catch (ImsException e) { |
| 4182 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4183 | } finally { |
| 4184 | Binder.restoreCallingIdentity(identity); |
| 4185 | } |
| 4186 | } |
| 4187 | |
| 4188 | @Override |
| 4189 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4190 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4191 | "setVoWiFiRoamingModeSetting"); |
| 4192 | final long identity = Binder.clearCallingIdentity(); |
| 4193 | try { |
| 4194 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4195 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4196 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4197 | } catch (ImsException e) { |
| 4198 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4199 | } finally { |
| 4200 | Binder.restoreCallingIdentity(identity); |
| 4201 | } |
| 4202 | } |
| 4203 | |
| 4204 | @Override |
| 4205 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4206 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4207 | "setRttCapabilityEnabled"); |
| 4208 | final long identity = Binder.clearCallingIdentity(); |
| 4209 | try { |
| 4210 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4211 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 4212 | } catch (ImsException e) { |
| 4213 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4214 | } finally { |
| 4215 | Binder.restoreCallingIdentity(identity); |
| 4216 | } |
| 4217 | } |
| 4218 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4219 | /** |
| 4220 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4221 | * @param subId The subscription to use to check the configuration. |
| 4222 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4223 | @Override |
| 4224 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4225 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4226 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4227 | final long identity = Binder.clearCallingIdentity(); |
| 4228 | try { |
| 4229 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4230 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4231 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4232 | } catch (ImsException e) { |
| 4233 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4234 | } finally { |
| 4235 | Binder.restoreCallingIdentity(identity); |
| 4236 | } |
| 4237 | } |
| 4238 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4239 | @Override |
| 4240 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4241 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 4242 | final long identity = Binder.clearCallingIdentity(); |
| 4243 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4244 | if (!isImsAvailableOnDevice()) { |
| 4245 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4246 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4247 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4248 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4249 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4250 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4251 | } catch (ImsException e) { |
| 4252 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4253 | } finally { |
| 4254 | Binder.restoreCallingIdentity(identity); |
| 4255 | } |
| 4256 | } |
| 4257 | |
| 4258 | @Override |
| 4259 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4260 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 4261 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4262 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4263 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4264 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4265 | try { |
| 4266 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4267 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4268 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4269 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4270 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4271 | + "is inactive, ignoring unregister."); |
| 4272 | // If the subscription is no longer active, just return, since the callback will already |
| 4273 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4274 | } finally { |
| 4275 | Binder.restoreCallingIdentity(identity); |
| 4276 | } |
| 4277 | } |
| 4278 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4279 | |
| 4280 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4281 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4282 | message); |
| 4283 | } |
| 4284 | |
| 4285 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4286 | boolean isMmtelCapability) { |
| 4287 | Phone phone = getPhone(subId); |
| 4288 | if (phone == null) { |
| 4289 | loge("phone instance null for subid " + subId); |
| 4290 | return false; |
| 4291 | } |
| 4292 | if (isMmtelCapability) { |
| 4293 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4294 | return false; |
| 4295 | } |
| 4296 | } else { |
| 4297 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4298 | return false; |
| 4299 | } |
| 4300 | } |
| 4301 | return true; |
| 4302 | } |
| 4303 | |
| 4304 | @Override |
| 4305 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4306 | boolean isProvisioned) { |
| 4307 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4308 | |
| 4309 | final long identity = Binder.clearCallingIdentity(); |
| 4310 | try { |
| 4311 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4312 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4313 | return; |
| 4314 | } |
| 4315 | |
| 4316 | // this capability requires provisioning, route to the correct API. |
| 4317 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4318 | switch (capability) { |
| 4319 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4320 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4321 | ims.setEabProvisioned(isProvisioned); |
| 4322 | break; |
| 4323 | default: { |
| 4324 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4325 | + "rcs capability '" + capability + "', which does not require " |
| 4326 | + "provisioning."); |
| 4327 | } |
| 4328 | } |
| 4329 | } finally { |
| 4330 | Binder.restoreCallingIdentity(identity); |
| 4331 | } |
| 4332 | |
| 4333 | } |
| 4334 | |
| 4335 | |
| 4336 | @Override |
| 4337 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4338 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4339 | final long identity = Binder.clearCallingIdentity(); |
| 4340 | try { |
| 4341 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4342 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4343 | return true; |
| 4344 | } |
| 4345 | |
| 4346 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4347 | switch (capability) { |
| 4348 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4349 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4350 | return ims.isEabProvisionedOnDevice(); |
| 4351 | |
| 4352 | default: { |
| 4353 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4354 | + "capability '" + capability + "', which does not require " |
| 4355 | + "provisioning."); |
| 4356 | } |
| 4357 | } |
| 4358 | |
| 4359 | } finally { |
| 4360 | Binder.restoreCallingIdentity(identity); |
| 4361 | } |
| 4362 | } |
| 4363 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4364 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4365 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4366 | boolean isProvisioned) { |
| 4367 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4368 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4369 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4370 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4371 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4372 | final long identity = Binder.clearCallingIdentity(); |
| 4373 | try { |
| 4374 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4375 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4376 | return; |
| 4377 | } |
| 4378 | |
| 4379 | // this capability requires provisioning, route to the correct API. |
| 4380 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4381 | switch (capability) { |
| 4382 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4383 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4384 | ims.setVolteProvisioned(isProvisioned); |
| 4385 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4386 | ims.setWfcProvisioned(isProvisioned); |
| 4387 | } |
| 4388 | break; |
| 4389 | } |
| 4390 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4391 | // There is currently no difference in VT provisioning type. |
| 4392 | ims.setVtProvisioned(isProvisioned); |
| 4393 | break; |
| 4394 | } |
| 4395 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4396 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4397 | // change the capability of the feature instead if needed. |
| 4398 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4399 | == isProvisioned) { |
| 4400 | // No change in provisioning. |
| 4401 | return; |
| 4402 | } |
| 4403 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4404 | try { |
| 4405 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4406 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4407 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4408 | + ", Exception" + e.getMessage()); |
| 4409 | } |
| 4410 | break; |
| 4411 | } |
| 4412 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4413 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4414 | + "MmTel capability '" + capability + "', which does not require " |
| 4415 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4416 | } |
| 4417 | } |
| 4418 | |
| 4419 | } finally { |
| 4420 | Binder.restoreCallingIdentity(identity); |
| 4421 | } |
| 4422 | } |
| 4423 | |
| 4424 | @Override |
| 4425 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4426 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4427 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4428 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4429 | } |
| 4430 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4431 | final long identity = Binder.clearCallingIdentity(); |
| 4432 | try { |
| 4433 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4434 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4435 | return true; |
| 4436 | } |
| 4437 | |
| 4438 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4439 | switch (capability) { |
| 4440 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4441 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4442 | return ims.isVolteProvisionedOnDevice(); |
| 4443 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4444 | return ims.isWfcProvisionedOnDevice(); |
| 4445 | } |
| 4446 | // This should never happen, since we are checking tech above to make sure it |
| 4447 | // is either LTE or IWLAN. |
| 4448 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4449 | + "capability."); |
| 4450 | } |
| 4451 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4452 | // There is currently no difference in VT provisioning type. |
| 4453 | return ims.isVtProvisionedOnDevice(); |
| 4454 | } |
| 4455 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4456 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4457 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4458 | } |
| 4459 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4460 | throw new IllegalArgumentException( |
| 4461 | "Tried to get provisioning for MmTel capability '" + capability |
| 4462 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4463 | } |
| 4464 | } |
| 4465 | |
| 4466 | } finally { |
| 4467 | Binder.restoreCallingIdentity(identity); |
| 4468 | } |
| 4469 | } |
| 4470 | |
| 4471 | @Override |
| 4472 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4473 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4474 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4475 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4476 | } |
| 4477 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4478 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4479 | return (provisionedBits & capability) > 0; |
| 4480 | } |
| 4481 | |
| 4482 | @Override |
| 4483 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4484 | boolean isProvisioned) { |
| 4485 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4486 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4487 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4488 | } |
| 4489 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4490 | "setProvisioningStatusForCapability"); |
| 4491 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4492 | // If the current provisioning status for capability already matches isProvisioned, |
| 4493 | // do nothing. |
| 4494 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4495 | return; |
| 4496 | } |
| 4497 | if (isProvisioned) { |
| 4498 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4499 | } else { |
| 4500 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4501 | } |
| 4502 | } |
| 4503 | |
| 4504 | /** |
| 4505 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4506 | * technology. The bitfield should mirror the bitfield defined by |
| 4507 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4508 | */ |
| 4509 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4510 | String key = getMmTelProvisioningKey(subId, tech); |
| 4511 | // Default is no capabilities are provisioned. |
| 4512 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4513 | } |
| 4514 | |
| 4515 | /** |
| 4516 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4517 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4518 | * technology specified. |
| 4519 | * |
| 4520 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4521 | */ |
| 4522 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4523 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4524 | String key = getMmTelProvisioningKey(subId, tech); |
| 4525 | editor.putInt(key, newField); |
| 4526 | editor.commit(); |
| 4527 | } |
| 4528 | |
| 4529 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4530 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4531 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4532 | } |
| 4533 | |
| 4534 | /** |
| 4535 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4536 | * carrier associated with the subscription id. |
| 4537 | */ |
| 4538 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4539 | int capability) { |
| 4540 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4541 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4542 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4543 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4544 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4545 | false); |
| 4546 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4547 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4548 | |
| 4549 | // First check to make sure that the capability requires provisioning. |
| 4550 | switch (capability) { |
| 4551 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4552 | // intentional fallthrough |
| 4553 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4554 | if (requireVoiceVtProvisioning) { |
| 4555 | // Voice and Video requires provisioning |
| 4556 | return true; |
| 4557 | } |
| 4558 | break; |
| 4559 | } |
| 4560 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4561 | if (requireUtProvisioning) { |
| 4562 | // UT requires provisioning |
| 4563 | return true; |
| 4564 | } |
| 4565 | break; |
| 4566 | } |
| 4567 | } |
| 4568 | return false; |
| 4569 | } |
| 4570 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4571 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4572 | int capability) { |
| 4573 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4574 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4575 | |
| 4576 | boolean requireRcsProvisioning = c.getBoolean( |
| 4577 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4578 | |
| 4579 | // First check to make sure that the capability requires provisioning. |
| 4580 | switch (capability) { |
| 4581 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4582 | // intentional fallthrough |
| 4583 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4584 | if (requireRcsProvisioning) { |
| 4585 | // OPTION or PRESENCE requires provisioning |
| 4586 | return true; |
| 4587 | } |
| 4588 | break; |
| 4589 | } |
| 4590 | } |
| 4591 | return false; |
| 4592 | } |
| 4593 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4594 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4595 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4596 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4597 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4598 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4599 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4600 | final long identity = Binder.clearCallingIdentity(); |
| 4601 | try { |
| 4602 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4603 | int slotId = getSlotIndex(subId); |
| 4604 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4605 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4606 | + subId + "' for key:" + key); |
| 4607 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4608 | } |
| 4609 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4610 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4611 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4612 | + subId + "' for key:" + key); |
| 4613 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4614 | } finally { |
| 4615 | Binder.restoreCallingIdentity(identity); |
| 4616 | } |
| 4617 | } |
| 4618 | |
| 4619 | @Override |
| 4620 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4621 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4622 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4623 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4624 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4625 | final long identity = Binder.clearCallingIdentity(); |
| 4626 | try { |
| 4627 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4628 | int slotId = getSlotIndex(subId); |
| 4629 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4630 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4631 | + subId + "' for key:" + key); |
| 4632 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4633 | } |
| 4634 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4635 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4636 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4637 | + subId + "' for key:" + key); |
| 4638 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4639 | } finally { |
| 4640 | Binder.restoreCallingIdentity(identity); |
| 4641 | } |
| 4642 | } |
| 4643 | |
| 4644 | @Override |
| 4645 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4646 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4647 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4648 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4649 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4650 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4651 | final long identity = Binder.clearCallingIdentity(); |
| 4652 | try { |
| 4653 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4654 | int slotId = getSlotIndex(subId); |
| 4655 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4656 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4657 | + subId + "' for key:" + key); |
| 4658 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4659 | } |
| 4660 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4661 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4662 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4663 | + "' for key:" + key); |
| 4664 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4665 | } finally { |
| 4666 | Binder.restoreCallingIdentity(identity); |
| 4667 | } |
| 4668 | } |
| 4669 | |
| 4670 | @Override |
| 4671 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4672 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4673 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4674 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4675 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4676 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4677 | final long identity = Binder.clearCallingIdentity(); |
| 4678 | try { |
| 4679 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4680 | int slotId = getSlotIndex(subId); |
| 4681 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4682 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4683 | + subId + "' for key:" + key); |
| 4684 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4685 | } |
| 4686 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4687 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4688 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4689 | + "' for key:" + key); |
| 4690 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4691 | } finally { |
| 4692 | Binder.restoreCallingIdentity(identity); |
| 4693 | } |
| 4694 | } |
| 4695 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4696 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4697 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4698 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4699 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4700 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4701 | } |
| 4702 | return slotId; |
| 4703 | } |
| 4704 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4705 | private int getSlotIndex(int subId) { |
| 4706 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4707 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4708 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4709 | } |
| 4710 | return slotId; |
| 4711 | } |
| 4712 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4713 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4714 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4715 | */ |
| 4716 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4717 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4718 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 4719 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4720 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4721 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4722 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4723 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4724 | mApp, subId, callingPackage, callingFeatureId, |
| 4725 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4726 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4727 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4728 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4729 | final long identity = Binder.clearCallingIdentity(); |
| 4730 | try { |
| 4731 | final Phone phone = getPhone(subId); |
| 4732 | if (phone != null) { |
| 4733 | return phone.getServiceState().getDataNetworkType(); |
| 4734 | } else { |
| 4735 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4736 | } |
| 4737 | } finally { |
| 4738 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4739 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4740 | } |
| 4741 | |
| 4742 | /** |
| 4743 | * Returns the data network type |
| 4744 | */ |
| 4745 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4746 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4747 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4748 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4749 | } |
| 4750 | |
| 4751 | /** |
| 4752 | * Returns the data network type for a subId |
| 4753 | */ |
| 4754 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4755 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4756 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4757 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4758 | mApp, subId, callingPackage, callingFeatureId, |
| 4759 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4760 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4761 | } |
| 4762 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4763 | final long identity = Binder.clearCallingIdentity(); |
| 4764 | try { |
| 4765 | final Phone phone = getPhone(subId); |
| 4766 | if (phone != null) { |
| 4767 | return phone.getServiceState().getDataNetworkType(); |
| 4768 | } else { |
| 4769 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4770 | } |
| 4771 | } finally { |
| 4772 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4773 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4774 | } |
| 4775 | |
| 4776 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4777 | * Returns the Voice network type for a subId |
| 4778 | */ |
| 4779 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4780 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4781 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4782 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4783 | mApp, subId, callingPackage, callingFeatureId, |
| 4784 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4785 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4786 | } |
| 4787 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4788 | final long identity = Binder.clearCallingIdentity(); |
| 4789 | try { |
| 4790 | final Phone phone = getPhone(subId); |
| 4791 | if (phone != null) { |
| 4792 | return phone.getServiceState().getVoiceNetworkType(); |
| 4793 | } else { |
| 4794 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4795 | } |
| 4796 | } finally { |
| 4797 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4798 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4799 | } |
| 4800 | |
| 4801 | /** |
| 4802 | * @return true if a ICC card is present |
| 4803 | */ |
| 4804 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4805 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4806 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4807 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4808 | } |
| 4809 | |
| 4810 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4811 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4812 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4813 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4814 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4815 | final long identity = Binder.clearCallingIdentity(); |
| 4816 | try { |
| 4817 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4818 | if (phone != null) { |
| 4819 | return phone.getIccCard().hasIccCard(); |
| 4820 | } else { |
| 4821 | return false; |
| 4822 | } |
| 4823 | } finally { |
| 4824 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4825 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4826 | } |
| 4827 | |
| 4828 | /** |
| 4829 | * Return if the current radio is LTE on CDMA. This |
| 4830 | * is a tri-state return value as for a period of time |
| 4831 | * the mode may be unknown. |
| 4832 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4833 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4834 | * @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] | 4835 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4836 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4837 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4838 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4839 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4840 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4841 | } |
| 4842 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4843 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4844 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4845 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4846 | try { |
| 4847 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4848 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4849 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4850 | } |
| 4851 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4852 | final long identity = Binder.clearCallingIdentity(); |
| 4853 | try { |
| 4854 | final Phone phone = getPhone(subId); |
| 4855 | if (phone == null) { |
| 4856 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4857 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 4858 | return TelephonyProperties.lte_on_cdma_device() |
| 4859 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4860 | } |
| 4861 | } finally { |
| 4862 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4863 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4864 | } |
| 4865 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4866 | /** |
| 4867 | * {@hide} |
| 4868 | * Returns Default subId, 0 in the case of single standby. |
| 4869 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4870 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4871 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4872 | } |
| 4873 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4874 | private int getSlotForDefaultSubscription() { |
| 4875 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4876 | } |
| 4877 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4878 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4879 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4880 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4881 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4882 | private boolean isActiveSubscription(int subId) { |
| 4883 | return mSubscriptionController.isActiveSubId(subId); |
| 4884 | } |
| 4885 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4886 | /** |
| 4887 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4888 | */ |
| 4889 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4890 | final long identity = Binder.clearCallingIdentity(); |
| 4891 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4892 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4893 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4894 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4895 | } finally { |
| 4896 | Binder.restoreCallingIdentity(identity); |
| 4897 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4898 | } |
| 4899 | |
| 4900 | /** |
| 4901 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4902 | */ |
| 4903 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4904 | final long identity = Binder.clearCallingIdentity(); |
| 4905 | try { |
| 4906 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4907 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4908 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4909 | } finally { |
| 4910 | Binder.restoreCallingIdentity(identity); |
| 4911 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4912 | } |
| 4913 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4914 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4915 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4916 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4917 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4918 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4919 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4920 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4921 | if (phoneId == -1) { |
| 4922 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4923 | + " does not correspond to an active phone"); |
| 4924 | } |
| 4925 | return PhoneFactory.getPhone(phoneId); |
| 4926 | } |
| 4927 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4928 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4929 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4930 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4931 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4932 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4933 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4934 | if (DBG) { |
| 4935 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4936 | } |
| 4937 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4938 | p2); |
| 4939 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4940 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4941 | |
| 4942 | @Override |
| 4943 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4944 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4945 | enforceModifyPermission(); |
| 4946 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4947 | if (DBG) { |
| 4948 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4949 | } |
| 4950 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4951 | callingPackage, aid, p2); |
| 4952 | } |
| 4953 | |
| 4954 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4955 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4956 | final long identity = Binder.clearCallingIdentity(); |
| 4957 | try { |
| 4958 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4959 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4960 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4961 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4962 | if (bestComponent == null |
| 4963 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4964 | loge("The calling package is not allowed to access ISD-R."); |
| 4965 | throw new SecurityException( |
| 4966 | "The calling package is not allowed to access ISD-R."); |
| 4967 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4968 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4969 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4970 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4971 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4972 | null /* workSource */); |
| 4973 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4974 | return response; |
| 4975 | } finally { |
| 4976 | Binder.restoreCallingIdentity(identity); |
| 4977 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4978 | } |
| 4979 | |
| 4980 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4981 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4982 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4983 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4984 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4985 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4986 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4987 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4988 | @Override |
| 4989 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4990 | enforceModifyPermission(); |
| 4991 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4992 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4993 | channel); |
| 4994 | } |
| 4995 | |
| 4996 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4997 | final long identity = Binder.clearCallingIdentity(); |
| 4998 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4999 | if (channel < 0) { |
| 5000 | return false; |
| 5001 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5002 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 5003 | null /* workSource */); |
| 5004 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5005 | return success; |
| 5006 | } finally { |
| 5007 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5008 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5009 | } |
| 5010 | |
| 5011 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5012 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5013 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5014 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5015 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5016 | if (DBG) { |
| 5017 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 5018 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5019 | + p3 + " data=" + data); |
| 5020 | } |
| 5021 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 5022 | command, p1, p2, p3, data); |
| 5023 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5024 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5025 | @Override |
| 5026 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 5027 | int command, int p1, int p2, int p3, String data) { |
| 5028 | enforceModifyPermission(); |
| 5029 | if (DBG) { |
| 5030 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 5031 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5032 | + p3 + " data=" + data); |
| 5033 | } |
| 5034 | return iccTransmitApduLogicalChannelWithPermission( |
| 5035 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 5036 | data); |
| 5037 | } |
| 5038 | |
| 5039 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5040 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5041 | final long identity = Binder.clearCallingIdentity(); |
| 5042 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5043 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5044 | return ""; |
| 5045 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5046 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5047 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5048 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5049 | null /* workSource */); |
| 5050 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5051 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5052 | // Append the returned status code to the end of the response payload. |
| 5053 | String s = Integer.toHexString( |
| 5054 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5055 | if (response.payload != null) { |
| 5056 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5057 | } |
| 5058 | return s; |
| 5059 | } finally { |
| 5060 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5061 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5062 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5063 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5064 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5065 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5066 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5067 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5068 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5069 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5070 | if (DBG) { |
| 5071 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5072 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5073 | } |
| 5074 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5075 | cla, command, p1, p2, p3, data); |
| 5076 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5077 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5078 | @Override |
| 5079 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 5080 | int command, int p1, int p2, int p3, String data) { |
| 5081 | enforceModifyPermission(); |
| 5082 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5083 | if (DBG) { |
| 5084 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 5085 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 5086 | + " data=" + data); |
| 5087 | } |
| 5088 | |
| 5089 | return iccTransmitApduBasicChannelWithPermission( |
| 5090 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 5091 | p2, p3, data); |
| 5092 | } |
| 5093 | |
| 5094 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5095 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5096 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5097 | final long identity = Binder.clearCallingIdentity(); |
| 5098 | try { |
| 5099 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5100 | && TextUtils.equals(ISDR_AID, data)) { |
| 5101 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5102 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5103 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5104 | if (bestComponent == null |
| 5105 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5106 | loge("The calling package is not allowed to select ISD-R."); |
| 5107 | throw new SecurityException( |
| 5108 | "The calling package is not allowed to select ISD-R."); |
| 5109 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5110 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5111 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5112 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5113 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5114 | null /* workSource */); |
| 5115 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5116 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5117 | // Append the returned status code to the end of the response payload. |
| 5118 | String s = Integer.toHexString( |
| 5119 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5120 | if (response.payload != null) { |
| 5121 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5122 | } |
| 5123 | return s; |
| 5124 | } finally { |
| 5125 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5126 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5127 | } |
| 5128 | |
| 5129 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5130 | 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] | 5131 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5132 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5133 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5134 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5135 | final long identity = Binder.clearCallingIdentity(); |
| 5136 | try { |
| 5137 | if (DBG) { |
| 5138 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5139 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5140 | } |
| 5141 | |
| 5142 | IccIoResult response = |
| 5143 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5144 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5145 | subId); |
| 5146 | |
| 5147 | if (DBG) { |
| 5148 | log("Exchange SIM_IO [R]" + response); |
| 5149 | } |
| 5150 | |
| 5151 | byte[] result = null; |
| 5152 | int length = 2; |
| 5153 | if (response.payload != null) { |
| 5154 | length = 2 + response.payload.length; |
| 5155 | result = new byte[length]; |
| 5156 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5157 | } else { |
| 5158 | result = new byte[length]; |
| 5159 | } |
| 5160 | |
| 5161 | result[length - 1] = (byte) response.sw2; |
| 5162 | result[length - 2] = (byte) response.sw1; |
| 5163 | return result; |
| 5164 | } finally { |
| 5165 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5166 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5167 | } |
| 5168 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5169 | /** |
| 5170 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5171 | * on a particular subscription |
| 5172 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5173 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5174 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5175 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5176 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5177 | return null; |
| 5178 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5179 | |
| 5180 | final long identity = Binder.clearCallingIdentity(); |
| 5181 | try { |
| 5182 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5183 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5184 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5185 | return null; |
| 5186 | } |
| 5187 | Object response = sendRequest( |
| 5188 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5189 | if (response instanceof String[]) { |
| 5190 | return (String[]) response; |
| 5191 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5192 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5193 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5194 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5195 | } finally { |
| 5196 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5197 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5198 | } |
| 5199 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5200 | /** |
| 5201 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5202 | * subscription. |
| 5203 | * |
| 5204 | * @param subId the id of the subscription. |
| 5205 | * @param appType the uicc app type, must be USIM or SIM. |
| 5206 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5207 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5208 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5209 | * @return number of fplmns that is successfully written to the SIM. |
| 5210 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5211 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5212 | String callingFeatureId) { |
| 5213 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 5214 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5215 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 5216 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 5217 | } |
| 5218 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5219 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5220 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5221 | } |
| 5222 | if (fplmns == null) { |
| 5223 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5224 | } |
| 5225 | for (String fplmn : fplmns) { |
| 5226 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5227 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5228 | } |
| 5229 | } |
| 5230 | final long identity = Binder.clearCallingIdentity(); |
| 5231 | try { |
| 5232 | Object response = sendRequest( |
| 5233 | CMD_SET_FORBIDDEN_PLMNS, |
| 5234 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5235 | subId); |
| 5236 | return (int) response; |
| 5237 | } finally { |
| 5238 | Binder.restoreCallingIdentity(identity); |
| 5239 | } |
| 5240 | } |
| 5241 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5242 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5243 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5244 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5245 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5246 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5247 | final long identity = Binder.clearCallingIdentity(); |
| 5248 | try { |
| 5249 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5250 | if (response.payload == null) { |
| 5251 | return ""; |
| 5252 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5253 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5254 | // Append the returned status code to the end of the response payload. |
| 5255 | String s = Integer.toHexString( |
| 5256 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5257 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5258 | return s; |
| 5259 | } finally { |
| 5260 | Binder.restoreCallingIdentity(identity); |
| 5261 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5262 | } |
| 5263 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5264 | /** |
| 5265 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5266 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5267 | * |
| 5268 | * @param itemID the ID of the item to read |
| 5269 | * @return the NV item as a String, or null on error. |
| 5270 | */ |
| 5271 | @Override |
| 5272 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5273 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5274 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5275 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5276 | |
| 5277 | final long identity = Binder.clearCallingIdentity(); |
| 5278 | try { |
| 5279 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5280 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5281 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5282 | return value; |
| 5283 | } finally { |
| 5284 | Binder.restoreCallingIdentity(identity); |
| 5285 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5286 | } |
| 5287 | |
| 5288 | /** |
| 5289 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5290 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5291 | * |
| 5292 | * @param itemID the ID of the item to read |
| 5293 | * @param itemValue the value to write, as a String |
| 5294 | * @return true on success; false on any failure |
| 5295 | */ |
| 5296 | @Override |
| 5297 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5298 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5299 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5300 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5301 | |
| 5302 | final long identity = Binder.clearCallingIdentity(); |
| 5303 | try { |
| 5304 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5305 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5306 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5307 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5308 | return success; |
| 5309 | } finally { |
| 5310 | Binder.restoreCallingIdentity(identity); |
| 5311 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5312 | } |
| 5313 | |
| 5314 | /** |
| 5315 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5316 | * Used for device configuration by some CDMA operators. |
| 5317 | * |
| 5318 | * @param preferredRoamingList byte array containing the new PRL |
| 5319 | * @return true on success; false on any failure |
| 5320 | */ |
| 5321 | @Override |
| 5322 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5323 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5324 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5325 | |
| 5326 | final long identity = Binder.clearCallingIdentity(); |
| 5327 | try { |
| 5328 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5329 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5330 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5331 | return success; |
| 5332 | } finally { |
| 5333 | Binder.restoreCallingIdentity(identity); |
| 5334 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5335 | } |
| 5336 | |
| 5337 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5338 | * 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] | 5339 | * Used for device configuration by some CDMA operators. |
| 5340 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5341 | * @param slotIndex - device slot. |
| 5342 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5343 | * @return true on success; false on any failure |
| 5344 | */ |
| 5345 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5346 | public boolean resetModemConfig(int slotIndex) { |
| 5347 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5348 | if (phone != null) { |
| 5349 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5350 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5351 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5352 | final long identity = Binder.clearCallingIdentity(); |
| 5353 | try { |
| 5354 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5355 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5356 | return success; |
| 5357 | } finally { |
| 5358 | Binder.restoreCallingIdentity(identity); |
| 5359 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5360 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5361 | return false; |
| 5362 | } |
| 5363 | |
| 5364 | /** |
| 5365 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5366 | * |
| 5367 | * @param slotIndex - device slot. |
| 5368 | * |
| 5369 | * @return true on success; false on any failure |
| 5370 | */ |
| 5371 | @Override |
| 5372 | public boolean rebootModem(int slotIndex) { |
| 5373 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5374 | if (phone != null) { |
| 5375 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5376 | mApp, phone.getSubId(), "rebootModem"); |
| 5377 | |
| 5378 | final long identity = Binder.clearCallingIdentity(); |
| 5379 | try { |
| 5380 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5381 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5382 | return success; |
| 5383 | } finally { |
| 5384 | Binder.restoreCallingIdentity(identity); |
| 5385 | } |
| 5386 | } |
| 5387 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5388 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5389 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5390 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5391 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5392 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5393 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5394 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5395 | return new String[0]; |
| 5396 | } |
| 5397 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5398 | final long identity = Binder.clearCallingIdentity(); |
| 5399 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5400 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5401 | } finally { |
| 5402 | Binder.restoreCallingIdentity(identity); |
| 5403 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5404 | } |
| 5405 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5406 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5407 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5408 | * {@link #disableIms(int)}. |
| 5409 | * @param slotIndex device slot. |
| 5410 | */ |
| 5411 | public void resetIms(int slotIndex) { |
| 5412 | enforceModifyPermission(); |
| 5413 | |
| 5414 | final long identity = Binder.clearCallingIdentity(); |
| 5415 | try { |
| 5416 | if (mImsResolver == null) { |
| 5417 | // may happen if the does not support IMS. |
| 5418 | return; |
| 5419 | } |
| 5420 | mImsResolver.disableIms(slotIndex); |
| 5421 | mImsResolver.enableIms(slotIndex); |
| 5422 | } finally { |
| 5423 | Binder.restoreCallingIdentity(identity); |
| 5424 | } |
| 5425 | } |
| 5426 | |
| 5427 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5428 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5429 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5430 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5431 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5432 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5433 | |
| 5434 | final long identity = Binder.clearCallingIdentity(); |
| 5435 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5436 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5437 | // may happen if the device does not support IMS. |
| 5438 | return; |
| 5439 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5440 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5441 | } finally { |
| 5442 | Binder.restoreCallingIdentity(identity); |
| 5443 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5444 | } |
| 5445 | |
| 5446 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5447 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5448 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5449 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5450 | public void disableIms(int slotId) { |
| 5451 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5452 | |
| 5453 | final long identity = Binder.clearCallingIdentity(); |
| 5454 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5455 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5456 | // may happen if the device does not support IMS. |
| 5457 | return; |
| 5458 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5459 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5460 | } finally { |
| 5461 | Binder.restoreCallingIdentity(identity); |
| 5462 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5463 | } |
| 5464 | |
| 5465 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5466 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5467 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5468 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5469 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5470 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5471 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5472 | |
| 5473 | final long identity = Binder.clearCallingIdentity(); |
| 5474 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5475 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5476 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5477 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5478 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5479 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5480 | } finally { |
| 5481 | Binder.restoreCallingIdentity(identity); |
| 5482 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5483 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5484 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5485 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5486 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5487 | @Override |
| 5488 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5489 | enforceModifyPermission(); |
| 5490 | |
| 5491 | final long identity = Binder.clearCallingIdentity(); |
| 5492 | try { |
| 5493 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5494 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5495 | } finally { |
| 5496 | Binder.restoreCallingIdentity(identity); |
| 5497 | } |
| 5498 | } |
| 5499 | |
| 5500 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5501 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5502 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5503 | */ |
| 5504 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5505 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5506 | |
| 5507 | final long identity = Binder.clearCallingIdentity(); |
| 5508 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5509 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5510 | // may happen if the device does not support IMS. |
| 5511 | return null; |
| 5512 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5513 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5514 | } finally { |
| 5515 | Binder.restoreCallingIdentity(identity); |
| 5516 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5517 | } |
| 5518 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5519 | /** |
| 5520 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5521 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5522 | */ |
| 5523 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5524 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5525 | |
| 5526 | final long identity = Binder.clearCallingIdentity(); |
| 5527 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5528 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5529 | // may happen if the device does not support IMS. |
| 5530 | return null; |
| 5531 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5532 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5533 | } finally { |
| 5534 | Binder.restoreCallingIdentity(identity); |
| 5535 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5536 | } |
| 5537 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5538 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5539 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5540 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5541 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5542 | * @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] | 5543 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5544 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5545 | * @param packageName The name of the package that the current configuration will be replaced |
| 5546 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5547 | * @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] | 5548 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5549 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5550 | int[] featureTypes, String packageName) { |
| 5551 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5552 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5553 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5554 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5555 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5556 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5557 | final long identity = Binder.clearCallingIdentity(); |
| 5558 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5559 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5560 | // may happen if the device does not support IMS. |
| 5561 | return false; |
| 5562 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5563 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5564 | for (int featureType : featureTypes) { |
| 5565 | featureConfig.put(featureType, packageName); |
| 5566 | } |
| 5567 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5568 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5569 | } finally { |
| 5570 | Binder.restoreCallingIdentity(identity); |
| 5571 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5572 | } |
| 5573 | |
| 5574 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5575 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5576 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5577 | * |
| 5578 | * This should only be used for testing. |
| 5579 | * |
| 5580 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5581 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5582 | */ |
| 5583 | @Override |
| 5584 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5585 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5586 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5587 | "clearCarrierImsServiceOverride"); |
| 5588 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5589 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5590 | "clearCarrierImsServiceOverride"); |
| 5591 | |
| 5592 | final long identity = Binder.clearCallingIdentity(); |
| 5593 | try { |
| 5594 | if (mImsResolver == null) { |
| 5595 | // may happen if the device does not support IMS. |
| 5596 | return false; |
| 5597 | } |
| 5598 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5599 | } finally { |
| 5600 | Binder.restoreCallingIdentity(identity); |
| 5601 | } |
| 5602 | } |
| 5603 | |
| 5604 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5605 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5606 | * |
| 5607 | * @param slotId The slot that the ImsService is associated with. |
| 5608 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5609 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5610 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5611 | * @return the package name of the ImsService configuration. |
| 5612 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5613 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5614 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5615 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5616 | TelephonyPermissions |
| 5617 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5618 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5619 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5620 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5621 | final long identity = Binder.clearCallingIdentity(); |
| 5622 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5623 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5624 | // may happen if the device does not support IMS. |
| 5625 | return ""; |
| 5626 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5627 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5628 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5629 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5630 | } finally { |
| 5631 | Binder.restoreCallingIdentity(identity); |
| 5632 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5633 | } |
| 5634 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5635 | /** |
| 5636 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5637 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5638 | * @param callback A callback with an integer containing the |
| 5639 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5640 | */ |
| 5641 | @Override |
| 5642 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5643 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5644 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5645 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5646 | "IMS not available on device."); |
| 5647 | } |
| 5648 | final long token = Binder.clearCallingIdentity(); |
| 5649 | try { |
| 5650 | int slotId = getSlotIndex(subId); |
| 5651 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5652 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5653 | + subId + "'"); |
| 5654 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5655 | } |
| 5656 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5657 | try { |
| 5658 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5659 | } catch (RemoteException e) { |
| 5660 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5661 | + "Ignore"); |
| 5662 | } |
| 5663 | }); |
| 5664 | } finally { |
| 5665 | Binder.restoreCallingIdentity(token); |
| 5666 | } |
| 5667 | } |
| 5668 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5669 | /** |
| 5670 | * Sets the ims registration state on all valid {@link Phone}s. |
| 5671 | */ |
| 5672 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5673 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5674 | |
| 5675 | final long identity = Binder.clearCallingIdentity(); |
| 5676 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5677 | // NOTE: Before S, this method only set the default phone. |
| 5678 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 5679 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 5680 | phone.setImsRegistrationState(registered); |
| 5681 | } |
| 5682 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5683 | } finally { |
| 5684 | Binder.restoreCallingIdentity(identity); |
| 5685 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5686 | } |
| 5687 | |
| 5688 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5689 | * Set the network selection mode to automatic. |
| 5690 | * |
| 5691 | */ |
| 5692 | @Override |
| 5693 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5694 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5695 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5696 | |
| 5697 | final long identity = Binder.clearCallingIdentity(); |
| 5698 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5699 | if (!isActiveSubscription(subId)) { |
| 5700 | return; |
| 5701 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5702 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 5703 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 5704 | } finally { |
| 5705 | Binder.restoreCallingIdentity(identity); |
| 5706 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5707 | } |
| 5708 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5709 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5710 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5711 | * |
| 5712 | * @param subId the id of the subscription. |
| 5713 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5714 | * the operator to attach to. |
| 5715 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5716 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5717 | * normal network selection next time. |
| 5718 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5719 | */ |
| 5720 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5721 | public boolean setNetworkSelectionModeManual( |
| 5722 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5723 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5724 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5725 | |
| 5726 | if (!isActiveSubscription(subId)) { |
| 5727 | return false; |
| 5728 | } |
| 5729 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5730 | final long identity = Binder.clearCallingIdentity(); |
| 5731 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5732 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5733 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5734 | if (DBG) { |
| 5735 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5736 | + " operator: " + operatorInfo); |
| 5737 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5738 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5739 | } finally { |
| 5740 | Binder.restoreCallingIdentity(identity); |
| 5741 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5742 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5743 | /** |
| 5744 | * Get the manual network selection |
| 5745 | * |
| 5746 | * @param subId the id of the subscription. |
| 5747 | * |
| 5748 | * @return the previously saved user selected PLMN |
| 5749 | */ |
| 5750 | @Override |
| 5751 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5752 | TelephonyPermissions |
| 5753 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5754 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5755 | |
| 5756 | final long identity = Binder.clearCallingIdentity(); |
| 5757 | try { |
| 5758 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5759 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5760 | } |
| 5761 | |
| 5762 | final Phone phone = getPhone(subId); |
| 5763 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5764 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5765 | } |
| 5766 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5767 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5768 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5769 | } finally { |
| 5770 | Binder.restoreCallingIdentity(identity); |
| 5771 | } |
| 5772 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5773 | |
| 5774 | /** |
| 5775 | * Scans for available networks. |
| 5776 | */ |
| 5777 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5778 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5779 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5780 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5781 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5782 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5783 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5784 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5785 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5786 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5787 | .setCallingPid(Binder.getCallingPid()) |
| 5788 | .setCallingUid(Binder.getCallingUid()) |
| 5789 | .setMethod("getCellNetworkScanResults") |
| 5790 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 5791 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5792 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5793 | .build()); |
| 5794 | switch (locationResult) { |
| 5795 | case DENIED_HARD: |
| 5796 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5797 | case DENIED_SOFT: |
| 5798 | return null; |
| 5799 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5800 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5801 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5802 | try { |
| 5803 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5804 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5805 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5806 | } finally { |
| 5807 | Binder.restoreCallingIdentity(identity); |
| 5808 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5809 | } |
| 5810 | |
| 5811 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5812 | * Get the call forwarding info, given the call forwarding reason. |
| 5813 | */ |
| 5814 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5815 | public void getCallForwarding(int subId, int callForwardingReason, |
| 5816 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5817 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5818 | long identity = Binder.clearCallingIdentity(); |
| 5819 | try { |
| 5820 | if (DBG) { |
| 5821 | log("getCallForwarding: subId " + subId |
| 5822 | + " callForwardingReason" + callForwardingReason); |
| 5823 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5824 | |
| 5825 | Phone phone = getPhone(subId); |
| 5826 | if (phone == null) { |
| 5827 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5828 | callback.onError( |
| 5829 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5830 | } catch (RemoteException e) { |
| 5831 | // ignore |
| 5832 | } |
| 5833 | return; |
| 5834 | } |
| 5835 | |
| 5836 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 5837 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 5838 | @Override |
| 5839 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 5840 | try { |
| 5841 | callback.onCallForwardingInfoAvailable(info); |
| 5842 | } catch (RemoteException e) { |
| 5843 | // ignore |
| 5844 | } |
| 5845 | } |
| 5846 | |
| 5847 | @Override |
| 5848 | public void onError(int error) { |
| 5849 | try { |
| 5850 | callback.onError(error); |
| 5851 | } catch (RemoteException e) { |
| 5852 | // ignore |
| 5853 | } |
| 5854 | } |
| 5855 | }); |
| 5856 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5857 | } finally { |
| 5858 | Binder.restoreCallingIdentity(identity); |
| 5859 | } |
| 5860 | } |
| 5861 | |
| 5862 | /** |
| 5863 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5864 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5865 | */ |
| 5866 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5867 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 5868 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5869 | enforceModifyPermission(); |
| 5870 | long identity = Binder.clearCallingIdentity(); |
| 5871 | try { |
| 5872 | if (DBG) { |
| 5873 | log("setCallForwarding: subId " + subId |
| 5874 | + " callForwardingInfo" + callForwardingInfo); |
| 5875 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5876 | |
| 5877 | Phone phone = getPhone(subId); |
| 5878 | if (phone == null) { |
| 5879 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5880 | callback.accept( |
| 5881 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5882 | } catch (RemoteException e) { |
| 5883 | // ignore |
| 5884 | } |
| 5885 | return; |
| 5886 | } |
| 5887 | |
| 5888 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 5889 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5890 | |
| 5891 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5892 | } finally { |
| 5893 | Binder.restoreCallingIdentity(identity); |
| 5894 | } |
| 5895 | } |
| 5896 | |
| 5897 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5898 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5899 | */ |
| 5900 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5901 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5902 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5903 | long identity = Binder.clearCallingIdentity(); |
| 5904 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5905 | |
| 5906 | Phone phone = getPhone(subId); |
| 5907 | if (phone == null) { |
| 5908 | try { |
| 5909 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5910 | } catch (RemoteException e) { |
| 5911 | // ignore |
| 5912 | } |
| 5913 | return; |
| 5914 | } |
| 5915 | |
| 5916 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 5917 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5918 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5919 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5920 | } finally { |
| 5921 | Binder.restoreCallingIdentity(identity); |
| 5922 | } |
| 5923 | } |
| 5924 | |
| 5925 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5926 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5927 | */ |
| 5928 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5929 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5930 | enforceModifyPermission(); |
| 5931 | long identity = Binder.clearCallingIdentity(); |
| 5932 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5933 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 5934 | |
| 5935 | Phone phone = getPhone(subId); |
| 5936 | if (phone == null) { |
| 5937 | try { |
| 5938 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5939 | } catch (RemoteException e) { |
| 5940 | // ignore |
| 5941 | } |
| 5942 | return; |
| 5943 | } |
| 5944 | |
| 5945 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 5946 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5947 | |
| 5948 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5949 | } finally { |
| 5950 | Binder.restoreCallingIdentity(identity); |
| 5951 | } |
| 5952 | } |
| 5953 | |
| 5954 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5955 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5956 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5957 | * @param subId id of the subscription |
| 5958 | * @param request contains the radio access networks with bands/channels to scan |
| 5959 | * @param messenger callback messenger for scan results or errors |
| 5960 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5961 | * @return the id of the requested scan which can be used to stop the scan. |
| 5962 | */ |
| 5963 | @Override |
| 5964 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5965 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5966 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5967 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5968 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5969 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5970 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5971 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5972 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5973 | .setCallingPid(Binder.getCallingPid()) |
| 5974 | .setCallingUid(Binder.getCallingUid()) |
| 5975 | .setMethod("requestNetworkScan") |
| 5976 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
James.cf Lin | 1d4d739 | 2020-07-03 18:22:53 +0800 | [diff] [blame] | 5977 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5978 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5979 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5980 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5981 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 5982 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5983 | if (e != null) { |
| 5984 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5985 | throw e; |
| 5986 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5987 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5988 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5989 | } |
| 5990 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5991 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5992 | int callingUid = Binder.getCallingUid(); |
| 5993 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5994 | final long identity = Binder.clearCallingIdentity(); |
| 5995 | try { |
| 5996 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5997 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5998 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5999 | } finally { |
| 6000 | Binder.restoreCallingIdentity(identity); |
| 6001 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6002 | } |
| 6003 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6004 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 6005 | NetworkScanRequest request, int subId, String callingPackage) { |
| 6006 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 6007 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6008 | boolean hasNetworkScanPermission = |
| 6009 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 6010 | == PERMISSION_GRANTED; |
| 6011 | |
| 6012 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 6013 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 6014 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6015 | } |
| 6016 | |
| 6017 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 6018 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6019 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 6020 | return new SecurityException("Specific channels must not be" |
| 6021 | + " scanned without location access."); |
| 6022 | } |
| 6023 | } |
| 6024 | } |
| 6025 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 6026 | return null; |
| 6027 | } |
| 6028 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6029 | /** |
| 6030 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 6031 | * |
| 6032 | * @param subId id of the subscription |
| 6033 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6034 | */ |
| 6035 | @Override |
| 6036 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6037 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6038 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6039 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6040 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6041 | final long identity = Binder.clearCallingIdentity(); |
| 6042 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6043 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6044 | } finally { |
| 6045 | Binder.restoreCallingIdentity(identity); |
| 6046 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6047 | } |
| 6048 | |
| 6049 | /** |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6050 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6051 | * |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6052 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6053 | */ |
| 6054 | @Override |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6055 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6056 | TelephonyPermissions |
| 6057 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6058 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6059 | |
| 6060 | final long identity = Binder.clearCallingIdentity(); |
| 6061 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6062 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6063 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6064 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6065 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6066 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6067 | } finally { |
| 6068 | Binder.restoreCallingIdentity(identity); |
| 6069 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6070 | } |
| 6071 | |
| 6072 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6073 | * Get the allowed network types for certain reason. |
| 6074 | * |
| 6075 | * @param subId the id of the subscription. |
| 6076 | * @param reason the reason the allowed network type change is taking place |
| 6077 | * @return the allowed network types. |
| 6078 | */ |
| 6079 | @Override |
| 6080 | public long getAllowedNetworkTypesForReason(int subId, |
| 6081 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
| 6082 | TelephonyPermissions |
| 6083 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6084 | mApp, subId, "getAllowedNetworkTypesForReason"); |
| 6085 | final long identity = Binder.clearCallingIdentity(); |
| 6086 | try { |
| 6087 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6088 | } finally { |
| 6089 | Binder.restoreCallingIdentity(identity); |
| 6090 | } |
| 6091 | } |
| 6092 | |
| 6093 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6094 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6095 | * @param subId subscription id of the sim card |
| 6096 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6097 | * This can be passed following states |
| 6098 | * <ol> |
| 6099 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6100 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6101 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6102 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6103 | * </ol> |
| 6104 | * @return operation result. |
| 6105 | */ |
| 6106 | @Override |
| 6107 | public int setNrDualConnectivityState(int subId, |
| 6108 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6109 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6110 | mApp, subId, "enableNRDualConnectivity"); |
| 6111 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6112 | final long identity = Binder.clearCallingIdentity(); |
| 6113 | try { |
| 6114 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6115 | nrDualConnectivityState, subId, |
| 6116 | workSource); |
| 6117 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6118 | return result; |
| 6119 | } finally { |
| 6120 | Binder.restoreCallingIdentity(identity); |
| 6121 | } |
| 6122 | } |
| 6123 | |
| 6124 | /** |
| 6125 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6126 | * @return true if dual connectivity is enabled else false |
| 6127 | */ |
| 6128 | @Override |
| 6129 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6130 | TelephonyPermissions |
| 6131 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6132 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6133 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6134 | final long identity = Binder.clearCallingIdentity(); |
| 6135 | try { |
| 6136 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6137 | null, subId, workSource); |
| 6138 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6139 | return isEnabled; |
| 6140 | } finally { |
| 6141 | Binder.restoreCallingIdentity(identity); |
| 6142 | } |
| 6143 | } |
| 6144 | |
| 6145 | /** |
Sooraj Sasindran | 4deb887 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 6146 | * get carrier bandwidth per primary and secondary carrier |
| 6147 | * @param subId subscription id of the sim card |
| 6148 | * @return CarrierBandwidth with bandwidth of both primary and secondary carrier.. |
| 6149 | */ |
| 6150 | @Override |
| 6151 | public CarrierBandwidth getCarrierBandwidth(int subId) { |
| 6152 | TelephonyPermissions |
| 6153 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6154 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6155 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6156 | final long identity = Binder.clearCallingIdentity(); |
| 6157 | try { |
| 6158 | CarrierBandwidth carrierBandwidth = |
| 6159 | getPhoneFromSubId(subId).getCarrierBandwidth(); |
| 6160 | if (DBG) log("getCarrierBandwidth: " + carrierBandwidth); |
| 6161 | return carrierBandwidth; |
| 6162 | } finally { |
| 6163 | Binder.restoreCallingIdentity(identity); |
| 6164 | } |
| 6165 | } |
| 6166 | |
| 6167 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6168 | * Set the allowed network types of the device and |
| 6169 | * provide the reason triggering the allowed network change. |
| 6170 | * |
| 6171 | * @param subId the id of the subscription. |
| 6172 | * @param reason the reason the allowed network type change is taking place |
| 6173 | * @param allowedNetworkTypes the allowed network types. |
| 6174 | * @return true on success; false on any failure. |
| 6175 | */ |
| 6176 | @Override |
| 6177 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6178 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6179 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6180 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6181 | mApp, subId, "setAllowedNetworkTypesForReason"); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6182 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
| 6183 | Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason); |
| 6184 | return false; |
| 6185 | } |
| 6186 | |
| 6187 | if (DBG) { |
| 6188 | log("setAllowedNetworkTypesForReason: " + reason |
| 6189 | + " value: " + allowedNetworkTypes); |
| 6190 | } |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6191 | final long identity = Binder.clearCallingIdentity(); |
| 6192 | try { |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 6193 | Boolean success = (Boolean) sendRequest( |
| 6194 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6195 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6196 | |
| 6197 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6198 | return success; |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6199 | } finally { |
| 6200 | Binder.restoreCallingIdentity(identity); |
| 6201 | } |
| 6202 | } |
| 6203 | |
| 6204 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6205 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6206 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6207 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6208 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6209 | * @hide |
| 6210 | */ |
| 6211 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6212 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6213 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6214 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6215 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6216 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6217 | if (phone != null) { |
| 6218 | return phone.hasMatchedTetherApnSetting(); |
| 6219 | } else { |
| 6220 | return false; |
| 6221 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6222 | } finally { |
| 6223 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6224 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6225 | } |
| 6226 | |
| 6227 | /** |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6228 | * Enable or disable always reporting signal strength changes from radio. |
| 6229 | * |
| 6230 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 6231 | */ |
| 6232 | @Override |
| 6233 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 6234 | enforceModifyPermission(); |
| 6235 | enforceSystemCaller(); |
| 6236 | |
| 6237 | final long identity = Binder.clearCallingIdentity(); |
| 6238 | final Phone phone = getPhone(subId); |
| 6239 | try { |
| 6240 | if (phone != null) { |
| 6241 | if (DBG) { |
| 6242 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6243 | + " isEnable=" + isEnable); |
| 6244 | } |
| 6245 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6246 | } else { |
| 6247 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6248 | + subId); |
| 6249 | } |
| 6250 | } finally { |
| 6251 | Binder.restoreCallingIdentity(identity); |
| 6252 | } |
| 6253 | } |
| 6254 | |
| 6255 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6256 | * Get the user enabled state of Mobile Data. |
| 6257 | * |
| 6258 | * TODO: remove and use isUserDataEnabled. |
| 6259 | * This can't be removed now because some vendor codes |
| 6260 | * calls through ITelephony directly while they should |
| 6261 | * use TelephonyManager. |
| 6262 | * |
| 6263 | * @return true on enabled |
| 6264 | */ |
| 6265 | @Override |
| 6266 | public boolean getDataEnabled(int subId) { |
| 6267 | return isUserDataEnabled(subId); |
| 6268 | } |
| 6269 | |
| 6270 | /** |
| 6271 | * Get whether mobile data is enabled per user setting. |
| 6272 | * |
| 6273 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6274 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6275 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6276 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6277 | * |
| 6278 | * @return {@code true} if data is enabled else {@code false} |
| 6279 | */ |
| 6280 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6281 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6282 | try { |
| 6283 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6284 | null); |
| 6285 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6286 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6287 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6288 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6289 | |
| 6290 | final long identity = Binder.clearCallingIdentity(); |
| 6291 | try { |
| 6292 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6293 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6294 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6295 | if (phone != null) { |
| 6296 | boolean retVal = phone.isUserDataEnabled(); |
| 6297 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6298 | return retVal; |
| 6299 | } else { |
| 6300 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6301 | return false; |
| 6302 | } |
| 6303 | } finally { |
| 6304 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6305 | } |
| 6306 | } |
| 6307 | |
| 6308 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6309 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6310 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6311 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6312 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6313 | * @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] | 6314 | */ |
| 6315 | @Override |
| 6316 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6317 | try { |
| 6318 | try { |
| 6319 | mApp.enforceCallingOrSelfPermission( |
| 6320 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6321 | null); |
| 6322 | } catch (Exception e) { |
| 6323 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6324 | "isDataEnabled"); |
| 6325 | } |
| 6326 | } catch (Exception e) { |
| 6327 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6328 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6329 | |
| 6330 | final long identity = Binder.clearCallingIdentity(); |
| 6331 | try { |
| 6332 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6333 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6334 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6335 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6336 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6337 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6338 | return retVal; |
| 6339 | } else { |
| 6340 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6341 | return false; |
| 6342 | } |
| 6343 | } finally { |
| 6344 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6345 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6346 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6347 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6348 | /** |
| 6349 | * Check if data is enabled for a specific reason |
| 6350 | * @param subId Subscription index |
| 6351 | * @param reason the reason the data enable change is taking place |
| 6352 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6353 | */ |
| 6354 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6355 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6356 | @TelephonyManager.DataEnabledReason int reason) { |
| 6357 | try { |
| 6358 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6359 | null); |
| 6360 | } catch (Exception e) { |
| 6361 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6362 | "isDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6363 | } |
| 6364 | |
| 6365 | |
| 6366 | final long identity = Binder.clearCallingIdentity(); |
| 6367 | try { |
| 6368 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6369 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6370 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6371 | + " reason=" + reason); |
| 6372 | } |
| 6373 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6374 | if (phone != null) { |
| 6375 | boolean retVal; |
| 6376 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6377 | retVal = phone.isUserDataEnabled(); |
| 6378 | } else { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6379 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6380 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6381 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6382 | return retVal; |
| 6383 | } else { |
| 6384 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6385 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6386 | + subId + " retVal=false"); |
| 6387 | } |
| 6388 | return false; |
| 6389 | } |
| 6390 | } finally { |
| 6391 | Binder.restoreCallingIdentity(identity); |
| 6392 | } |
| 6393 | } |
| 6394 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6395 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6396 | Phone phone) { |
Hall Liu | 54a2a0c | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 6397 | if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) { |
| 6398 | // Skip the check if it's one of these special uids |
| 6399 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6400 | } |
| 6401 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6402 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6403 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6404 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6405 | || subController == null) return privilegeFromSim; |
| 6406 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6407 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6408 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6409 | |
| 6410 | final long identity = Binder.clearCallingIdentity(); |
| 6411 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6412 | int subId = phone.getSubId(); |
| 6413 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6414 | // A test override is in place for the privileges for this subId, so don't try to |
| 6415 | // read the subscription privileges. |
| 6416 | return privilegeFromSim; |
| 6417 | } |
| 6418 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6419 | SubscriptionManager subManager = (SubscriptionManager) |
| 6420 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6421 | for (String pkg : packages) { |
| 6422 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6423 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6424 | } |
| 6425 | } |
| 6426 | return privilegeFromSim; |
| 6427 | } finally { |
| 6428 | Binder.restoreCallingIdentity(identity); |
| 6429 | } |
| 6430 | } |
| 6431 | |
| 6432 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6433 | String pkgName) { |
| 6434 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6435 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6436 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6437 | || subController == null) return privilegeFromSim; |
| 6438 | |
| 6439 | final long identity = Binder.clearCallingIdentity(); |
| 6440 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6441 | int subId = phone.getSubId(); |
| 6442 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6443 | // A test override is in place for the privileges for this subId, so don't try to |
| 6444 | // read the subscription privileges. |
| 6445 | return privilegeFromSim; |
| 6446 | } |
| 6447 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6448 | SubscriptionManager subManager = (SubscriptionManager) |
| 6449 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6450 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6451 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6452 | } finally { |
| 6453 | Binder.restoreCallingIdentity(identity); |
| 6454 | } |
| 6455 | } |
| 6456 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6457 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6458 | public int getCarrierPrivilegeStatus(int subId) { |
| 6459 | final Phone phone = getPhone(subId); |
| 6460 | if (phone == null) { |
| 6461 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6462 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6463 | } |
| 6464 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6465 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6466 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6467 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6468 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6469 | |
| 6470 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6471 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6472 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6473 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6474 | |
| 6475 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6476 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6477 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6478 | final Phone phone = getPhone(subId); |
| 6479 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6480 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6481 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6482 | } |
| 6483 | UiccProfile profile = |
| 6484 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6485 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6486 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6487 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6488 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6489 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6490 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6491 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6492 | } |
| 6493 | |
| 6494 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6495 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 6496 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6497 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6498 | } |
| 6499 | |
| 6500 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 6501 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6502 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6503 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6504 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6505 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6506 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6507 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6508 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6509 | } |
| 6510 | |
| 6511 | @Override |
| 6512 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6513 | if (TextUtils.isEmpty(pkgName)) |
| 6514 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6515 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6516 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6517 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 6518 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6519 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6520 | continue; |
| 6521 | } |
| 6522 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6523 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6524 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6525 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6526 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6527 | break; |
| 6528 | } |
| 6529 | } |
| 6530 | |
| 6531 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6532 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6533 | |
| 6534 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6535 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 6536 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6537 | loge("phoneId " + phoneId + " is not valid."); |
| 6538 | return null; |
| 6539 | } |
| 6540 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6541 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6542 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6543 | return null ; |
| 6544 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6545 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6546 | } |
| 6547 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6548 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6549 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6550 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6551 | List<String> privilegedPackages = new ArrayList<>(); |
| 6552 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6553 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 6554 | // has UICC in that slot. |
| 6555 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6556 | if (card.hasCarrierPrivilegeRules()) { |
| 6557 | if (packages == null) { |
| 6558 | // Only check packages in user 0 for now |
| 6559 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6560 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6561 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6562 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6563 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6564 | } |
| 6565 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6566 | PackageInfo pkgInfo = packages.get(p); |
| 6567 | if (pkgInfo != null && pkgInfo.packageName != null |
| 6568 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6569 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6570 | privilegedPackages.add(pkgInfo.packageName); |
| 6571 | } |
| 6572 | } |
| 6573 | } |
| 6574 | } |
| 6575 | return privilegedPackages; |
| 6576 | } |
| 6577 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6578 | @Override |
| 6579 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6580 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6581 | |
| 6582 | final long identity = Binder.clearCallingIdentity(); |
| 6583 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6584 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6585 | try { |
| 6586 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6587 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6588 | } |
| 6589 | } finally { |
| 6590 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6591 | } |
| 6592 | return privilegedPackages; |
| 6593 | } |
| 6594 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6595 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6596 | final Phone phone = getPhone(subId); |
| 6597 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6598 | if (card == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6599 | return null; |
| 6600 | } |
| 6601 | String iccId = card.getIccId(); |
| 6602 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6603 | return null; |
| 6604 | } |
| 6605 | return iccId; |
| 6606 | } |
| 6607 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6608 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6609 | public void setCallComposerStatus(int subId, int status) { |
| 6610 | enforceModifyPermission(); |
| 6611 | |
| 6612 | final long identity = Binder.clearCallingIdentity(); |
| 6613 | try { |
| 6614 | Phone phone = getPhone(subId); |
| 6615 | if (phone != null) { |
| 6616 | Phone defaultPhone = phone.getImsPhone(); |
| 6617 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6618 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6619 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6620 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6621 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6622 | } |
| 6623 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6624 | } catch (ImsException e) { |
| 6625 | throw new ServiceSpecificException(e.getCode()); |
| 6626 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6627 | Binder.restoreCallingIdentity(identity); |
| 6628 | } |
| 6629 | } |
| 6630 | |
| 6631 | @Override |
| 6632 | public int getCallComposerStatus(int subId) { |
| 6633 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 6634 | |
| 6635 | final long identity = Binder.clearCallingIdentity(); |
| 6636 | try { |
| 6637 | Phone phone = getPhone(subId); |
| 6638 | if (phone != null) { |
| 6639 | Phone defaultPhone = phone.getImsPhone(); |
| 6640 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6641 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6642 | return imsPhone.getCallComposerStatus(); |
| 6643 | } |
| 6644 | } |
| 6645 | } finally { |
| 6646 | Binder.restoreCallingIdentity(identity); |
| 6647 | } |
| 6648 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 6649 | } |
| 6650 | |
| 6651 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6652 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6653 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6654 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6655 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6656 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6657 | final long identity = Binder.clearCallingIdentity(); |
| 6658 | try { |
| 6659 | final String iccId = getIccId(subId); |
| 6660 | final Phone phone = getPhone(subId); |
| 6661 | if (phone == null) { |
| 6662 | return false; |
| 6663 | } |
| 6664 | final String subscriberId = phone.getSubscriberId(); |
| 6665 | |
| 6666 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6667 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6668 | + subscriberId + " to " + number); |
| 6669 | } |
| 6670 | |
| 6671 | if (TextUtils.isEmpty(iccId)) { |
| 6672 | return false; |
| 6673 | } |
| 6674 | |
| 6675 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6676 | |
| 6677 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6678 | if (alphaTag == null) { |
| 6679 | editor.remove(alphaTagPrefKey); |
| 6680 | } else { |
| 6681 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6682 | } |
| 6683 | |
| 6684 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6685 | // track all merged IMSIs based on line number |
| 6686 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6687 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6688 | if (number == null) { |
| 6689 | editor.remove(numberPrefKey); |
| 6690 | editor.remove(subscriberPrefKey); |
| 6691 | } else { |
| 6692 | editor.putString(numberPrefKey, number); |
| 6693 | editor.putString(subscriberPrefKey, subscriberId); |
| 6694 | } |
| 6695 | |
| 6696 | editor.commit(); |
| 6697 | return true; |
| 6698 | } finally { |
| 6699 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6700 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6701 | } |
| 6702 | |
| 6703 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6704 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6705 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6706 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6707 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6708 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6709 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6710 | return null; |
| 6711 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6712 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6713 | final long identity = Binder.clearCallingIdentity(); |
| 6714 | try { |
| 6715 | String iccId = getIccId(subId); |
| 6716 | if (iccId != null) { |
| 6717 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6718 | if (DBG_MERGE) { |
| 6719 | log("getLine1NumberForDisplay returning " |
| 6720 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6721 | } |
| 6722 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6723 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6724 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6725 | return null; |
| 6726 | } finally { |
| 6727 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6728 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6729 | } |
| 6730 | |
| 6731 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6732 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6733 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6734 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6735 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6736 | return null; |
| 6737 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6738 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6739 | final long identity = Binder.clearCallingIdentity(); |
| 6740 | try { |
| 6741 | String iccId = getIccId(subId); |
| 6742 | if (iccId != null) { |
| 6743 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6744 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6745 | } |
| 6746 | return null; |
| 6747 | } finally { |
| 6748 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6749 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6750 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6751 | |
| 6752 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6753 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6754 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6755 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6756 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6757 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6758 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6759 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6760 | return null; |
| 6761 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6762 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6763 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6764 | // the process, where TelephonyManager was instantiated. |
| 6765 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6766 | final long identity = Binder.clearCallingIdentity(); |
| 6767 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6768 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6769 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6770 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6771 | |
| 6772 | // Figure out what subscribers are currently active |
| 6773 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6774 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6775 | // Only consider subs which match the current subId |
| 6776 | // This logic can be simplified. See b/131189269 for progress. |
| 6777 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6778 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6779 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6780 | |
| 6781 | // First pass, find a number override for an active subscriber |
| 6782 | String mergeNumber = null; |
| 6783 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6784 | for (String key : prefs.keySet()) { |
| 6785 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6786 | final String subscriberId = (String) prefs.get(key); |
| 6787 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6788 | final String iccId = key.substring( |
| 6789 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6790 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6791 | mergeNumber = (String) prefs.get(numberKey); |
| 6792 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6793 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6794 | + " for active subscriber " + subscriberId); |
| 6795 | } |
| 6796 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6797 | break; |
| 6798 | } |
| 6799 | } |
| 6800 | } |
| 6801 | } |
| 6802 | |
| 6803 | // Shortcut when no active merged subscribers |
| 6804 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6805 | return null; |
| 6806 | } |
| 6807 | |
| 6808 | // Second pass, find all subscribers under that line override |
| 6809 | final ArraySet<String> result = new ArraySet<>(); |
| 6810 | for (String key : prefs.keySet()) { |
| 6811 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6812 | final String number = (String) prefs.get(key); |
| 6813 | if (mergeNumber.equals(number)) { |
| 6814 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6815 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6816 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6817 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6818 | result.add(subscriberId); |
| 6819 | } |
| 6820 | } |
| 6821 | } |
| 6822 | } |
| 6823 | |
| 6824 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6825 | Arrays.sort(resultArray); |
| 6826 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6827 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6828 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6829 | } |
| 6830 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6831 | } finally { |
| 6832 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6833 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6834 | } |
| 6835 | |
| 6836 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6837 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6838 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6839 | |
| 6840 | final long identity = Binder.clearCallingIdentity(); |
| 6841 | try { |
| 6842 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6843 | TelephonyManager.class); |
| 6844 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6845 | if (subscriberId == null) { |
| 6846 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6847 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6848 | + subId); |
| 6849 | } |
| 6850 | return null; |
| 6851 | } |
| 6852 | |
| 6853 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6854 | .getSubscriptionInfo(subId); |
| 6855 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6856 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6857 | if (groupUuid == null) { |
| 6858 | return new String[]{subscriberId}; |
| 6859 | } |
| 6860 | |
| 6861 | // Get all subscriberIds from the group. |
| 6862 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6863 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6864 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6865 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6866 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6867 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6868 | if (subscriberId != null) { |
| 6869 | mergedSubscriberIds.add(subscriberId); |
| 6870 | } |
| 6871 | } |
| 6872 | |
| 6873 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6874 | } finally { |
| 6875 | Binder.restoreCallingIdentity(identity); |
| 6876 | |
| 6877 | } |
| 6878 | } |
| 6879 | |
| 6880 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6881 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6882 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6883 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6884 | |
| 6885 | final long identity = Binder.clearCallingIdentity(); |
| 6886 | try { |
| 6887 | final Phone phone = getPhone(subId); |
| 6888 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6889 | } finally { |
| 6890 | Binder.restoreCallingIdentity(identity); |
| 6891 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6892 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6893 | |
| 6894 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6895 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6896 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6897 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6898 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6899 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6900 | |
| 6901 | final long identity = Binder.clearCallingIdentity(); |
| 6902 | try { |
| 6903 | final Phone phone = getPhone(subId); |
| 6904 | if (phone == null) { |
| 6905 | return false; |
| 6906 | } |
| 6907 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6908 | cdmaNonRoamingList); |
| 6909 | } finally { |
| 6910 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6911 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6912 | } |
| 6913 | |
| 6914 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6915 | @Deprecated |
| 6916 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6917 | enforceModifyPermission(); |
| 6918 | |
| 6919 | int returnValue = 0; |
| 6920 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6921 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6922 | if(result.exception == null) { |
| 6923 | if (result.result != null) { |
| 6924 | byte[] responseData = (byte[])(result.result); |
| 6925 | if(responseData.length > oemResp.length) { |
| 6926 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6927 | responseData.length + "bytes. Buffer Size is " + |
| 6928 | oemResp.length + "bytes."); |
| 6929 | } |
| 6930 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6931 | returnValue = responseData.length; |
| 6932 | } |
| 6933 | } else { |
| 6934 | CommandException ex = (CommandException) result.exception; |
| 6935 | returnValue = ex.getCommandError().ordinal(); |
| 6936 | if(returnValue > 0) returnValue *= -1; |
| 6937 | } |
| 6938 | } catch (RuntimeException e) { |
| 6939 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6940 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6941 | if(returnValue > 0) returnValue *= -1; |
| 6942 | } |
| 6943 | |
| 6944 | return returnValue; |
| 6945 | } |
| 6946 | |
| 6947 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6948 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6949 | try { |
| 6950 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6951 | } catch (RuntimeException e) { |
| 6952 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6953 | } |
| 6954 | } |
| 6955 | |
| 6956 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6957 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6958 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 6959 | try { |
| 6960 | TelephonyPermissions |
| 6961 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6962 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6963 | } catch (SecurityException e) { |
| 6964 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 6965 | throw e; |
| 6966 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6967 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6968 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6969 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6970 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6971 | final long identity = Binder.clearCallingIdentity(); |
| 6972 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6973 | TelephonyPermissions |
| 6974 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6975 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6976 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6977 | } finally { |
| 6978 | Binder.restoreCallingIdentity(identity); |
| 6979 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6980 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6981 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6982 | |
| 6983 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 6984 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
Hall Liu | e31bac6 | 2020-12-23 19:16:10 -0800 | [diff] [blame] | 6985 | String contentType, ParcelFileDescriptor fd, ResultReceiver callback) { |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 6986 | try { |
| 6987 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 6988 | Binder.getCallingUid())) { |
| 6989 | throw new SecurityException("Package uid and package name do not match: " |
| 6990 | + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage); |
| 6991 | } |
| 6992 | } catch (PackageManager.NameNotFoundException e) { |
| 6993 | throw new SecurityException("Package name invalid:" + callingPackage); |
| 6994 | } |
| 6995 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 6996 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 6997 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 6998 | throw new SecurityException("App must be the dialer role holder to" |
| 6999 | + " upload a call composer pic"); |
| 7000 | } |
| 7001 | |
| 7002 | Executors.newSingleThreadExecutor().execute(() -> { |
| 7003 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 7004 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 7005 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 7006 | boolean readUntilEnd = false; |
| 7007 | int totalBytesRead = 0; |
| 7008 | byte[] buffer = new byte[16 * 1024]; |
| 7009 | while (true) { |
| 7010 | int numRead; |
| 7011 | try { |
| 7012 | numRead = input.read(buffer); |
| 7013 | } catch (IOException e) { |
| 7014 | try { |
| 7015 | fd.checkError(); |
| 7016 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 7017 | null); |
| 7018 | } catch (IOException e1) { |
| 7019 | // This means that the other side closed explicitly with an error. If this |
| 7020 | // happens, log and ignore. |
| 7021 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 7022 | } |
| 7023 | break; |
| 7024 | } |
| 7025 | if (numRead == -1) { |
| 7026 | readUntilEnd = true; |
| 7027 | break; |
| 7028 | } |
| 7029 | totalBytesRead += numRead; |
| 7030 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 7031 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 7032 | try { |
| 7033 | input.close(); |
| 7034 | } catch (IOException e) { |
| 7035 | // ignore |
| 7036 | } |
| 7037 | break; |
| 7038 | } |
| 7039 | output.write(buffer, 0, numRead); |
| 7040 | } |
| 7041 | // Generally, the remote end will close the file descriptors. The only case where we |
| 7042 | // close is above, where the picture size is too big. |
| 7043 | |
| 7044 | try { |
| 7045 | fd.checkError(); |
| 7046 | } catch (IOException e) { |
| 7047 | loge("Remote end for call composer closed with an error: " + e); |
| 7048 | return; |
| 7049 | } |
| 7050 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7051 | if (!readUntilEnd) { |
| 7052 | loge("Did not finish reading entire image; aborting"); |
| 7053 | return; |
| 7054 | } |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7055 | |
Hall Liu | aa4211e | 2021-01-20 15:43:39 -0800 | [diff] [blame] | 7056 | ImageData imageData = new ImageData(output.toByteArray(), contentType, null); |
| 7057 | CallComposerPictureManager.getInstance(mApp, subscriptionId).handleUploadToServer( |
| 7058 | new CallComposerPictureTransfer.Factory() {}, |
| 7059 | imageData, |
| 7060 | (result) -> { |
| 7061 | if (result.first != null) { |
| 7062 | ParcelUuid parcelUuid = new ParcelUuid(result.first); |
| 7063 | Bundle outputResult = new Bundle(); |
| 7064 | outputResult.putParcelable( |
| 7065 | TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, parcelUuid); |
| 7066 | callback.send(TelephonyManager.CallComposerException.SUCCESS, |
| 7067 | outputResult); |
| 7068 | } else { |
| 7069 | callback.send(result.second, null); |
| 7070 | } |
| 7071 | } |
| 7072 | ); |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame] | 7073 | }); |
| 7074 | } |
| 7075 | |
| 7076 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7077 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7078 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7079 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7080 | |
| 7081 | final long identity = Binder.clearCallingIdentity(); |
| 7082 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7083 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7084 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7085 | } finally { |
| 7086 | Binder.restoreCallingIdentity(identity); |
| 7087 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7088 | } |
| 7089 | |
| 7090 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7091 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7092 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7093 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7094 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7095 | return false; |
| 7096 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7097 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7098 | final long identity = Binder.clearCallingIdentity(); |
| 7099 | try { |
| 7100 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7101 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7102 | // In the long run, we may instead need to check if there exists a connection service |
| 7103 | // which can support video calling. |
| 7104 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7105 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7106 | return imsManager.isVtEnabledByPlatform() |
| 7107 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7108 | && imsManager.isVtEnabledByUser(); |
| 7109 | } finally { |
| 7110 | Binder.restoreCallingIdentity(identity); |
| 7111 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7112 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7113 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7114 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7115 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7116 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7117 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7118 | mApp, subId, callingPackage, callingFeatureId, |
| 7119 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7120 | return false; |
| 7121 | } |
| 7122 | |
| 7123 | final long identity = Binder.clearCallingIdentity(); |
| 7124 | try { |
| 7125 | CarrierConfigManager configManager = |
| 7126 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7127 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7128 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7129 | } finally { |
| 7130 | Binder.restoreCallingIdentity(identity); |
| 7131 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7132 | } |
| 7133 | |
| 7134 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7135 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7136 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7137 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7138 | return false; |
| 7139 | } |
| 7140 | |
| 7141 | final long identity = Binder.clearCallingIdentity(); |
| 7142 | try { |
| 7143 | CarrierConfigManager configManager = |
| 7144 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7145 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7146 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7147 | } finally { |
| 7148 | Binder.restoreCallingIdentity(identity); |
| 7149 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7150 | } |
| 7151 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7152 | @Override |
| 7153 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7154 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7155 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7156 | } |
| 7157 | |
| 7158 | @Override |
| 7159 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7160 | final long identity = Binder.clearCallingIdentity(); |
| 7161 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7162 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7163 | } finally { |
| 7164 | Binder.restoreCallingIdentity(identity); |
| 7165 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7166 | } |
| 7167 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7168 | /** |
| 7169 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7170 | * support for the feature and device firmware support. |
| 7171 | * |
| 7172 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7173 | */ |
| 7174 | @Override |
| 7175 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7176 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7177 | final Phone phone = getPhone(subscriptionId); |
| 7178 | if (phone == null) { |
| 7179 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7180 | return false; |
| 7181 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7182 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7183 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7184 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7185 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7186 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7187 | return isCarrierSupported && isDeviceSupported; |
| 7188 | } finally { |
| 7189 | Binder.restoreCallingIdentity(identity); |
| 7190 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7191 | } |
| 7192 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7193 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7194 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7195 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7196 | * 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] | 7197 | */ |
| 7198 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7199 | final long identity = Binder.clearCallingIdentity(); |
| 7200 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7201 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7202 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7203 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7204 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7205 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7206 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7207 | } finally { |
| 7208 | Binder.restoreCallingIdentity(identity); |
| 7209 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7210 | } |
| 7211 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7212 | @Deprecated |
| 7213 | @Override |
| 7214 | public String getDeviceId(String callingPackage) { |
| 7215 | return getDeviceIdWithFeature(callingPackage, null); |
| 7216 | } |
| 7217 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7218 | /** |
| 7219 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7220 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7221 | * |
| 7222 | * <p>Requires Permission: |
| 7223 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7224 | */ |
| 7225 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7226 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7227 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7228 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7229 | return null; |
| 7230 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7231 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7232 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7233 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7234 | return null; |
| 7235 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7236 | |
| 7237 | final long identity = Binder.clearCallingIdentity(); |
| 7238 | try { |
| 7239 | return phone.getDeviceId(); |
| 7240 | } finally { |
| 7241 | Binder.restoreCallingIdentity(identity); |
| 7242 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7243 | } |
| 7244 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7245 | /** |
| 7246 | * {@hide} |
| 7247 | * Returns the IMS Registration Status on a particular subid |
| 7248 | * |
| 7249 | * @param subId |
| 7250 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7251 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7252 | Phone phone = getPhone(subId); |
| 7253 | if (phone != null) { |
| 7254 | return phone.isImsRegistered(); |
| 7255 | } else { |
| 7256 | return false; |
| 7257 | } |
| 7258 | } |
| 7259 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7260 | @Override |
| 7261 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7262 | final long identity = Binder.clearCallingIdentity(); |
| 7263 | try { |
| 7264 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 7265 | } finally { |
| 7266 | Binder.restoreCallingIdentity(identity); |
| 7267 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7268 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 7269 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7270 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7271 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7272 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7273 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7274 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7275 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7276 | } |
| 7277 | final long identity = Binder.clearCallingIdentity(); |
| 7278 | try { |
| 7279 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7280 | } finally { |
| 7281 | Binder.restoreCallingIdentity(identity); |
| 7282 | } |
| 7283 | } |
| 7284 | |
| 7285 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7286 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
duki.hong | fd96bde | 2020-07-22 17:32:19 +0900 | [diff] [blame] | 7287 | enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, " |
| 7288 | + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7289 | final long identity = Binder.clearCallingIdentity(); |
| 7290 | try { |
| 7291 | Phone phone = getPhone(subscriptionId); |
| 7292 | if (phone == null) { |
| 7293 | return null; |
| 7294 | } |
| 7295 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7296 | } finally { |
| 7297 | Binder.restoreCallingIdentity(identity); |
| 7298 | } |
| 7299 | } |
| 7300 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7301 | /** |
| 7302 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7303 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7304 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7305 | final long identity = Binder.clearCallingIdentity(); |
| 7306 | try { |
| 7307 | Phone phone = getPhone(subId); |
| 7308 | if (phone != null) { |
| 7309 | return phone.isWifiCallingEnabled(); |
| 7310 | } else { |
| 7311 | return false; |
| 7312 | } |
| 7313 | } finally { |
| 7314 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7315 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7316 | } |
| 7317 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7318 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7319 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7320 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7321 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7322 | final long identity = Binder.clearCallingIdentity(); |
| 7323 | try { |
| 7324 | Phone phone = getPhone(subId); |
| 7325 | if (phone != null) { |
| 7326 | return phone.isVideoEnabled(); |
| 7327 | } else { |
| 7328 | return false; |
| 7329 | } |
| 7330 | } finally { |
| 7331 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7332 | } |
| 7333 | } |
| 7334 | |
| 7335 | /** |
| 7336 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7337 | * defined in {@link ImsRegistrationImplBase}. |
| 7338 | */ |
| 7339 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7340 | final long identity = Binder.clearCallingIdentity(); |
| 7341 | try { |
| 7342 | Phone phone = getPhone(subId); |
| 7343 | if (phone != null) { |
| 7344 | return phone.getImsRegistrationTech(); |
| 7345 | } else { |
| 7346 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7347 | } |
| 7348 | } finally { |
| 7349 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7350 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7351 | } |
| 7352 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7353 | @Override |
| 7354 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7355 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7356 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7357 | return; |
| 7358 | } |
| 7359 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7360 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7361 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7362 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7363 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7364 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7365 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7366 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7367 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 3ef3e07 | 2020-12-21 16:41:52 +0800 | [diff] [blame] | 7368 | setAllowedNetworkTypesForReason(subId, |
| 7369 | TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7370 | RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId))); |
| 7371 | setAllowedNetworkTypesForReason(subId, |
| 7372 | TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER, |
| 7373 | RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId))); |
| 7374 | setAllowedNetworkTypesForReason(subId, |
| 7375 | TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER, |
| 7376 | RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId))); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7377 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 7378 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7379 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7380 | // There has been issues when Sms raw table somehow stores orphan |
| 7381 | // fragments. They lead to garbled message when new fragments come |
| 7382 | // in and combined with those stale ones. In case this happens again, |
| 7383 | // user can reset all network settings which will clean up this table. |
| 7384 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7385 | // Clean up IMS settings as well here. |
| 7386 | int slotId = getSlotIndex(subId); |
| 7387 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7388 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7389 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7390 | |
| 7391 | // Erase modem config if erase modem on network setting is enabled. |
| 7392 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7393 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7394 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 7395 | sendEraseModemConfig(getDefaultPhone()); |
| 7396 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7397 | } finally { |
| 7398 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7399 | } |
| 7400 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7401 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7402 | private void cleanUpSmsRawTable(Context context) { |
| 7403 | ContentResolver resolver = context.getContentResolver(); |
| 7404 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7405 | resolver.delete(uri, null, null); |
| 7406 | } |
| 7407 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7408 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7409 | public String getSimLocaleForSubscriber(int subId) { |
| 7410 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7411 | final Phone phone = getPhone(subId); |
| 7412 | if (phone == null) { |
| 7413 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7414 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7415 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7416 | final long identity = Binder.clearCallingIdentity(); |
| 7417 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7418 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7419 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7420 | if (info == null) { |
| 7421 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7422 | return null; |
| 7423 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7424 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7425 | // preferences (EF-PL and EF-LI)... |
| 7426 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7427 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7428 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7429 | if (localeFromDefaultSim != null) { |
| 7430 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7431 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7432 | + localeFromDefaultSim); |
| 7433 | return localeFromDefaultSim.toLanguageTag(); |
| 7434 | } else { |
| 7435 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7436 | } |
| 7437 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7438 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7439 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7440 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7441 | // the SIM and carrier preferences does not include a country we add the country |
| 7442 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7443 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7444 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7445 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7446 | return mccLocale.toLanguageTag(); |
| 7447 | } |
| 7448 | |
| 7449 | if (DBG) log("No locale found - returning null"); |
| 7450 | return null; |
| 7451 | } finally { |
| 7452 | Binder.restoreCallingIdentity(identity); |
| 7453 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7454 | } |
| 7455 | |
| 7456 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7457 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7458 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7459 | } |
| 7460 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7461 | /** |
| 7462 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7463 | */ |
| 7464 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7465 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7466 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7467 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7468 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7469 | private final ModemActivityInfo mLastModemActivityInfo = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7470 | new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7471 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7472 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7473 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7474 | * representing the state of the modem. |
| 7475 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7476 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7477 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7478 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7479 | */ |
| 7480 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7481 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7482 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7483 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7484 | |
| 7485 | final long identity = Binder.clearCallingIdentity(); |
| 7486 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7487 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7488 | } finally { |
| 7489 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7490 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7491 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7492 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7493 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7494 | // less than total activity duration. |
| 7495 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7496 | if (info == null) { |
| 7497 | return false; |
| 7498 | } |
| 7499 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7500 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7501 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7502 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7503 | return (info.isValid() |
| 7504 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7505 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7506 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7507 | && (totalTxTimeMs <= activityDurationMs)); |
| 7508 | } |
| 7509 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7510 | /** |
| 7511 | * {@hide} |
| 7512 | * Returns the service state information on specified subscription. |
| 7513 | */ |
| 7514 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7515 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7516 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7517 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7518 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7519 | return null; |
| 7520 | } |
| 7521 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7522 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7523 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7524 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7525 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7526 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7527 | .setCallingPid(Binder.getCallingPid()) |
| 7528 | .setCallingUid(Binder.getCallingUid()) |
| 7529 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7530 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7531 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7532 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7533 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7534 | .build()); |
| 7535 | |
| 7536 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7537 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7538 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7539 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7540 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7541 | .setCallingPid(Binder.getCallingPid()) |
| 7542 | .setCallingUid(Binder.getCallingUid()) |
| 7543 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7544 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7545 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7546 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7547 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7548 | .build()); |
| 7549 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7550 | boolean hasFinePermission = |
| 7551 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7552 | boolean hasCoarsePermission = |
| 7553 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7554 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7555 | final Phone phone = getPhone(subId); |
| 7556 | if (phone == null) { |
| 7557 | return null; |
| 7558 | } |
| 7559 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 7560 | final long identity = Binder.clearCallingIdentity(); |
| 7561 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7562 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 7563 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7564 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7565 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7566 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7567 | Rlog.d(LOG_TAG, |
| 7568 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7569 | return null; |
| 7570 | } |
| 7571 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7572 | ServiceState ss = phone.getServiceState(); |
| 7573 | |
| 7574 | // Scrub out the location info in ServiceState depending on what level of access |
| 7575 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7576 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7577 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7578 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7579 | } finally { |
| 7580 | Binder.restoreCallingIdentity(identity); |
| 7581 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7582 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7583 | |
| 7584 | /** |
| 7585 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7586 | * |
| 7587 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7588 | * voicemail ringtone. |
| 7589 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7590 | * PhoneAccount. |
| 7591 | */ |
| 7592 | @Override |
| 7593 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7594 | final long identity = Binder.clearCallingIdentity(); |
| 7595 | try { |
| 7596 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7597 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7598 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7599 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7600 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7601 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7602 | } finally { |
| 7603 | Binder.restoreCallingIdentity(identity); |
| 7604 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7605 | } |
| 7606 | |
| 7607 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7608 | * Sets the per-account voicemail ringtone. |
| 7609 | * |
| 7610 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7611 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7612 | * |
| 7613 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7614 | * voicemail ringtone. |
| 7615 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7616 | * PhoneAccount. |
| 7617 | */ |
| 7618 | @Override |
| 7619 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7620 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7621 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7622 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7623 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7624 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7625 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7626 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7627 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7628 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7629 | |
| 7630 | final long identity = Binder.clearCallingIdentity(); |
| 7631 | try { |
| 7632 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7633 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7634 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7635 | } |
| 7636 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7637 | } finally { |
| 7638 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7639 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7640 | } |
| 7641 | |
| 7642 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7643 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7644 | * |
| 7645 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7646 | * voicemail vibration setting. |
| 7647 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7648 | */ |
| 7649 | @Override |
| 7650 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7651 | final long identity = Binder.clearCallingIdentity(); |
| 7652 | try { |
| 7653 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7654 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7655 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7656 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7657 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7658 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7659 | } finally { |
| 7660 | Binder.restoreCallingIdentity(identity); |
| 7661 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7662 | } |
| 7663 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7664 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7665 | * Sets the per-account voicemail vibration. |
| 7666 | * |
| 7667 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7668 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7669 | * |
| 7670 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7671 | * voicemail vibration setting. |
| 7672 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7673 | * specific PhoneAccount. |
| 7674 | */ |
| 7675 | @Override |
| 7676 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7677 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7678 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7679 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7680 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7681 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7682 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7683 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7684 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7685 | } |
| 7686 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7687 | final long identity = Binder.clearCallingIdentity(); |
| 7688 | try { |
| 7689 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7690 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7691 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7692 | } |
| 7693 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7694 | } finally { |
| 7695 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7696 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7697 | } |
| 7698 | |
| 7699 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7700 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 7701 | * |
| 7702 | * @throws SecurityException if the caller does not have the required permission |
| 7703 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7704 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7705 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7706 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7707 | } |
| 7708 | |
| 7709 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7710 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 7711 | * permission. |
| 7712 | * |
| 7713 | * @throws SecurityException if the caller does not have the required permission |
| 7714 | */ |
| 7715 | private void enforceSendSmsPermission() { |
| 7716 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 7717 | } |
| 7718 | |
| 7719 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7720 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7721 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7722 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7723 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7724 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7725 | final long identity = Binder.clearCallingIdentity(); |
| 7726 | try { |
| 7727 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7728 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7729 | if (componentName == null) { |
| 7730 | throw new SecurityException( |
| 7731 | "Caller not current active visual voicemail package[null]"); |
| 7732 | } |
| 7733 | String vvmPackage = componentName.getPackageName(); |
| 7734 | if (!callingPackage.equals(vvmPackage)) { |
| 7735 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 7736 | + vvmPackage + "]"); |
| 7737 | } |
| 7738 | } finally { |
| 7739 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7740 | } |
| 7741 | } |
| 7742 | |
| 7743 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7744 | * Return the application ID for the app type. |
| 7745 | * |
| 7746 | * @param subId the subscription ID that this request applies to. |
| 7747 | * @param appType the uicc app type. |
| 7748 | * @return Application ID for specificied app type, or null if no uicc. |
| 7749 | */ |
| 7750 | @Override |
| 7751 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7752 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7753 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7754 | |
| 7755 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7756 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7757 | if (phone == null) { |
| 7758 | return null; |
| 7759 | } |
| 7760 | String aid = null; |
| 7761 | try { |
| 7762 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 7763 | .getApplicationByType(appType).getAid(); |
| 7764 | } catch (Exception e) { |
| 7765 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 7766 | } |
| 7767 | return aid; |
| 7768 | } finally { |
| 7769 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7770 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7771 | } |
| 7772 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7773 | /** |
| 7774 | * Return the Electronic Serial Number. |
| 7775 | * |
| 7776 | * @param subId the subscription ID that this request applies to. |
| 7777 | * @return ESN or null if error. |
| 7778 | */ |
| 7779 | @Override |
| 7780 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7781 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7782 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7783 | |
| 7784 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7785 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7786 | if (phone == null) { |
| 7787 | return null; |
| 7788 | } |
| 7789 | String esn = null; |
| 7790 | try { |
| 7791 | esn = phone.getEsn(); |
| 7792 | } catch (Exception e) { |
| 7793 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 7794 | } |
| 7795 | return esn; |
| 7796 | } finally { |
| 7797 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7798 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7799 | } |
| 7800 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7801 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7802 | * Return the Preferred Roaming List Version. |
| 7803 | * |
| 7804 | * @param subId the subscription ID that this request applies to. |
| 7805 | * @return PRLVersion or null if error. |
| 7806 | */ |
| 7807 | @Override |
| 7808 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7809 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7810 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7811 | |
| 7812 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7813 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7814 | if (phone == null) { |
| 7815 | return null; |
| 7816 | } |
| 7817 | String cdmaPrlVersion = null; |
| 7818 | try { |
| 7819 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7820 | } catch (Exception e) { |
| 7821 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7822 | } |
| 7823 | return cdmaPrlVersion; |
| 7824 | } finally { |
| 7825 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7826 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7827 | } |
| 7828 | |
| 7829 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7830 | * Get snapshot of Telephony histograms |
| 7831 | * @return List of Telephony histograms |
| 7832 | * @hide |
| 7833 | */ |
| 7834 | @Override |
| 7835 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7836 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7837 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7838 | |
| 7839 | final long identity = Binder.clearCallingIdentity(); |
| 7840 | try { |
| 7841 | return RIL.getTelephonyRILTimingHistograms(); |
| 7842 | } finally { |
| 7843 | Binder.restoreCallingIdentity(identity); |
| 7844 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7845 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7846 | |
| 7847 | /** |
| 7848 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7849 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7850 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7851 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7852 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7853 | * @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] | 7854 | */ |
| 7855 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7856 | @TelephonyManager.SetCarrierRestrictionResult |
| 7857 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7858 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7859 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7860 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7861 | if (carrierRestrictionRules == null) { |
| 7862 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7863 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7864 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7865 | final long identity = Binder.clearCallingIdentity(); |
| 7866 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7867 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7868 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7869 | } finally { |
| 7870 | Binder.restoreCallingIdentity(identity); |
| 7871 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7872 | } |
| 7873 | |
| 7874 | /** |
| 7875 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7876 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7877 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7878 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7879 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7880 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7881 | */ |
| 7882 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7883 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7884 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7885 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7886 | |
| 7887 | final long identity = Binder.clearCallingIdentity(); |
| 7888 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7889 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7890 | if (response instanceof CarrierRestrictionRules) { |
| 7891 | return (CarrierRestrictionRules) response; |
| 7892 | } |
| 7893 | // Response is an Exception of some kind, |
| 7894 | // which is signalled to the user as a NULL retval |
| 7895 | return null; |
| 7896 | } catch (Exception e) { |
| 7897 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7898 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7899 | } finally { |
| 7900 | Binder.restoreCallingIdentity(identity); |
| 7901 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7902 | } |
| 7903 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7904 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7905 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7906 | * @param subId the subscription ID that this action applies to. |
| 7907 | * @param enabled control enable or disable radio. |
| 7908 | * {@hide} |
| 7909 | */ |
| 7910 | @Override |
| 7911 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7912 | enforceModifyPermission(); |
| 7913 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7914 | |
| 7915 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7916 | if (phone == null) { |
| 7917 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7918 | return; |
| 7919 | } |
| 7920 | try { |
| 7921 | phone.carrierActionSetRadioEnabled(enabled); |
| 7922 | } catch (Exception e) { |
| 7923 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7924 | } finally { |
| 7925 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7926 | } |
| 7927 | } |
| 7928 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7929 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7930 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7931 | * network status based on which carrier apps could apply actions accordingly, |
| 7932 | * enable/disable default url handler for example. |
| 7933 | * |
| 7934 | * @param subId the subscription ID that this action applies to. |
| 7935 | * @param report control start/stop reporting the default network status. |
| 7936 | * {@hide} |
| 7937 | */ |
| 7938 | @Override |
| 7939 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7940 | enforceModifyPermission(); |
| 7941 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7942 | |
| 7943 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7944 | if (phone == null) { |
| 7945 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7946 | return; |
| 7947 | } |
| 7948 | try { |
| 7949 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7950 | } catch (Exception e) { |
| 7951 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7952 | } finally { |
| 7953 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7954 | } |
| 7955 | } |
| 7956 | |
| 7957 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7958 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7959 | * @param subId the subscription ID that this action applies to. |
| 7960 | * {@hide} |
| 7961 | */ |
| 7962 | @Override |
| 7963 | public void carrierActionResetAll(int subId) { |
| 7964 | enforceModifyPermission(); |
| 7965 | final Phone phone = getPhone(subId); |
| 7966 | if (phone == null) { |
| 7967 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7968 | return; |
| 7969 | } |
| 7970 | try { |
| 7971 | phone.carrierActionResetAll(); |
| 7972 | } catch (Exception e) { |
| 7973 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7974 | } |
| 7975 | } |
| 7976 | |
| 7977 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7978 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7979 | * bug report is being generated. |
| 7980 | */ |
| 7981 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7982 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7983 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7984 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7985 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7986 | + Binder.getCallingPid() |
| 7987 | + ", uid=" + Binder.getCallingUid() |
| 7988 | + "without permission " |
| 7989 | + android.Manifest.permission.DUMP); |
| 7990 | return; |
| 7991 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7992 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7993 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7994 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7995 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 7996 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 7997 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 7998 | @NonNull String[] args) { |
| 7999 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 8000 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 8001 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 8002 | } |
| 8003 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 8004 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8005 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 8006 | * @param subId Subscription index |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8007 | * @param reason the reason the data enable change is taking place |
| 8008 | * @param enabled True if enabling the data, otherwise disabling. |
| 8009 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8010 | */ |
| 8011 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8012 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8013 | boolean enabled) { |
| 8014 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 8015 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8016 | try { |
| 8017 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 8018 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8019 | } catch (SecurityException se) { |
| 8020 | enforceModifyPermission(); |
| 8021 | } |
| 8022 | } else { |
| 8023 | enforceModifyPermission(); |
| 8024 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8025 | |
| 8026 | final long identity = Binder.clearCallingIdentity(); |
| 8027 | try { |
| 8028 | Phone phone = getPhone(subId); |
| 8029 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 8030 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 8031 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 8032 | } else { |
| 8033 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 8034 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8035 | } |
| 8036 | } finally { |
| 8037 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 8038 | } |
| 8039 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8040 | |
| 8041 | /** |
| 8042 | * Get Client request stats |
| 8043 | * @return List of Client Request Stats |
| 8044 | * @hide |
| 8045 | */ |
| 8046 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8047 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 8048 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 8049 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8050 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8051 | return null; |
| 8052 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8053 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8054 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8055 | final long identity = Binder.clearCallingIdentity(); |
| 8056 | try { |
| 8057 | if (phone != null) { |
| 8058 | return phone.getClientRequestStats(); |
| 8059 | } |
| 8060 | |
| 8061 | return null; |
| 8062 | } finally { |
| 8063 | Binder.restoreCallingIdentity(identity); |
| 8064 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8065 | } |
| 8066 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8067 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8068 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 8069 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 8070 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8071 | |
| 8072 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8073 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8074 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8075 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8076 | * @param state State of SIM (power down, power up, pass through) |
| 8077 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8078 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8079 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8080 | * |
| 8081 | **/ |
| 8082 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8083 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8084 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8085 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8086 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8087 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8088 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8089 | final long identity = Binder.clearCallingIdentity(); |
| 8090 | try { |
| 8091 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8092 | phone.setSimPowerState(state, null, workSource); |
| 8093 | } |
| 8094 | } finally { |
| 8095 | Binder.restoreCallingIdentity(identity); |
| 8096 | } |
| 8097 | } |
| 8098 | |
| 8099 | /** |
| 8100 | * Set SIM card power state. |
| 8101 | * |
| 8102 | * @param slotIndex SIM slot id. |
| 8103 | * @param state State of SIM (power down, power up, pass through) |
| 8104 | * @param callback callback to trigger after success or failure |
| 8105 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8106 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8107 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8108 | * |
| 8109 | **/ |
| 8110 | @Override |
| 8111 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8112 | IIntegerConsumer callback) { |
| 8113 | enforceModifyPermission(); |
| 8114 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8115 | |
| 8116 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8117 | |
| 8118 | final long identity = Binder.clearCallingIdentity(); |
| 8119 | try { |
| 8120 | if (phone != null) { |
| 8121 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8122 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8123 | } |
| 8124 | } finally { |
| 8125 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8126 | } |
| 8127 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8128 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8129 | private boolean isUssdApiAllowed(int subId) { |
| 8130 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8131 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8132 | if (configManager == null) { |
| 8133 | return false; |
| 8134 | } |
| 8135 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8136 | if (pb == null) { |
| 8137 | return false; |
| 8138 | } |
| 8139 | return pb.getBoolean( |
| 8140 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8141 | } |
| 8142 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8143 | /** |
| 8144 | * Check if phone is in emergency callback mode |
| 8145 | * @return true if phone is in emergency callback mode |
| 8146 | * @param subId sub id |
| 8147 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8148 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8149 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8150 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8151 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8152 | |
| 8153 | final long identity = Binder.clearCallingIdentity(); |
| 8154 | try { |
| 8155 | if (phone != null) { |
| 8156 | return phone.isInEcm(); |
| 8157 | } else { |
| 8158 | return false; |
| 8159 | } |
| 8160 | } finally { |
| 8161 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8162 | } |
| 8163 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8164 | |
| 8165 | /** |
| 8166 | * Get the current signal strength information for the given subscription. |
| 8167 | * Because this information is not updated when the device is in a low power state |
| 8168 | * it should not be relied-upon to be current. |
| 8169 | * @param subId Subscription index |
| 8170 | * @return the most recent cached signal strength info from the modem |
| 8171 | */ |
| 8172 | @Override |
| 8173 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8174 | final long identity = Binder.clearCallingIdentity(); |
| 8175 | try { |
| 8176 | Phone p = getPhone(subId); |
| 8177 | if (p == null) { |
| 8178 | return null; |
| 8179 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8180 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8181 | return p.getSignalStrength(); |
| 8182 | } finally { |
| 8183 | Binder.restoreCallingIdentity(identity); |
| 8184 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8185 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8186 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8187 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8188 | * Get the current modem radio state for the given slot. |
| 8189 | * @param slotIndex slot index. |
| 8190 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8191 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8192 | * @return the current radio power state from the modem |
| 8193 | */ |
| 8194 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8195 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8196 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8197 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8198 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8199 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8200 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8201 | } |
| 8202 | |
| 8203 | final long identity = Binder.clearCallingIdentity(); |
| 8204 | try { |
| 8205 | return phone.getRadioPowerState(); |
| 8206 | } finally { |
| 8207 | Binder.restoreCallingIdentity(identity); |
| 8208 | } |
| 8209 | } |
| 8210 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8211 | } |
| 8212 | |
| 8213 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8214 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8215 | * |
| 8216 | * <p>Requires one of the following permissions: |
| 8217 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 8218 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8219 | * privileges. |
| 8220 | * |
| 8221 | * @param subId subscription id |
| 8222 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8223 | * {@code false}. |
| 8224 | */ |
| 8225 | @Override |
| 8226 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8227 | try { |
| 8228 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8229 | null); |
| 8230 | } catch (Exception e) { |
| 8231 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 8232 | mApp, subId, "isDataRoamingEnabled"); |
| 8233 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8234 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8235 | boolean isEnabled = false; |
| 8236 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8237 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8238 | Phone phone = getPhone(subId); |
| 8239 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8240 | } finally { |
| 8241 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8242 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8243 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8244 | } |
| 8245 | |
| 8246 | |
| 8247 | /** |
| 8248 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8249 | * |
| 8250 | * <p> Requires permission: |
| 8251 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8252 | * privileges. |
| 8253 | * |
| 8254 | * @param subId subscription id |
| 8255 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8256 | */ |
| 8257 | @Override |
| 8258 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8259 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8260 | mApp, subId, "setDataRoamingEnabled"); |
| 8261 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8262 | final long identity = Binder.clearCallingIdentity(); |
| 8263 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8264 | Phone phone = getPhone(subId); |
| 8265 | if (phone != null) { |
| 8266 | phone.setDataRoamingEnabled(isEnabled); |
| 8267 | } |
| 8268 | } finally { |
| 8269 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8270 | } |
| 8271 | } |
| 8272 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8273 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8274 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8275 | TelephonyPermissions |
| 8276 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8277 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8278 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8279 | boolean isAllowed = true; |
| 8280 | final long identity = Binder.clearCallingIdentity(); |
| 8281 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8282 | Phone phone = getPhone(subId); |
| 8283 | if (phone != null) { |
| 8284 | isAllowed = phone.isCspPlmnEnabled(); |
| 8285 | } |
| 8286 | } finally { |
| 8287 | Binder.restoreCallingIdentity(identity); |
| 8288 | } |
| 8289 | return isAllowed; |
| 8290 | } |
| 8291 | |
| 8292 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8293 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8294 | // Verify that tha callingPackage belongs to the calling UID |
| 8295 | mApp.getSystemService(AppOpsManager.class) |
| 8296 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8297 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8298 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8299 | try { |
| 8300 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8301 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8302 | } catch (SecurityException e) { |
| 8303 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8304 | // has carrier privileges on an active UICC |
| 8305 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8306 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8307 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8308 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8309 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8310 | |
| 8311 | final long identity = Binder.clearCallingIdentity(); |
| 8312 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8313 | UiccController uiccController = UiccController.getInstance(); |
| 8314 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8315 | if (hasReadPermission) { |
| 8316 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8317 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8318 | |
| 8319 | // Remove private info if the caller doesn't have access |
| 8320 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8321 | for (UiccCardInfo cardInfo : cardInfos) { |
| 8322 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8323 | // is available |
| 8324 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 8325 | if (card == null || card.getUiccProfile() == null) { |
| 8326 | // assume no access if the card or profile is unavailable |
| 8327 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8328 | continue; |
| 8329 | } |
| 8330 | UiccProfile profile = card.getUiccProfile(); |
| 8331 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8332 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8333 | filteredInfos.add(cardInfo); |
| 8334 | } else { |
| 8335 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8336 | } |
| 8337 | } |
| 8338 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8339 | } finally { |
| 8340 | Binder.restoreCallingIdentity(identity); |
| 8341 | } |
| 8342 | } |
| 8343 | |
| 8344 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8345 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8346 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8347 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8348 | final long identity = Binder.clearCallingIdentity(); |
| 8349 | try { |
| 8350 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8351 | if (slots == null) { |
| 8352 | Rlog.i(LOG_TAG, "slots is null."); |
| 8353 | return null; |
| 8354 | } |
| 8355 | |
| 8356 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8357 | for (int i = 0; i < slots.length; i++) { |
| 8358 | UiccSlot slot = slots[i]; |
| 8359 | if (slot == null) { |
| 8360 | continue; |
| 8361 | } |
| 8362 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8363 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8364 | UiccCard card = slot.getUiccCard(); |
| 8365 | if (card != null) { |
| 8366 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8367 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8368 | cardId = slot.getEid(); |
| 8369 | if (TextUtils.isEmpty(cardId)) { |
| 8370 | cardId = slot.getIccId(); |
| 8371 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8372 | } |
| 8373 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8374 | if (cardId != null) { |
| 8375 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8376 | // if cardId is an EID, it's all digits so this is fine |
| 8377 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8378 | } |
| 8379 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8380 | int cardState = 0; |
| 8381 | switch (slot.getCardState()) { |
| 8382 | case CARDSTATE_ABSENT: |
| 8383 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8384 | break; |
| 8385 | case CARDSTATE_PRESENT: |
| 8386 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8387 | break; |
| 8388 | case CARDSTATE_ERROR: |
| 8389 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8390 | break; |
| 8391 | case CARDSTATE_RESTRICTED: |
| 8392 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8393 | break; |
| 8394 | default: |
| 8395 | break; |
| 8396 | |
| 8397 | } |
| 8398 | |
| 8399 | infos[i] = new UiccSlotInfo( |
| 8400 | slot.isActive(), |
| 8401 | slot.isEuicc(), |
| 8402 | cardId, |
| 8403 | cardState, |
| 8404 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8405 | slot.isExtendedApduSupported(), |
| 8406 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8407 | } |
| 8408 | return infos; |
| 8409 | } finally { |
| 8410 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8411 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8412 | } |
| 8413 | |
| 8414 | @Override |
| 8415 | public boolean switchSlots(int[] physicalSlots) { |
| 8416 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8417 | |
| 8418 | final long identity = Binder.clearCallingIdentity(); |
| 8419 | try { |
| 8420 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8421 | } finally { |
| 8422 | Binder.restoreCallingIdentity(identity); |
| 8423 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8424 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8425 | |
| 8426 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8427 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8428 | final long identity = Binder.clearCallingIdentity(); |
| 8429 | try { |
| 8430 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8431 | } finally { |
| 8432 | Binder.restoreCallingIdentity(identity); |
| 8433 | } |
| 8434 | } |
| 8435 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8436 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8437 | * A test API to reload the UICC profile. |
| 8438 | * |
| 8439 | * <p>Requires that the calling app has permission |
| 8440 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8441 | * @hide |
| 8442 | */ |
| 8443 | @Override |
| 8444 | public void refreshUiccProfile(int subId) { |
| 8445 | enforceModifyPermission(); |
| 8446 | |
| 8447 | final long identity = Binder.clearCallingIdentity(); |
| 8448 | try { |
| 8449 | Phone phone = getPhone(subId); |
| 8450 | if (phone == null) { |
| 8451 | return; |
| 8452 | } |
| 8453 | UiccCard uiccCard = phone.getUiccCard(); |
| 8454 | if (uiccCard == null) { |
| 8455 | return; |
| 8456 | } |
| 8457 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8458 | if (uiccProfile == null) { |
| 8459 | return; |
| 8460 | } |
| 8461 | uiccProfile.refresh(); |
| 8462 | } finally { |
| 8463 | Binder.restoreCallingIdentity(identity); |
| 8464 | } |
| 8465 | } |
| 8466 | |
| 8467 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8468 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8469 | */ |
| 8470 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8471 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8472 | } |
| 8473 | |
| 8474 | /** |
| 8475 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8476 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8477 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8478 | */ |
| 8479 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8480 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8481 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8482 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8483 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8484 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8485 | return isDataRoamingEnabled; |
| 8486 | } |
| 8487 | |
| 8488 | /** |
| 8489 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8490 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8491 | */ |
| 8492 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8493 | List<Integer> list = TelephonyProperties.default_network(); |
| 8494 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8495 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8496 | return list.get(phoneId); |
| 8497 | } |
| 8498 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8499 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8500 | |
| 8501 | @Override |
| 8502 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8503 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8504 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8505 | |
| 8506 | final long identity = Binder.clearCallingIdentity(); |
| 8507 | try { |
| 8508 | final Phone phone = getPhone(subId); |
| 8509 | if (phone == null) { |
| 8510 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8511 | return; |
| 8512 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8513 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8514 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8515 | if (carrierPrivilegeRules == null) { |
| 8516 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8517 | } else { |
| 8518 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8519 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8520 | } finally { |
| 8521 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8522 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8523 | } |
| 8524 | |
| 8525 | @Override |
| 8526 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8527 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8528 | |
| 8529 | final long identity = Binder.clearCallingIdentity(); |
| 8530 | try { |
| 8531 | final Phone phone = getPhone(subId); |
| 8532 | if (phone == null) { |
| 8533 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 8534 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 8535 | } |
| 8536 | return phone.getCarrierIdListVersion(); |
| 8537 | } finally { |
| 8538 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8539 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8540 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8541 | |
| 8542 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8543 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 8544 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8545 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8546 | mApp, subId, callingPackage, callingFeatureId, |
| 8547 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8548 | return -1; |
| 8549 | } |
| 8550 | |
| 8551 | final long identity = Binder.clearCallingIdentity(); |
| 8552 | try { |
| 8553 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 8554 | } finally { |
| 8555 | Binder.restoreCallingIdentity(identity); |
| 8556 | } |
| 8557 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8558 | |
| 8559 | @Override |
| 8560 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 8561 | TelephonyPermissions |
| 8562 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8563 | mApp, subId, "getCdmaRoamingMode"); |
| 8564 | |
| 8565 | final long identity = Binder.clearCallingIdentity(); |
| 8566 | try { |
| 8567 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 8568 | } finally { |
| 8569 | Binder.restoreCallingIdentity(identity); |
| 8570 | } |
| 8571 | } |
| 8572 | |
| 8573 | @Override |
| 8574 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 8575 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8576 | mApp, subId, "setCdmaRoamingMode"); |
| 8577 | |
| 8578 | final long identity = Binder.clearCallingIdentity(); |
| 8579 | try { |
| 8580 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 8581 | } finally { |
| 8582 | Binder.restoreCallingIdentity(identity); |
| 8583 | } |
| 8584 | } |
| 8585 | |
| 8586 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8587 | public int getCdmaSubscriptionMode(int subId) { |
| 8588 | TelephonyPermissions |
| 8589 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8590 | mApp, subId, "getCdmaSubscriptionMode"); |
| 8591 | |
| 8592 | final long identity = Binder.clearCallingIdentity(); |
| 8593 | try { |
| 8594 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 8595 | } finally { |
| 8596 | Binder.restoreCallingIdentity(identity); |
| 8597 | } |
| 8598 | } |
| 8599 | |
| 8600 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8601 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 8602 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8603 | mApp, subId, "setCdmaSubscriptionMode"); |
| 8604 | |
| 8605 | final long identity = Binder.clearCallingIdentity(); |
| 8606 | try { |
| 8607 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 8608 | } finally { |
| 8609 | Binder.restoreCallingIdentity(identity); |
| 8610 | } |
| 8611 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8612 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8613 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8614 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8615 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8616 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8617 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 8618 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8619 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8620 | } |
| 8621 | final long identity = Binder.clearCallingIdentity(); |
| 8622 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8623 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 8624 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8625 | if (phone.getEmergencyNumberTracker() != null |
| 8626 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 8627 | emergencyNumberListInternal.put( |
| 8628 | phone.getSubId(), |
| 8629 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 8630 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8631 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8632 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8633 | } finally { |
| 8634 | Binder.restoreCallingIdentity(identity); |
| 8635 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8636 | } |
| 8637 | |
| 8638 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8639 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8640 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8641 | if (!exactMatch) { |
| 8642 | TelephonyPermissions |
| 8643 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8644 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8645 | } |
| 8646 | final long identity = Binder.clearCallingIdentity(); |
| 8647 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8648 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8649 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8650 | && phone.getEmergencyNumberTracker() |
| 8651 | .isEmergencyNumber(number, exactMatch)) { |
| 8652 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8653 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8654 | } |
| 8655 | return false; |
| 8656 | } finally { |
| 8657 | Binder.restoreCallingIdentity(identity); |
| 8658 | } |
| 8659 | } |
| 8660 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8661 | /** |
| 8662 | * Update emergency number list for test mode. |
| 8663 | */ |
| 8664 | @Override |
| 8665 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 8666 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8667 | "updateEmergencyNumberListTestMode"); |
| 8668 | |
| 8669 | final long identity = Binder.clearCallingIdentity(); |
| 8670 | try { |
| 8671 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8672 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8673 | if (tracker != null) { |
| 8674 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 8675 | } |
| 8676 | } |
| 8677 | } finally { |
| 8678 | Binder.restoreCallingIdentity(identity); |
| 8679 | } |
| 8680 | } |
| 8681 | |
| 8682 | /** |
| 8683 | * Get the full emergency number list for test mode. |
| 8684 | */ |
| 8685 | @Override |
| 8686 | public List<String> getEmergencyNumberListTestMode() { |
| 8687 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8688 | "getEmergencyNumberListTestMode"); |
| 8689 | |
| 8690 | final long identity = Binder.clearCallingIdentity(); |
| 8691 | try { |
| 8692 | Set<String> emergencyNumbers = new HashSet<>(); |
| 8693 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8694 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8695 | if (tracker != null) { |
| 8696 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 8697 | emergencyNumbers.add(num.getNumber()); |
| 8698 | } |
| 8699 | } |
| 8700 | } |
| 8701 | return new ArrayList<>(emergencyNumbers); |
| 8702 | } finally { |
| 8703 | Binder.restoreCallingIdentity(identity); |
| 8704 | } |
| 8705 | } |
| 8706 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8707 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8708 | public int getEmergencyNumberDbVersion(int subId) { |
| 8709 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 8710 | |
| 8711 | final long identity = Binder.clearCallingIdentity(); |
| 8712 | try { |
| 8713 | final Phone phone = getPhone(subId); |
| 8714 | if (phone == null) { |
| 8715 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 8716 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 8717 | } |
| 8718 | return phone.getEmergencyNumberDbVersion(); |
| 8719 | } finally { |
| 8720 | Binder.restoreCallingIdentity(identity); |
| 8721 | } |
| 8722 | } |
| 8723 | |
| 8724 | @Override |
| 8725 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 8726 | enforceModifyPermission(); |
| 8727 | |
| 8728 | final long identity = Binder.clearCallingIdentity(); |
| 8729 | try { |
| 8730 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8731 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8732 | if (tracker != null) { |
| 8733 | tracker.updateOtaEmergencyNumberDatabase(); |
| 8734 | } |
| 8735 | } |
| 8736 | } finally { |
| 8737 | Binder.restoreCallingIdentity(identity); |
| 8738 | } |
| 8739 | } |
| 8740 | |
| 8741 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8742 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8743 | enforceActiveEmergencySessionPermission(); |
| 8744 | |
| 8745 | final long identity = Binder.clearCallingIdentity(); |
| 8746 | try { |
| 8747 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8748 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8749 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8750 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 8751 | } |
| 8752 | } |
| 8753 | } finally { |
| 8754 | Binder.restoreCallingIdentity(identity); |
| 8755 | } |
| 8756 | } |
| 8757 | |
| 8758 | @Override |
| 8759 | public void resetOtaEmergencyNumberDbFilePath() { |
| 8760 | enforceActiveEmergencySessionPermission(); |
| 8761 | |
| 8762 | final long identity = Binder.clearCallingIdentity(); |
| 8763 | try { |
| 8764 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8765 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8766 | if (tracker != null) { |
| 8767 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8768 | } |
| 8769 | } |
| 8770 | } finally { |
| 8771 | Binder.restoreCallingIdentity(identity); |
| 8772 | } |
| 8773 | } |
| 8774 | |
| 8775 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8776 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 8777 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 8778 | Phone phone = getPhone(subId); |
| 8779 | if (phone == null) { |
| 8780 | return null; |
| 8781 | } |
| 8782 | final long identity = Binder.clearCallingIdentity(); |
| 8783 | try { |
| 8784 | UiccProfile profile = UiccController.getInstance() |
| 8785 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 8786 | if (profile != null) { |
| 8787 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 8788 | } |
| 8789 | } finally { |
| 8790 | Binder.restoreCallingIdentity(identity); |
| 8791 | } |
| 8792 | return null; |
| 8793 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 8794 | |
| 8795 | /** |
| 8796 | * Enable or disable a modem stack. |
| 8797 | */ |
| 8798 | @Override |
| 8799 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 8800 | enforceModifyPermission(); |
| 8801 | |
| 8802 | final long identity = Binder.clearCallingIdentity(); |
| 8803 | try { |
| 8804 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8805 | if (phone == null) { |
| 8806 | return false; |
| 8807 | } else { |
| 8808 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 8809 | } |
| 8810 | } finally { |
| 8811 | Binder.restoreCallingIdentity(identity); |
| 8812 | } |
| 8813 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8814 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8815 | /** |
| 8816 | * Whether a modem stack is enabled or not. |
| 8817 | */ |
| 8818 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8819 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 8820 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8821 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8822 | if (phone == null) return false; |
| 8823 | |
| 8824 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8825 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 8826 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8827 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8828 | } |
| 8829 | |
| 8830 | final long identity = Binder.clearCallingIdentity(); |
| 8831 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8832 | try { |
| 8833 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 8834 | } catch (NoSuchElementException ex) { |
| 8835 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 8836 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8837 | } finally { |
| 8838 | Binder.restoreCallingIdentity(identity); |
| 8839 | } |
| 8840 | } |
| 8841 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8842 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8843 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8844 | enforceModifyPermission(); |
| 8845 | |
| 8846 | final long identity = Binder.clearCallingIdentity(); |
| 8847 | try { |
| 8848 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8849 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8850 | .commit(); |
| 8851 | } finally { |
| 8852 | Binder.restoreCallingIdentity(identity); |
| 8853 | } |
| 8854 | } |
| 8855 | |
| 8856 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8857 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8858 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8859 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8860 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8861 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8862 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8863 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8864 | |
| 8865 | final long identity = Binder.clearCallingIdentity(); |
| 8866 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8867 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8868 | } finally { |
| 8869 | Binder.restoreCallingIdentity(identity); |
| 8870 | } |
| 8871 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8872 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8873 | @TelephonyManager.IsMultiSimSupportedResult |
| 8874 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8875 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8876 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8877 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8878 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8879 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8880 | } |
| 8881 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8882 | // supported by the modem, indicate that it is restricted. |
| 8883 | PhoneCapability staticCapability = |
| 8884 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8885 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8886 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8887 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8888 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 8889 | if (staticCapability.getLogicalModemList().size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8890 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8891 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8892 | } |
| 8893 | // Check if support of multiple SIMs is restricted by carrier |
| 8894 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8895 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8896 | } |
| 8897 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8898 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8899 | } |
| 8900 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8901 | /** |
| 8902 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8903 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8904 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8905 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8906 | * @param numOfSims number of active sims we want to switch to |
| 8907 | */ |
| 8908 | @Override |
| 8909 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8910 | if (numOfSims == 1) { |
| 8911 | enforceModifyPermission(); |
| 8912 | } else { |
| 8913 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8914 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8915 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8916 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8917 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8918 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8919 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8920 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8921 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8922 | return; |
| 8923 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8924 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8925 | } finally { |
| 8926 | Binder.restoreCallingIdentity(identity); |
| 8927 | } |
| 8928 | } |
| 8929 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8930 | @Override |
| 8931 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8932 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8933 | Phone phone = getPhone(subId); |
| 8934 | if (phone == null) { |
| 8935 | return false; |
| 8936 | } |
| 8937 | final long identity = Binder.clearCallingIdentity(); |
| 8938 | try { |
| 8939 | UiccCard uiccCard = phone.getUiccCard(); |
| 8940 | if (uiccCard == null) { |
| 8941 | return false; |
| 8942 | } |
| 8943 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8944 | if (uiccProfile == null) { |
| 8945 | return false; |
| 8946 | } |
| 8947 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8948 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8949 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8950 | } |
| 8951 | return false; |
| 8952 | } finally { |
| 8953 | Binder.restoreCallingIdentity(identity); |
| 8954 | } |
| 8955 | } |
| 8956 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8957 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8958 | * Get whether making changes to modem configurations will trigger reboot. |
| 8959 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8960 | */ |
| 8961 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8962 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8963 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8964 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8965 | mApp, subId, callingPackage, callingFeatureId, |
| 8966 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8967 | return false; |
| 8968 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8969 | final long identity = Binder.clearCallingIdentity(); |
| 8970 | try { |
| 8971 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8972 | } finally { |
| 8973 | Binder.restoreCallingIdentity(identity); |
| 8974 | } |
| 8975 | } |
| 8976 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8977 | private void updateModemStateMetrics() { |
| 8978 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8979 | // TODO: check the state for each modem if the api is ready. |
| 8980 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8981 | } |
| 8982 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8983 | @Override |
| 8984 | public int[] getSlotsMapping() { |
| 8985 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8986 | |
| 8987 | final long identity = Binder.clearCallingIdentity(); |
| 8988 | try { |
| 8989 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8990 | // All logical slots should have a mapping to a physical slot. |
| 8991 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8992 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8993 | for (int i = 0; i < slotInfos.length; i++) { |
| 8994 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8995 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8996 | } |
| 8997 | } |
| 8998 | return logicalSlotsMapping; |
| 8999 | } finally { |
| 9000 | Binder.restoreCallingIdentity(identity); |
| 9001 | } |
| 9002 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 9003 | |
| 9004 | /** |
| 9005 | * Get the IRadio HAL Version |
| 9006 | */ |
| 9007 | @Override |
| 9008 | public int getRadioHalVersion() { |
| 9009 | Phone phone = getDefaultPhone(); |
| 9010 | if (phone == null) return -1; |
| 9011 | HalVersion hv = phone.getHalVersion(); |
| 9012 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 9013 | return hv.major * 100 + hv.minor; |
| 9014 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9015 | |
| 9016 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9017 | * Get the current calling package name. |
| 9018 | * @return the current calling package name |
| 9019 | */ |
| 9020 | @Override |
| 9021 | public String getCurrentPackageName() { |
| 9022 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 9023 | } |
| 9024 | |
| 9025 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9026 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 9027 | * corresponding network requests on a subId. |
| 9028 | * |
| 9029 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9030 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9031 | * 2) APN is un-metered for this subscription, or |
| 9032 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9033 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9034 | * |
| 9035 | * @return whether data is allowed for a apn type. |
| 9036 | * |
| 9037 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9038 | */ |
| 9039 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9040 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 9041 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 9042 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9043 | |
| 9044 | // Now that all security checks passes, perform the operation as ourselves. |
| 9045 | final long identity = Binder.clearCallingIdentity(); |
| 9046 | try { |
| 9047 | Phone phone = getPhone(subId); |
| 9048 | if (phone == null) return false; |
| 9049 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9050 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9051 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 9052 | } finally { |
| 9053 | Binder.restoreCallingIdentity(identity); |
| 9054 | } |
| 9055 | } |
| 9056 | |
| 9057 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9058 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 9059 | enforceReadPrivilegedPermission("isApnMetered"); |
| 9060 | |
| 9061 | // Now that all security checks passes, perform the operation as ourselves. |
| 9062 | final long identity = Binder.clearCallingIdentity(); |
| 9063 | try { |
| 9064 | Phone phone = getPhone(subId); |
| 9065 | if (phone == null) return true; // By default return true. |
| 9066 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 9067 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 9068 | } finally { |
| 9069 | Binder.restoreCallingIdentity(identity); |
| 9070 | } |
| 9071 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9072 | |
| 9073 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 9074 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 9075 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 9076 | enforceModifyPermission(); |
| 9077 | long token = Binder.clearCallingIdentity(); |
| 9078 | try { |
| 9079 | Phone phone = getPhone(subscriptionId); |
| 9080 | if (phone == null) { |
| 9081 | try { |
| 9082 | if (resultCallback != null) { |
| 9083 | resultCallback.accept(false); |
| 9084 | } |
| 9085 | } catch (RemoteException e) { |
| 9086 | // ignore |
| 9087 | } |
| 9088 | return; |
| 9089 | } |
| 9090 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9091 | Pair.create(specifiers, (x) -> { |
| 9092 | try { |
| 9093 | if (resultCallback != null) { |
| 9094 | resultCallback.accept(x); |
| 9095 | } |
| 9096 | } catch (RemoteException e) { |
| 9097 | // ignore |
| 9098 | } |
| 9099 | }); |
| 9100 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9101 | } finally { |
| 9102 | Binder.restoreCallingIdentity(token); |
| 9103 | } |
| 9104 | } |
| 9105 | |
| 9106 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9107 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9108 | TelephonyPermissions |
| 9109 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 9110 | mApp, subId, "getSystemSelectionChannels"); |
| 9111 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9112 | final long identity = Binder.clearCallingIdentity(); |
| 9113 | try { |
| 9114 | List<RadioAccessSpecifier> specifiers = |
| 9115 | (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, |
| 9116 | null, subId, workSource); |
| 9117 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9118 | return specifiers; |
| 9119 | } finally { |
| 9120 | Binder.restoreCallingIdentity(identity); |
| 9121 | } |
| 9122 | } |
| 9123 | |
| 9124 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9125 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9126 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9127 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 9128 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 9129 | if (iccRecords == null) { |
| 9130 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 9131 | return false; |
| 9132 | } |
| 9133 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9134 | } |
| 9135 | |
| 9136 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9137 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9138 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9139 | if (callingPackage == null) { |
| 9140 | callingPackage = getCurrentPackageName(); |
| 9141 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9142 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9143 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9144 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9145 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9146 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9147 | } |
| 9148 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9149 | Intent intent = new Intent(); |
| 9150 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9151 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9152 | // Bring up choose default SMS subscription dialog right now |
| 9153 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9154 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9155 | mApp.startActivity(intent); |
| 9156 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9157 | |
| 9158 | @Override |
| 9159 | public String getMmsUAProfUrl(int subId) { |
| 9160 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9161 | final long identity = Binder.clearCallingIdentity(); |
| 9162 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9163 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9164 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9165 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9166 | return carrierUAProfUrl; |
| 9167 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9168 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9169 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9170 | } finally { |
| 9171 | Binder.restoreCallingIdentity(identity); |
| 9172 | } |
| 9173 | } |
| 9174 | |
| 9175 | @Override |
| 9176 | public String getMmsUserAgent(int subId) { |
| 9177 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9178 | final long identity = Binder.clearCallingIdentity(); |
| 9179 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9180 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9181 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9182 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9183 | return carrierUserAgent; |
| 9184 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9185 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9186 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9187 | } finally { |
| 9188 | Binder.restoreCallingIdentity(identity); |
| 9189 | } |
| 9190 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9191 | |
| 9192 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9193 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9194 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9195 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9196 | final long identity = Binder.clearCallingIdentity(); |
| 9197 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9198 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9199 | if (phone == null) return false; |
| 9200 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9201 | switch (policy) { |
| 9202 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9203 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9204 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9205 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9206 | default: |
| 9207 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9208 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9209 | } finally { |
| 9210 | Binder.restoreCallingIdentity(identity); |
| 9211 | } |
| 9212 | } |
| 9213 | |
| 9214 | @Override |
Hall Liu | c66bb11 | 2021-02-02 12:09:32 -0800 | [diff] [blame] | 9215 | public void setMobileDataPolicyEnabled(int subscriptionId, int policy, |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9216 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9217 | enforceModifyPermission(); |
| 9218 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9219 | final long identity = Binder.clearCallingIdentity(); |
| 9220 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9221 | Phone phone = getPhone(subscriptionId); |
| 9222 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9223 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9224 | switch (policy) { |
| 9225 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9226 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9227 | break; |
| 9228 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9229 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9230 | break; |
| 9231 | default: |
| 9232 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9233 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9234 | } finally { |
| 9235 | Binder.restoreCallingIdentity(identity); |
| 9236 | } |
| 9237 | } |
| 9238 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9239 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9240 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9241 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9242 | * otherwise. |
| 9243 | */ |
| 9244 | @Override |
| 9245 | public void setCepEnabled(boolean isCepEnabled) { |
| 9246 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9247 | |
| 9248 | final long identity = Binder.clearCallingIdentity(); |
| 9249 | try { |
| 9250 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9251 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9252 | Phone defaultPhone = phone.getImsPhone(); |
| 9253 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9254 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9255 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9256 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9257 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9258 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9259 | + imsPhone.getMsisdn()); |
| 9260 | } |
| 9261 | } |
| 9262 | } finally { |
| 9263 | Binder.restoreCallingIdentity(identity); |
| 9264 | } |
| 9265 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9266 | |
| 9267 | /** |
| 9268 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9269 | * |
| 9270 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9271 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9272 | * before being read. |
| 9273 | */ |
| 9274 | @Override |
| 9275 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9276 | isCompressed) { |
| 9277 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9278 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9279 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9280 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9281 | } |
| 9282 | if (!isImsAvailableOnDevice()) { |
| 9283 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9284 | "IMS not available on device."); |
| 9285 | } |
| 9286 | |
| 9287 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9288 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9289 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9290 | } finally { |
| 9291 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9292 | } |
| 9293 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9294 | |
| 9295 | @Override |
| 9296 | public boolean isIccLockEnabled(int subId) { |
| 9297 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9298 | |
| 9299 | // Now that all security checks passes, perform the operation as ourselves. |
| 9300 | final long identity = Binder.clearCallingIdentity(); |
| 9301 | try { |
| 9302 | Phone phone = getPhone(subId); |
| 9303 | if (phone != null && phone.getIccCard() != null) { |
| 9304 | return phone.getIccCard().getIccLockEnabled(); |
| 9305 | } else { |
| 9306 | return false; |
| 9307 | } |
| 9308 | } finally { |
| 9309 | Binder.restoreCallingIdentity(identity); |
| 9310 | } |
| 9311 | } |
| 9312 | |
| 9313 | /** |
| 9314 | * Set the ICC pin lock enabled or disabled. |
| 9315 | * |
| 9316 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9317 | * three cases: |
| 9318 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9319 | * successfully. |
| 9320 | * - Positive number and zero for remaining password attempts. |
| 9321 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9322 | * |
| 9323 | */ |
| 9324 | @Override |
| 9325 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9326 | enforceModifyPermission(); |
| 9327 | |
| 9328 | Phone phone = getPhone(subId); |
| 9329 | if (phone == null) { |
| 9330 | return 0; |
| 9331 | } |
| 9332 | // Now that all security checks passes, perform the operation as ourselves. |
| 9333 | final long identity = Binder.clearCallingIdentity(); |
| 9334 | try { |
| 9335 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9336 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9337 | return attemptsRemaining; |
| 9338 | |
| 9339 | } catch (Exception e) { |
| 9340 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9341 | } finally { |
| 9342 | Binder.restoreCallingIdentity(identity); |
| 9343 | } |
| 9344 | return 0; |
| 9345 | } |
| 9346 | |
| 9347 | /** |
| 9348 | * Change the ICC password used in ICC pin lock. |
| 9349 | * |
| 9350 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9351 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9352 | * - Positive number and zero for remaining password attempts. |
| 9353 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9354 | * |
| 9355 | */ |
| 9356 | @Override |
| 9357 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9358 | enforceModifyPermission(); |
| 9359 | |
| 9360 | Phone phone = getPhone(subId); |
| 9361 | if (phone == null) { |
| 9362 | return 0; |
| 9363 | } |
| 9364 | // Now that all security checks passes, perform the operation as ourselves. |
| 9365 | final long identity = Binder.clearCallingIdentity(); |
| 9366 | try { |
| 9367 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9368 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9369 | return attemptsRemaining; |
| 9370 | |
| 9371 | } catch (Exception e) { |
| 9372 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9373 | } finally { |
| 9374 | Binder.restoreCallingIdentity(identity); |
| 9375 | } |
| 9376 | return 0; |
| 9377 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9378 | |
| 9379 | /** |
| 9380 | * Request for receiving user activity notification |
| 9381 | */ |
| 9382 | @Override |
| 9383 | public void requestUserActivityNotification() { |
| 9384 | if (!mNotifyUserActivity.get() |
| 9385 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9386 | mNotifyUserActivity.set(true); |
| 9387 | } |
| 9388 | } |
| 9389 | |
| 9390 | /** |
| 9391 | * Called when userActivity is signalled in the power manager. |
| 9392 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9393 | */ |
| 9394 | @Override |
| 9395 | public void userActivity() { |
| 9396 | // *************************************** |
| 9397 | // * Inherited from PhoneWindowManager * |
| 9398 | // *************************************** |
| 9399 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9400 | // WITH ITS LOCKS HELD. |
| 9401 | // |
| 9402 | // This code must be VERY careful about the locks |
| 9403 | // it acquires. |
| 9404 | // In fact, the current code acquires way too many, |
| 9405 | // and probably has lurking deadlocks. |
| 9406 | |
| 9407 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9408 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9409 | } |
| 9410 | |
| 9411 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9412 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9413 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9414 | } |
| 9415 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9416 | |
| 9417 | @Override |
| 9418 | public boolean canConnectTo5GInDsdsMode() { |
| 9419 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9420 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9421 | |
| 9422 | @Override |
| 9423 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 9424 | String callingFeatureId) { |
| 9425 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 9426 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 9427 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9428 | } |
| 9429 | |
| 9430 | Phone phone = getPhone(subId); |
| 9431 | if (phone == null) { |
| 9432 | throw new RuntimeException("phone is not available"); |
| 9433 | } |
| 9434 | // Now that all security checks passes, perform the operation as ourselves. |
| 9435 | final long identity = Binder.clearCallingIdentity(); |
| 9436 | try { |
| 9437 | return phone.getEquivalentHomePlmns(); |
| 9438 | } finally { |
| 9439 | Binder.restoreCallingIdentity(identity); |
| 9440 | } |
| 9441 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9442 | |
| 9443 | @Override |
| 9444 | public boolean isRadioInterfaceCapabilitySupported( |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame^] | 9445 | final @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 9446 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9447 | mPhoneConfigurationManager.getRadioInterfaceCapabilities(); |
| 9448 | if (radioInterfaceCapabilities == null) { |
| 9449 | throw new RuntimeException("radio interface capabilities are not available"); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9450 | } |
Daniel Bright | 95a4c1f | 2021-02-11 09:57:16 -0800 | [diff] [blame^] | 9451 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9452 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9453 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9454 | @Override |
| 9455 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 9456 | UaSecurityProtocolIdentifier securityProtocol, |
| 9457 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) |
| 9458 | throws RemoteException { |
| 9459 | enforceModifyPermission(); |
| 9460 | if (DBG) { |
| 9461 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 9462 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 9463 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 9464 | } |
| 9465 | |
| 9466 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 9467 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 9468 | || appType > TelephonyManager.APPTYPE_ISIM |
| 9469 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 9470 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 9471 | if (callback != null) { |
| 9472 | try { |
| 9473 | callback.onAuthenticationFailure( |
| 9474 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 9475 | } catch (RemoteException exception) { |
| 9476 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 9477 | } |
| 9478 | return; |
| 9479 | } |
| 9480 | } |
| 9481 | |
| 9482 | final long token = Binder.clearCallingIdentity(); |
| 9483 | try { |
| 9484 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 9485 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 9486 | forceBootStrapping, callback)); |
| 9487 | } finally { |
| 9488 | Binder.restoreCallingIdentity(token); |
| 9489 | } |
| 9490 | } |
| 9491 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9492 | /** |
| 9493 | * Attempts to set the radio power state for thermal reason. This does not guarantee that the |
| 9494 | * requested radio power state will actually be set. See {@link |
| 9495 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 9496 | * |
| 9497 | * @param subId the subscription ID of the phone requesting to set the radio power state. |
| 9498 | * @param enable {@code true} if trying to turn radio on. |
| 9499 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 9500 | * false}. |
| 9501 | */ |
| 9502 | private boolean setRadioPowerForThermal(int subId, boolean enable) { |
| 9503 | Phone phone = getPhone(subId); |
| 9504 | if (phone != null) { |
| 9505 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 9506 | return true; |
| 9507 | } |
| 9508 | return false; |
| 9509 | } |
| 9510 | |
| 9511 | private int handleDataThrottlingRequest(int subId, |
| 9512 | DataThrottlingRequest dataThrottlingRequest) { |
| 9513 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 9514 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9515 | if (!setRadioPowerForThermal(subId, true)) { |
| 9516 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9517 | } |
| 9518 | |
| 9519 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 9520 | |
| 9521 | int thermalMitigationResult = |
| 9522 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
| 9523 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 9524 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 9525 | } |
| 9526 | return thermalMitigationResult; |
| 9527 | } |
| 9528 | |
| 9529 | /** |
| 9530 | * Thermal mitigation request to control functionalities at modem. |
| 9531 | * |
| 9532 | * @param subId the id of the subscription. |
| 9533 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
| 9534 | * |
| 9535 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 9536 | */ |
| 9537 | @Override |
| 9538 | @ThermalMitigationResult |
| 9539 | public int sendThermalMitigationRequest( |
| 9540 | int subId, |
| 9541 | ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException { |
| 9542 | enforceModifyPermission(); |
| 9543 | |
| 9544 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9545 | final long identity = Binder.clearCallingIdentity(); |
| 9546 | |
| 9547 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 9548 | try { |
| 9549 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 9550 | switch (thermalMitigationAction) { |
| 9551 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 9552 | thermalMitigationResult = |
| 9553 | handleDataThrottlingRequest(subId, |
| 9554 | thermalMitigationRequest.getDataThrottlingRequest()); |
| 9555 | break; |
| 9556 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 9557 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9558 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 9559 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 9560 | } |
| 9561 | |
| 9562 | // Ensure that radio is on. If not able to power on due to phone being |
| 9563 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9564 | if (!setRadioPowerForThermal(subId, true)) { |
| 9565 | thermalMitigationResult = |
| 9566 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9567 | break; |
| 9568 | } |
| 9569 | |
| 9570 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 9571 | false); |
| 9572 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9573 | break; |
| 9574 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 9575 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9576 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 9577 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 9578 | } |
| 9579 | |
| 9580 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 9581 | if (registry != null) { |
| 9582 | TelephonyConnectionService service = |
| 9583 | registry.getTelephonyConnectionService(); |
| 9584 | Phone phone = getPhone(subId); |
| 9585 | if (phone == null) { |
| 9586 | thermalMitigationResult = |
| 9587 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9588 | break; |
| 9589 | } |
| 9590 | |
| 9591 | if (PhoneConstantConversions.convertCallState(phone.getState()) |
| 9592 | != TelephonyManager.CALL_STATE_IDLE |
| 9593 | || phone.isInEmergencySmsMode() || phone.isInEcm() |
| 9594 | || (service != null && service.isEmergencyCallPending())) { |
| 9595 | String errorMessage = "Phone state is not valid. call state = " |
| 9596 | + PhoneConstantConversions.convertCallState(phone.getState()) |
| 9597 | + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode() |
| 9598 | + " isInEmergencyCallbackMode = " + phone.isInEcm(); |
| 9599 | errorMessage += service == null |
| 9600 | ? " TelephonyConnectionService is null" |
| 9601 | : " isEmergencyCallPending = " |
| 9602 | + service.isEmergencyCallPending(); |
| 9603 | Log.e(LOG_TAG, errorMessage); |
| 9604 | thermalMitigationResult = |
| 9605 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 9606 | break; |
| 9607 | } |
| 9608 | } else { |
| 9609 | thermalMitigationResult = |
| 9610 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9611 | break; |
| 9612 | } |
| 9613 | |
| 9614 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 9615 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9616 | if (!setRadioPowerForThermal(subId, false)) { |
| 9617 | thermalMitigationResult = |
| 9618 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9619 | break; |
| 9620 | } |
| 9621 | thermalMitigationResult = |
| 9622 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9623 | break; |
| 9624 | default: |
| 9625 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 9626 | + "not exist. Requested action: " + thermalMitigationAction); |
| 9627 | } |
| 9628 | } catch (IllegalArgumentException e) { |
| 9629 | throw e; |
| 9630 | } catch (Exception e) { |
| 9631 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 9632 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 9633 | } finally { |
| 9634 | Binder.restoreCallingIdentity(identity); |
| 9635 | } |
| 9636 | |
| 9637 | if (DBG) { |
| 9638 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 9639 | + thermalMitigationResult); |
| 9640 | } |
| 9641 | |
| 9642 | return thermalMitigationResult; |
| 9643 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9644 | |
| 9645 | /** |
| 9646 | * Set the GbaService Package Name that Telephony will bind to. |
| 9647 | * |
| 9648 | * @param subId The sim that the GbaService is associated with. |
| 9649 | * @param packageName The name of the package to be replaced with. |
| 9650 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9651 | */ |
| 9652 | @Override |
| 9653 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 9654 | enforceModifyPermission(); |
| 9655 | |
| 9656 | final long identity = Binder.clearCallingIdentity(); |
| 9657 | try { |
| 9658 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 9659 | } finally { |
| 9660 | Binder.restoreCallingIdentity(identity); |
| 9661 | } |
| 9662 | } |
| 9663 | |
| 9664 | /** |
| 9665 | * Return the package name of the currently bound GbaService. |
| 9666 | * |
| 9667 | * @param subId The sim that the GbaService is associated with. |
| 9668 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 9669 | */ |
| 9670 | @Override |
| 9671 | public String getBoundGbaService(int subId) { |
| 9672 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 9673 | |
| 9674 | final long identity = Binder.clearCallingIdentity(); |
| 9675 | try { |
| 9676 | return getGbaManager(subId).getServicePackage(); |
| 9677 | } finally { |
| 9678 | Binder.restoreCallingIdentity(identity); |
| 9679 | } |
| 9680 | } |
| 9681 | |
| 9682 | /** |
| 9683 | * Set the release time for telephony to unbind GbaService. |
| 9684 | * |
| 9685 | * @param subId The sim that the GbaService is associated with. |
| 9686 | * @param interval The release time to unbind GbaService by millisecond. |
| 9687 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9688 | */ |
| 9689 | @Override |
| 9690 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 9691 | enforceModifyPermission(); |
| 9692 | |
| 9693 | final long identity = Binder.clearCallingIdentity(); |
| 9694 | try { |
| 9695 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 9696 | } finally { |
| 9697 | Binder.restoreCallingIdentity(identity); |
| 9698 | } |
| 9699 | } |
| 9700 | |
| 9701 | /** |
| 9702 | * Return the release time for telephony to unbind GbaService. |
| 9703 | * |
| 9704 | * @param subId The sim that the GbaService is associated with. |
| 9705 | * @return The release time to unbind GbaService by millisecond. |
| 9706 | */ |
| 9707 | @Override |
| 9708 | public int getGbaReleaseTime(int subId) { |
| 9709 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 9710 | |
| 9711 | final long identity = Binder.clearCallingIdentity(); |
| 9712 | try { |
| 9713 | return getGbaManager(subId).getReleaseTime(); |
| 9714 | } finally { |
| 9715 | Binder.restoreCallingIdentity(identity); |
| 9716 | } |
| 9717 | } |
| 9718 | |
| 9719 | private GbaManager getGbaManager(int subId) { |
| 9720 | GbaManager instance = GbaManager.getInstance(subId); |
| 9721 | if (instance == null) { |
| 9722 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 9723 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 9724 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 9725 | } |
| 9726 | return instance; |
| 9727 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9728 | |
| 9729 | /** |
| 9730 | * indicate whether the device and the carrier can support |
| 9731 | * RCS VoLTE single registration. |
| 9732 | */ |
| 9733 | @Override |
| 9734 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
| 9735 | enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable"); |
| 9736 | |
| 9737 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9738 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9739 | } |
| 9740 | |
| 9741 | final long identity = Binder.clearCallingIdentity(); |
| 9742 | try { |
| 9743 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 9744 | if (rpm != null) { |
| 9745 | return rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 9746 | } |
| 9747 | return false; |
| 9748 | } finally { |
| 9749 | Binder.restoreCallingIdentity(identity); |
| 9750 | } |
| 9751 | } |
| 9752 | |
| 9753 | /** |
| 9754 | * Register RCS provisioning callback. |
| 9755 | */ |
| 9756 | @Override |
| 9757 | public void registerRcsProvisioningChangedCallback(int subId, |
| 9758 | IRcsConfigCallback callback) { |
| 9759 | enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback"); |
| 9760 | |
| 9761 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9762 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9763 | } |
| 9764 | if (!isImsAvailableOnDevice()) { |
| 9765 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9766 | "IMS not available on device."); |
| 9767 | } |
| 9768 | |
| 9769 | final long identity = Binder.clearCallingIdentity(); |
| 9770 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9771 | if (!RcsProvisioningMonitor.getInstance() |
| 9772 | .registerRcsProvisioningChangedCallback(subId, callback)) { |
| 9773 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9774 | "Service not available for the subscription."); |
| 9775 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9776 | } finally { |
| 9777 | Binder.restoreCallingIdentity(identity); |
| 9778 | } |
| 9779 | } |
| 9780 | |
| 9781 | /** |
| 9782 | * Unregister RCS provisioning callback. |
| 9783 | */ |
| 9784 | @Override |
| 9785 | public void unregisterRcsProvisioningChangedCallback(int subId, |
| 9786 | IRcsConfigCallback callback) { |
| 9787 | enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback"); |
| 9788 | |
| 9789 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9790 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9791 | } |
| 9792 | if (!isImsAvailableOnDevice()) { |
| 9793 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9794 | "IMS not available on device."); |
| 9795 | } |
| 9796 | |
| 9797 | final long identity = Binder.clearCallingIdentity(); |
| 9798 | try { |
Hui Wang | 68cd372 | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9799 | RcsProvisioningMonitor.getInstance() |
| 9800 | .unregisterRcsProvisioningChangedCallback(subId, callback); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9801 | } finally { |
| 9802 | Binder.restoreCallingIdentity(identity); |
| 9803 | } |
| 9804 | } |
| 9805 | |
| 9806 | /** |
| 9807 | * trigger RCS reconfiguration. |
| 9808 | */ |
| 9809 | public void triggerRcsReconfiguration(int subId) { |
| 9810 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9811 | mApp, subId, "triggerRcsReconfiguration"); |
| 9812 | |
| 9813 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9814 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9815 | } |
| 9816 | if (!isImsAvailableOnDevice()) { |
| 9817 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9818 | "IMS not available on device."); |
| 9819 | } |
| 9820 | |
| 9821 | final long identity = Binder.clearCallingIdentity(); |
| 9822 | try { |
| 9823 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 9824 | } finally { |
| 9825 | Binder.restoreCallingIdentity(identity); |
| 9826 | } |
| 9827 | } |
| 9828 | |
| 9829 | /** |
| 9830 | * Provide the client configuration parameters of the RCS application. |
| 9831 | */ |
| 9832 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
| 9833 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9834 | mApp, subId, "setRcsClientConfiguration"); |
| 9835 | |
| 9836 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9837 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9838 | } |
| 9839 | if (!isImsAvailableOnDevice()) { |
| 9840 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9841 | "IMS not available on device."); |
| 9842 | } |
| 9843 | |
| 9844 | final long identity = Binder.clearCallingIdentity(); |
| 9845 | |
| 9846 | try { |
| 9847 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 9848 | if (configBinder == null) { |
| 9849 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
| 9850 | } else { |
| 9851 | configBinder.setRcsClientConfiguration(rcc); |
| 9852 | } |
| 9853 | } catch (RemoteException e) { |
| 9854 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
| 9855 | } finally { |
| 9856 | Binder.restoreCallingIdentity(identity); |
| 9857 | } |
| 9858 | } |
| 9859 | |
| 9860 | /** |
| 9861 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 9862 | */ |
| 9863 | @Override |
| 9864 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 9865 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9866 | "setDeviceSingleRegistrationEnabledOverride"); |
| 9867 | enforceModifyPermission(); |
| 9868 | |
| 9869 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9870 | : Boolean.parseBoolean(enabledStr); |
| 9871 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 9872 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9873 | } |
| 9874 | |
| 9875 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 9876 | * Sends a device to device communication message. Only usable via shell. |
| 9877 | * @param message message to send. |
| 9878 | * @param value message value. |
| 9879 | */ |
| 9880 | @Override |
| 9881 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 9882 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9883 | "setCarrierSingleRegistrationEnabledOverride"); |
| 9884 | enforceModifyPermission(); |
| 9885 | |
| 9886 | final long identity = Binder.clearCallingIdentity(); |
| 9887 | try { |
| 9888 | TelephonyConnectionService service = |
| 9889 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 9890 | if (service == null) { |
| 9891 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 9892 | return; |
| 9893 | } |
| 9894 | service.sendTestDeviceToDeviceMessage(message, value); |
| 9895 | } finally { |
| 9896 | Binder.restoreCallingIdentity(identity); |
| 9897 | } |
| 9898 | } |
| 9899 | |
| 9900 | |
| 9901 | /** |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9902 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 9903 | */ |
| 9904 | @Override |
| 9905 | public boolean getDeviceSingleRegistrationEnabled() { |
| 9906 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 9907 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 9908 | } |
| 9909 | |
| 9910 | /** |
| 9911 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 9912 | */ |
| 9913 | @Override |
| 9914 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 9915 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9916 | "setCarrierSingleRegistrationEnabledOverride"); |
| 9917 | enforceModifyPermission(); |
| 9918 | |
| 9919 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9920 | : Boolean.parseBoolean(enabledStr); |
| 9921 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 9922 | subId, enabled); |
| 9923 | } |
| 9924 | |
| 9925 | /** |
| 9926 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 9927 | */ |
| 9928 | @Override |
| 9929 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 9930 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 9931 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 9932 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 9933 | |
| 9934 | /** |
| 9935 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 9936 | * their mobile plan. |
| 9937 | */ |
| 9938 | @Override |
| 9939 | public String getMobileProvisioningUrl() { |
| 9940 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 9941 | final long identity = Binder.clearCallingIdentity(); |
| 9942 | try { |
| 9943 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 9944 | } finally { |
| 9945 | Binder.restoreCallingIdentity(identity); |
| 9946 | } |
| 9947 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 9948 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 9949 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 9950 | * Get the EAB contact from the EAB database. |
| 9951 | */ |
| 9952 | @Override |
| 9953 | public String getContactFromEab(String contact) { |
| 9954 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 9955 | enforceModifyPermission(); |
| 9956 | final long identity = Binder.clearCallingIdentity(); |
| 9957 | try { |
| 9958 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 9959 | } finally { |
| 9960 | Binder.restoreCallingIdentity(identity); |
| 9961 | } |
| 9962 | } |
| 9963 | |
| 9964 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 9965 | * Remove the EAB contacts from the EAB database. |
| 9966 | */ |
| 9967 | @Override |
| 9968 | public int removeContactFromEab(int subId, String contacts) { |
| 9969 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 9970 | enforceModifyPermission(); |
| 9971 | final long identity = Binder.clearCallingIdentity(); |
| 9972 | try { |
| 9973 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 9974 | } finally { |
| 9975 | Binder.restoreCallingIdentity(identity); |
| 9976 | } |
| 9977 | } |
| 9978 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 9979 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 9980 | public boolean getDeviceUceEnabled() { |
| 9981 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 9982 | final long identity = Binder.clearCallingIdentity(); |
| 9983 | try { |
| 9984 | return mApp.getDeviceUceEnabled(); |
| 9985 | } finally { |
| 9986 | Binder.restoreCallingIdentity(identity); |
| 9987 | } |
| 9988 | } |
| 9989 | |
| 9990 | @Override |
| 9991 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 9992 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 9993 | final long identity = Binder.clearCallingIdentity(); |
| 9994 | try { |
| 9995 | mApp.setDeviceUceEnabled(isEnabled); |
| 9996 | } finally { |
| 9997 | Binder.restoreCallingIdentity(identity); |
| 9998 | } |
| 9999 | } |
| 10000 | |
| 10001 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 10002 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10003 | String callingPackage) { |
| 10004 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10005 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 10006 | |
| 10007 | final int callingUid = Binder.getCallingUid(); |
| 10008 | // Verify that tha callingPackage belongs to the calling UID |
| 10009 | mApp.getSystemService(AppOpsManager.class) |
| 10010 | .checkPackage(callingUid, callingPackage); |
| 10011 | |
| 10012 | validateSignalStrengthUpdateRequest(request, callingUid); |
| 10013 | |
| 10014 | final long identity = Binder.clearCallingIdentity(); |
| 10015 | try { |
| 10016 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10017 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10018 | |
| 10019 | if (result instanceof IllegalStateException) { |
| 10020 | throw (IllegalStateException) result; |
| 10021 | } |
| 10022 | } finally { |
| 10023 | Binder.restoreCallingIdentity(identity); |
| 10024 | } |
| 10025 | } |
| 10026 | |
| 10027 | @Override |
| 10028 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 10029 | String callingPackage) { |
| 10030 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 10031 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 10032 | |
| 10033 | final int callingUid = Binder.getCallingUid(); |
| 10034 | // Verify that tha callingPackage belongs to the calling UID |
| 10035 | mApp.getSystemService(AppOpsManager.class) |
| 10036 | .checkPackage(callingUid, callingPackage); |
| 10037 | |
| 10038 | final long identity = Binder.clearCallingIdentity(); |
| 10039 | try { |
| 10040 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 10041 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 10042 | |
| 10043 | if (result instanceof IllegalStateException) { |
| 10044 | throw (IllegalStateException) result; |
| 10045 | } |
| 10046 | } finally { |
| 10047 | Binder.restoreCallingIdentity(identity); |
| 10048 | } |
| 10049 | } |
| 10050 | |
| 10051 | private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request, |
| 10052 | int callingUid) { |
| 10053 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 10054 | // phone/system process do not have further restriction on request |
| 10055 | return; |
| 10056 | } |
| 10057 | |
| 10058 | // Applications has restrictions on how to use the request: |
| 10059 | // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle |
| 10060 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
| 10061 | // This is not system caller which has been checked above |
| 10062 | throw new IllegalArgumentException( |
| 10063 | "Only system can set isSystemThresholdReportingRequestedWhileIdle"); |
| 10064 | } |
| 10065 | |
| 10066 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 10067 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 10068 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 10069 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 10070 | || info.isEnabled()) { |
| 10071 | throw new IllegalArgumentException( |
| 10072 | "Only system can set hide fields in SignalThresholdInfo"); |
| 10073 | } |
| 10074 | |
| 10075 | // Thresholds length for each RAN need in range. This has been validated in |
| 10076 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 10077 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 10078 | final int[] thresholds = info.getThresholds(); |
| 10079 | Objects.requireNonNull(thresholds); |
| 10080 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 10081 | || thresholds.length |
| 10082 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 10083 | throw new IllegalArgumentException( |
| 10084 | "thresholds length is out of range: " + thresholds.length); |
| 10085 | } |
| 10086 | } |
| 10087 | } |
SongFerngWang | 8236caa | 2021-01-17 21:51:44 +0800 | [diff] [blame] | 10088 | |
| 10089 | /** |
| 10090 | * Gets the current phone capability. |
| 10091 | * |
| 10092 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 10093 | * @return the PhoneCapability which describes the data connection capability of modem. |
| 10094 | * It's used to evaluate possible phone config change, for example from single |
| 10095 | * SIM device to multi-SIM device. |
| 10096 | */ |
| 10097 | @Override |
| 10098 | public PhoneCapability getPhoneCapability() { |
| 10099 | enforceReadPrivilegedPermission("getPhoneCapability"); |
| 10100 | final long identity = Binder.clearCallingIdentity(); |
| 10101 | try { |
| 10102 | return mPhoneConfigurationManager.getCurrentPhoneCapability(); |
| 10103 | } finally { |
| 10104 | Binder.restoreCallingIdentity(identity); |
| 10105 | } |
| 10106 | } |
Michele Berionne | 5e41151 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 10107 | |
| 10108 | /** |
| 10109 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 10110 | * required to be done shortly after the API is invoked. |
| 10111 | */ |
| 10112 | @Override |
| 10113 | @TelephonyManager.PrepareUnattendedRebootResult |
| 10114 | public int prepareForUnattendedReboot() { |
| 10115 | enforceRebootPermission(); |
| 10116 | |
| 10117 | final long identity = Binder.clearCallingIdentity(); |
| 10118 | try { |
| 10119 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null); |
| 10120 | } finally { |
| 10121 | Binder.restoreCallingIdentity(identity); |
| 10122 | } |
| 10123 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 10124 | } |